1/* 2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and --- 136 unchanged lines hidden (view full) --- 145static struct h6namemem h6nametable[HASHNAMESIZE]; 146 147struct enamemem { 148 u_short e_addr0; 149 u_short e_addr1; 150 u_short e_addr2; 151 const char *e_name; 152 u_char *e_nsap; /* used only for nsaptable[] */ |
153 struct enamemem *e_nxt; 154}; 155 156static struct enamemem enametable[HASHNAMESIZE]; 157static struct enamemem nsaptable[HASHNAMESIZE]; |
158 |
159struct bsnamemem { 160 u_short bs_addr0; 161 u_short bs_addr1; 162 u_short bs_addr2; 163 const char *bs_name; 164 u_char *bs_bytes; 165 unsigned int bs_nbytes; 166 struct bsnamemem *bs_nxt; 167}; 168 169static struct bsnamemem bytestringtable[HASHNAMESIZE]; 170 |
171struct protoidmem { 172 uint32_t p_oui; 173 u_short p_proto; 174 const char *p_name; 175 struct protoidmem *p_nxt; 176}; 177 178static struct protoidmem protoidtable[HASHNAMESIZE]; --- 168 unchanged lines hidden (view full) --- 347 } 348 cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf)); 349 p->name = strdup(cp); 350 if (p->name == NULL) 351 (*ndo->ndo_error)(ndo, "getname6: strdup(cp)"); 352 return (p->name); 353} 354 |
355static const char hex[16] = "0123456789abcdef"; |
356 357 358/* Find the hash node that corresponds the ether address 'ep' */ 359 360static inline struct enamemem * 361lookup_emem(netdissect_options *ndo, const u_char *ep) 362{ 363 register u_int i, j, k; --- 21 unchanged lines hidden (view full) --- 385 return tp; 386} 387 388/* 389 * Find the hash node that corresponds to the bytestring 'bs' 390 * with length 'nlen' 391 */ 392 |
393static inline struct bsnamemem * |
394lookup_bytestring(netdissect_options *ndo, register const u_char *bs, 395 const unsigned int nlen) 396{ |
397 struct bsnamemem *tp; |
398 register u_int i, j, k; 399 400 if (nlen >= 6) { 401 k = (bs[0] << 8) | bs[1]; 402 j = (bs[2] << 8) | bs[3]; 403 i = (bs[4] << 8) | bs[5]; 404 } else if (nlen >= 4) { 405 k = (bs[0] << 8) | bs[1]; 406 j = (bs[2] << 8) | bs[3]; 407 i = 0; 408 } else 409 i = j = k = 0; 410 411 tp = &bytestringtable[(i ^ j) & (HASHNAMESIZE-1)]; |
412 while (tp->bs_nxt) 413 if (nlen == tp->bs_nbytes && 414 tp->bs_addr0 == i && 415 tp->bs_addr1 == j && 416 tp->bs_addr2 == k && 417 memcmp((const char *)bs, (const char *)(tp->bs_bytes), nlen) == 0) |
418 return tp; 419 else |
420 tp = tp->bs_nxt; |
421 |
422 tp->bs_addr0 = i; 423 tp->bs_addr1 = j; 424 tp->bs_addr2 = k; |
425 |
426 tp->bs_bytes = (u_char *) calloc(1, nlen); 427 if (tp->bs_bytes == NULL) |
428 (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc"); 429 |
430 memcpy(tp->bs_bytes, bs, nlen); 431 tp->bs_nbytes = nlen; 432 tp->bs_nxt = (struct bsnamemem *)calloc(1, sizeof(*tp)); 433 if (tp->bs_nxt == NULL) |
434 (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc"); 435 436 return tp; 437} 438 439/* Find the hash node that corresponds the NSAP 'nsap' */ 440 441static inline struct enamemem * --- 10 unchanged lines hidden (view full) --- 452 j = (ensap[2] << 8) | ensap[3]; 453 i = (ensap[4] << 8) | ensap[5]; 454 } 455 else 456 i = j = k = 0; 457 458 tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)]; 459 while (tp->e_nxt) |
460 if (nsap_length == tp->e_nsap[0] && 461 tp->e_addr0 == i && |
462 tp->e_addr1 == j && 463 tp->e_addr2 == k && |
464 memcmp((const char *)nsap, |
465 (char *)&(tp->e_nsap[1]), nsap_length) == 0) 466 return tp; 467 else 468 tp = tp->e_nxt; 469 tp->e_addr0 = i; 470 tp->e_addr1 = j; 471 tp->e_addr2 = k; 472 tp->e_nsap = (u_char *)malloc(nsap_length + 1); --- 83 unchanged lines hidden (view full) --- 556} 557 558const char * 559le64addr_string(netdissect_options *ndo, const u_char *ep) 560{ 561 const unsigned int len = 8; 562 register u_int i; 563 register char *cp; |
564 register struct bsnamemem *tp; |
565 char buf[BUFSIZE]; 566 567 tp = lookup_bytestring(ndo, ep, len); |
568 if (tp->bs_name) 569 return (tp->bs_name); |
570 571 cp = buf; 572 for (i = len; i > 0 ; --i) { 573 *cp++ = hex[*(ep + i - 1) >> 4]; 574 *cp++ = hex[*(ep + i - 1) & 0xf]; 575 *cp++ = ':'; 576 } 577 cp --; 578 579 *cp = '\0'; 580 |
581 tp->bs_name = strdup(buf); 582 if (tp->bs_name == NULL) |
583 (*ndo->ndo_error)(ndo, "le64addr_string: strdup(buf)"); 584 |
585 return (tp->bs_name); |
586} 587 588const char * 589linkaddr_string(netdissect_options *ndo, const u_char *ep, 590 const unsigned int type, const unsigned int len) 591{ 592 register u_int i; 593 register char *cp; |
594 register struct bsnamemem *tp; |
595 596 if (len == 0) 597 return ("<empty>"); 598 599 if (type == LINKADDR_ETHER && len == ETHER_ADDR_LEN) 600 return (etheraddr_string(ndo, ep)); 601 602 if (type == LINKADDR_FRELAY) 603 return (q922_string(ndo, ep, len)); 604 605 tp = lookup_bytestring(ndo, ep, len); |
606 if (tp->bs_name) 607 return (tp->bs_name); |
608 |
609 tp->bs_name = cp = (char *)malloc(len*3); 610 if (tp->bs_name == NULL) |
611 (*ndo->ndo_error)(ndo, "linkaddr_string: malloc"); 612 *cp++ = hex[*ep >> 4]; 613 *cp++ = hex[*ep++ & 0xf]; 614 for (i = len-1; i > 0 ; --i) { 615 *cp++ = ':'; 616 *cp++ = hex[*ep >> 4]; 617 *cp++ = hex[*ep++ & 0xf]; 618 } 619 *cp = '\0'; |
620 return (tp->bs_name); |
621} 622 623const char * 624etherproto_string(netdissect_options *ndo, u_short port) 625{ 626 register char *cp; 627 register struct hnamemem *tp; 628 register uint32_t i = port; --- 678 unchanged lines hidden --- |