Deleted Added
full compact
addrtoname.c (313537) addrtoname.c (327234)
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[] */
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#define e_bs e_nsap /* for bytestringtable */
154 struct enamemem *e_nxt;
155};
156
157static struct enamemem enametable[HASHNAMESIZE];
158static struct enamemem nsaptable[HASHNAMESIZE];
153 struct enamemem *e_nxt;
154};
155
156static struct enamemem enametable[HASHNAMESIZE];
157static struct enamemem nsaptable[HASHNAMESIZE];
159static struct enamemem bytestringtable[HASHNAMESIZE];
160
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
161struct protoidmem {
162 uint32_t p_oui;
163 u_short p_proto;
164 const char *p_name;
165 struct protoidmem *p_nxt;
166};
167
168static struct protoidmem protoidtable[HASHNAMESIZE];

--- 168 unchanged lines hidden (view full) ---

337 }
338 cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
339 p->name = strdup(cp);
340 if (p->name == NULL)
341 (*ndo->ndo_error)(ndo, "getname6: strdup(cp)");
342 return (p->name);
343}
344
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
345static const char hex[] = "0123456789abcdef";
355static const char hex[16] = "0123456789abcdef";
346
347
348/* Find the hash node that corresponds the ether address 'ep' */
349
350static inline struct enamemem *
351lookup_emem(netdissect_options *ndo, const u_char *ep)
352{
353 register u_int i, j, k;

--- 21 unchanged lines hidden (view full) ---

375 return tp;
376}
377
378/*
379 * Find the hash node that corresponds to the bytestring 'bs'
380 * with length 'nlen'
381 */
382
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
383static inline struct enamemem *
393static inline struct bsnamemem *
384lookup_bytestring(netdissect_options *ndo, register const u_char *bs,
385 const unsigned int nlen)
386{
394lookup_bytestring(netdissect_options *ndo, register const u_char *bs,
395 const unsigned int nlen)
396{
387 struct enamemem *tp;
397 struct bsnamemem *tp;
388 register u_int i, j, k;
389
390 if (nlen >= 6) {
391 k = (bs[0] << 8) | bs[1];
392 j = (bs[2] << 8) | bs[3];
393 i = (bs[4] << 8) | bs[5];
394 } else if (nlen >= 4) {
395 k = (bs[0] << 8) | bs[1];
396 j = (bs[2] << 8) | bs[3];
397 i = 0;
398 } else
399 i = j = k = 0;
400
401 tp = &bytestringtable[(i ^ j) & (HASHNAMESIZE-1)];
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)];
402 while (tp->e_nxt)
403 if (tp->e_addr0 == i &&
404 tp->e_addr1 == j &&
405 tp->e_addr2 == k &&
406 memcmp((const char *)bs, (const char *)(tp->e_bs), nlen) == 0)
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)
407 return tp;
408 else
418 return tp;
419 else
409 tp = tp->e_nxt;
420 tp = tp->bs_nxt;
410
421
411 tp->e_addr0 = i;
412 tp->e_addr1 = j;
413 tp->e_addr2 = k;
422 tp->bs_addr0 = i;
423 tp->bs_addr1 = j;
424 tp->bs_addr2 = k;
414
425
415 tp->e_bs = (u_char *) calloc(1, nlen + 1);
416 if (tp->e_bs == NULL)
426 tp->bs_bytes = (u_char *) calloc(1, nlen);
427 if (tp->bs_bytes == NULL)
417 (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
418
428 (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
429
419 memcpy(tp->e_bs, bs, nlen);
420 tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
421 if (tp->e_nxt == NULL)
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)
422 (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
423
424 return tp;
425}
426
427/* Find the hash node that corresponds the NSAP 'nsap' */
428
429static inline struct enamemem *

--- 10 unchanged lines hidden (view full) ---

440 j = (ensap[2] << 8) | ensap[3];
441 i = (ensap[4] << 8) | ensap[5];
442 }
443 else
444 i = j = k = 0;
445
446 tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)];
447 while (tp->e_nxt)
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)
448 if (tp->e_addr0 == i &&
460 if (nsap_length == tp->e_nsap[0] &&
461 tp->e_addr0 == i &&
449 tp->e_addr1 == j &&
450 tp->e_addr2 == k &&
462 tp->e_addr1 == j &&
463 tp->e_addr2 == k &&
451 tp->e_nsap[0] == nsap_length &&
452 memcmp((const char *)&(nsap[1]),
464 memcmp((const char *)nsap,
453 (char *)&(tp->e_nsap[1]), nsap_length) == 0)
454 return tp;
455 else
456 tp = tp->e_nxt;
457 tp->e_addr0 = i;
458 tp->e_addr1 = j;
459 tp->e_addr2 = k;
460 tp->e_nsap = (u_char *)malloc(nsap_length + 1);

--- 83 unchanged lines hidden (view full) ---

544}
545
546const char *
547le64addr_string(netdissect_options *ndo, const u_char *ep)
548{
549 const unsigned int len = 8;
550 register u_int i;
551 register char *cp;
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;
552 register struct enamemem *tp;
564 register struct bsnamemem *tp;
553 char buf[BUFSIZE];
554
555 tp = lookup_bytestring(ndo, ep, len);
565 char buf[BUFSIZE];
566
567 tp = lookup_bytestring(ndo, ep, len);
556 if (tp->e_name)
557 return (tp->e_name);
568 if (tp->bs_name)
569 return (tp->bs_name);
558
559 cp = buf;
560 for (i = len; i > 0 ; --i) {
561 *cp++ = hex[*(ep + i - 1) >> 4];
562 *cp++ = hex[*(ep + i - 1) & 0xf];
563 *cp++ = ':';
564 }
565 cp --;
566
567 *cp = '\0';
568
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
569 tp->e_name = strdup(buf);
570 if (tp->e_name == NULL)
581 tp->bs_name = strdup(buf);
582 if (tp->bs_name == NULL)
571 (*ndo->ndo_error)(ndo, "le64addr_string: strdup(buf)");
572
583 (*ndo->ndo_error)(ndo, "le64addr_string: strdup(buf)");
584
573 return (tp->e_name);
585 return (tp->bs_name);
574}
575
576const char *
577linkaddr_string(netdissect_options *ndo, const u_char *ep,
578 const unsigned int type, const unsigned int len)
579{
580 register u_int i;
581 register char *cp;
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;
582 register struct enamemem *tp;
594 register struct bsnamemem *tp;
583
584 if (len == 0)
585 return ("<empty>");
586
587 if (type == LINKADDR_ETHER && len == ETHER_ADDR_LEN)
588 return (etheraddr_string(ndo, ep));
589
590 if (type == LINKADDR_FRELAY)
591 return (q922_string(ndo, ep, len));
592
593 tp = lookup_bytestring(ndo, ep, len);
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);
594 if (tp->e_name)
595 return (tp->e_name);
606 if (tp->bs_name)
607 return (tp->bs_name);
596
608
597 tp->e_name = cp = (char *)malloc(len*3);
598 if (tp->e_name == NULL)
609 tp->bs_name = cp = (char *)malloc(len*3);
610 if (tp->bs_name == NULL)
599 (*ndo->ndo_error)(ndo, "linkaddr_string: malloc");
600 *cp++ = hex[*ep >> 4];
601 *cp++ = hex[*ep++ & 0xf];
602 for (i = len-1; i > 0 ; --i) {
603 *cp++ = ':';
604 *cp++ = hex[*ep >> 4];
605 *cp++ = hex[*ep++ & 0xf];
606 }
607 *cp = '\0';
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';
608 return (tp->e_name);
620 return (tp->bs_name);
609}
610
611const char *
612etherproto_string(netdissect_options *ndo, u_short port)
613{
614 register char *cp;
615 register struct hnamemem *tp;
616 register uint32_t i = port;

--- 678 unchanged lines hidden ---
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 ---