2 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * Internet, ethernet, port, and protocol string to address
22 * and address to string conversion routines
30 #include <libcasper.h>
31 #include <casper/cap_dns.h>
32 #endif /* HAVE_CASPER */
34 #include <netdissect-stdinc.h>
36 #ifdef USE_ETHER_NTOHOST
37 #ifdef HAVE_NETINET_IF_ETHER_H
38 struct mbuf; /* Squelch compiler warnings on some platforms for */
39 struct rtentry; /* declarations in <net/if.h> */
40 #include <net/if.h> /* for "struct ifnet" in "struct arpcom" on Solaris */
41 #include <netinet/if_ether.h>
42 #endif /* HAVE_NETINET_IF_ETHER_H */
43 #ifdef NETINET_ETHER_H_DECLARES_ETHER_NTOHOST
44 #include <netinet/ether.h>
45 #endif /* NETINET_ETHER_H_DECLARES_ETHER_NTOHOST */
47 #if !defined(HAVE_DECL_ETHER_NTOHOST) || !HAVE_DECL_ETHER_NTOHOST
48 #ifndef HAVE_STRUCT_ETHER_ADDR
50 unsigned char ether_addr_octet[6];
53 extern int ether_ntohost(char *, const struct ether_addr *);
56 #endif /* USE_ETHER_NTOHOST */
59 #include <pcap-namedb.h>
65 #include "netdissect.h"
66 #include "addrtoname.h"
67 #include "addrtostr.h"
68 #include "ethertype.h"
70 #include "setsignal.h"
74 #ifndef ETHER_ADDR_LEN
75 #define ETHER_ADDR_LEN 6
79 * hash tables for whatever-to-name translations
81 * ndo_error() called on strdup(3) failure
84 #define HASHNAMESIZE 4096
92 static struct hnamemem hnametable[HASHNAMESIZE];
93 static struct hnamemem tporttable[HASHNAMESIZE];
94 static struct hnamemem uporttable[HASHNAMESIZE];
95 static struct hnamemem eprototable[HASHNAMESIZE];
96 static struct hnamemem dnaddrtable[HASHNAMESIZE];
97 static struct hnamemem ipxsaptable[HASHNAMESIZE];
101 * fake gethostbyaddr for Win2k/XP
102 * gethostbyaddr() returns incorrect value when AF_INET6 is passed
105 * h_name in struct hostent is only valid.
107 static struct hostent *
108 win32_gethostbyaddr(const char *addr, int len, int type)
110 static struct hostent host;
111 static char hostbuf[NI_MAXHOST];
112 char hname[NI_MAXHOST];
113 struct sockaddr_in6 addr6;
115 host.h_name = hostbuf;
118 return gethostbyaddr(addr, len, type);
121 memset(&addr6, 0, sizeof(addr6));
122 addr6.sin6_family = AF_INET6;
123 memcpy(&addr6.sin6_addr, addr, len);
124 if (getnameinfo((struct sockaddr *)&addr6, sizeof(addr6),
125 hname, sizeof(hname), NULL, 0, 0)) {
128 strlcpy(host.h_name, hname, NI_MAXHOST);
136 #define gethostbyaddr win32_gethostbyaddr
140 struct in6_addr addr;
142 struct h6namemem *nxt;
145 static struct h6namemem h6nametable[HASHNAMESIZE];
152 u_char *e_nsap; /* used only for nsaptable[] */
153 struct enamemem *e_nxt;
156 static struct enamemem enametable[HASHNAMESIZE];
157 static struct enamemem nsaptable[HASHNAMESIZE];
165 unsigned int bs_nbytes;
166 struct bsnamemem *bs_nxt;
169 static struct bsnamemem bytestringtable[HASHNAMESIZE];
175 struct protoidmem *p_nxt;
178 static struct protoidmem protoidtable[HASHNAMESIZE];
181 * A faster replacement for inet_ntoa().
189 static char buf[sizeof(".xxx.xxx.xxx.xxx")];
192 cp = buf + sizeof(buf);
198 *--cp = byte % 10 + '0';
201 *--cp = byte % 10 + '0';
213 static uint32_t f_netmask;
214 static uint32_t f_localnet;
216 extern cap_channel_t *capdns;
220 * Return a name for the IP address pointed to by ap. This address
221 * is assumed to be in network byte order.
223 * NOTE: ap is *NOT* necessarily part of the packet data (not even if
224 * this is being called with the "ipaddr_string()" macro), so you
225 * *CANNOT* use the ND_TCHECK{2}/ND_TTEST{2} macros on it. Furthermore,
226 * even in cases where it *is* part of the packet data, the caller
227 * would still have to check for a null return value, even if it's
228 * just printing the return value with "%s" - not all versions of
229 * printf print "(null)" with "%s" and a null pointer, some of them
230 * don't check for a null pointer and crash in that case.
232 * The callers of this routine should, before handing this routine
233 * a pointer to packet data, be sure that the data is present in
234 * the packet buffer. They should probably do those checks anyway,
235 * as other data at that layer might not be IP addresses, and it
236 * also needs to check whether they're present in the packet buffer.
239 getname(netdissect_options *ndo, const u_char *ap)
241 register struct hostent *hp;
245 memcpy(&addr, ap, sizeof(addr));
246 p = &hnametable[addr & (HASHNAMESIZE-1)];
247 for (; p->nxt; p = p->nxt) {
252 p->nxt = newhnamemem(ndo);
255 * Print names unless:
257 * (2) Address is foreign and -f was given. (If -f was not
258 * given, f_netmask and f_localnet are 0 and the test
261 if (!ndo->ndo_nflag &&
262 (addr & f_netmask) == f_localnet) {
264 if (capdns != NULL) {
265 hp = cap_gethostbyaddr(capdns, (char *)&addr, 4,
269 hp = gethostbyaddr((char *)&addr, 4, AF_INET);
273 p->name = strdup(hp->h_name);
275 (*ndo->ndo_error)(ndo,
276 "getname: strdup(hp->h_name)");
277 if (ndo->ndo_Nflag) {
278 /* Remove domain qualifications */
279 dotp = strchr(p->name, '.');
286 p->name = strdup(intoa(addr));
288 (*ndo->ndo_error)(ndo, "getname: strdup(intoa(addr))");
293 * Return a name for the IP6 address pointed to by ap. This address
294 * is assumed to be in network byte order.
297 getname6(netdissect_options *ndo, const u_char *ap)
299 register struct hostent *hp;
301 struct in6_addr addr;
302 struct for_hash_addr {
308 register const char *cp;
309 char ntop_buf[INET6_ADDRSTRLEN];
311 memcpy(&addr, ap, sizeof(addr));
312 p = &h6nametable[addr.addra.d & (HASHNAMESIZE-1)];
313 for (; p->nxt; p = p->nxt) {
314 if (memcmp(&p->addr, &addr, sizeof(addr)) == 0)
318 p->nxt = newh6namemem(ndo);
321 * Do not print names if -n was given.
323 if (!ndo->ndo_nflag) {
325 if (capdns != NULL) {
326 hp = cap_gethostbyaddr(capdns, (char *)&addr,
327 sizeof(addr), AF_INET6);
330 hp = gethostbyaddr((char *)&addr, sizeof(addr),
335 p->name = strdup(hp->h_name);
337 (*ndo->ndo_error)(ndo,
338 "getname6: strdup(hp->h_name)");
339 if (ndo->ndo_Nflag) {
340 /* Remove domain qualifications */
341 dotp = strchr(p->name, '.');
348 cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
349 p->name = strdup(cp);
351 (*ndo->ndo_error)(ndo, "getname6: strdup(cp)");
355 static const char hex[16] = "0123456789abcdef";
358 /* Find the hash node that corresponds the ether address 'ep' */
360 static inline struct enamemem *
361 lookup_emem(netdissect_options *ndo, const u_char *ep)
363 register u_int i, j, k;
366 k = (ep[0] << 8) | ep[1];
367 j = (ep[2] << 8) | ep[3];
368 i = (ep[4] << 8) | ep[5];
370 tp = &enametable[(i ^ j) & (HASHNAMESIZE-1)];
372 if (tp->e_addr0 == i &&
381 tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
382 if (tp->e_nxt == NULL)
383 (*ndo->ndo_error)(ndo, "lookup_emem: calloc");
389 * Find the hash node that corresponds to the bytestring 'bs'
393 static inline struct bsnamemem *
394 lookup_bytestring(netdissect_options *ndo, register const u_char *bs,
395 const unsigned int nlen)
397 struct bsnamemem *tp;
398 register u_int i, j, k;
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];
411 tp = &bytestringtable[(i ^ j) & (HASHNAMESIZE-1)];
413 if (nlen == tp->bs_nbytes &&
417 memcmp((const char *)bs, (const char *)(tp->bs_bytes), nlen) == 0)
426 tp->bs_bytes = (u_char *) calloc(1, nlen);
427 if (tp->bs_bytes == NULL)
428 (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
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");
439 /* Find the hash node that corresponds the NSAP 'nsap' */
441 static inline struct enamemem *
442 lookup_nsap(netdissect_options *ndo, register const u_char *nsap,
443 register u_int nsap_length)
445 register u_int i, j, k;
449 if (nsap_length > 6) {
450 ensap = nsap + nsap_length - 6;
451 k = (ensap[0] << 8) | ensap[1];
452 j = (ensap[2] << 8) | ensap[3];
453 i = (ensap[4] << 8) | ensap[5];
458 tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)];
460 if (nsap_length == tp->e_nsap[0] &&
464 memcmp((const char *)nsap,
465 (char *)&(tp->e_nsap[1]), nsap_length) == 0)
472 tp->e_nsap = (u_char *)malloc(nsap_length + 1);
473 if (tp->e_nsap == NULL)
474 (*ndo->ndo_error)(ndo, "lookup_nsap: malloc");
475 tp->e_nsap[0] = (u_char)nsap_length; /* guaranteed < ISONSAP_MAX_LENGTH */
476 memcpy((char *)&tp->e_nsap[1], (const char *)nsap, nsap_length);
477 tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
478 if (tp->e_nxt == NULL)
479 (*ndo->ndo_error)(ndo, "lookup_nsap: calloc");
484 /* Find the hash node that corresponds the protoid 'pi'. */
486 static inline struct protoidmem *
487 lookup_protoid(netdissect_options *ndo, const u_char *pi)
490 struct protoidmem *tp;
492 /* 5 octets won't be aligned */
493 i = (((pi[0] << 8) + pi[1]) << 8) + pi[2];
494 j = (pi[3] << 8) + pi[4];
495 /* XXX should be endian-insensitive, but do big-endian testing XXX */
497 tp = &protoidtable[(i ^ j) & (HASHNAMESIZE-1)];
499 if (tp->p_oui == i && tp->p_proto == j)
505 tp->p_nxt = (struct protoidmem *)calloc(1, sizeof(*tp));
506 if (tp->p_nxt == NULL)
507 (*ndo->ndo_error)(ndo, "lookup_protoid: calloc");
513 etheraddr_string(netdissect_options *ndo, register const u_char *ep)
517 register struct enamemem *tp;
521 tp = lookup_emem(ndo, ep);
524 #ifdef USE_ETHER_NTOHOST
525 if (!ndo->ndo_nflag) {
528 if (ether_ntohost(buf2, (const struct ether_addr *)ep) == 0) {
529 tp->e_name = strdup(buf2);
530 if (tp->e_name == NULL)
531 (*ndo->ndo_error)(ndo,
532 "etheraddr_string: strdup(buf2)");
538 oui = EXTRACT_24BITS(ep);
539 *cp++ = hex[*ep >> 4 ];
540 *cp++ = hex[*ep++ & 0xf];
541 for (i = 5; --i >= 0;) {
543 *cp++ = hex[*ep >> 4 ];
544 *cp++ = hex[*ep++ & 0xf];
547 if (!ndo->ndo_nflag) {
548 snprintf(cp, BUFSIZE - (2 + 5*3), " (oui %s)",
549 tok2str(oui_values, "Unknown", oui));
552 tp->e_name = strdup(buf);
553 if (tp->e_name == NULL)
554 (*ndo->ndo_error)(ndo, "etheraddr_string: strdup(buf)");
559 le64addr_string(netdissect_options *ndo, const u_char *ep)
561 const unsigned int len = 8;
564 register struct bsnamemem *tp;
567 tp = lookup_bytestring(ndo, ep, len);
569 return (tp->bs_name);
572 for (i = len; i > 0 ; --i) {
573 *cp++ = hex[*(ep + i - 1) >> 4];
574 *cp++ = hex[*(ep + i - 1) & 0xf];
581 tp->bs_name = strdup(buf);
582 if (tp->bs_name == NULL)
583 (*ndo->ndo_error)(ndo, "le64addr_string: strdup(buf)");
585 return (tp->bs_name);
589 linkaddr_string(netdissect_options *ndo, const u_char *ep,
590 const unsigned int type, const unsigned int len)
594 register struct bsnamemem *tp;
599 if (type == LINKADDR_ETHER && len == ETHER_ADDR_LEN)
600 return (etheraddr_string(ndo, ep));
602 if (type == LINKADDR_FRELAY)
603 return (q922_string(ndo, ep, len));
605 tp = lookup_bytestring(ndo, ep, len);
607 return (tp->bs_name);
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) {
616 *cp++ = hex[*ep >> 4];
617 *cp++ = hex[*ep++ & 0xf];
620 return (tp->bs_name);
624 etherproto_string(netdissect_options *ndo, u_short port)
627 register struct hnamemem *tp;
628 register uint32_t i = port;
629 char buf[sizeof("0000")];
631 for (tp = &eprototable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
636 tp->nxt = newhnamemem(ndo);
640 *cp++ = hex[port >> 12 & 0xf];
641 *cp++ = hex[port >> 8 & 0xf];
642 *cp++ = hex[port >> 4 & 0xf];
643 *cp++ = hex[port & 0xf];
645 tp->name = strdup(buf);
646 if (tp->name == NULL)
647 (*ndo->ndo_error)(ndo, "etherproto_string: strdup(buf)");
652 protoid_string(netdissect_options *ndo, register const u_char *pi)
656 register struct protoidmem *tp;
657 char buf[sizeof("00:00:00:00:00")];
659 tp = lookup_protoid(ndo, pi);
664 if ((j = *pi >> 4) != 0)
666 *cp++ = hex[*pi++ & 0xf];
667 for (i = 4; (int)--i >= 0;) {
669 if ((j = *pi >> 4) != 0)
671 *cp++ = hex[*pi++ & 0xf];
674 tp->p_name = strdup(buf);
675 if (tp->p_name == NULL)
676 (*ndo->ndo_error)(ndo, "protoid_string: strdup(buf)");
680 #define ISONSAP_MAX_LENGTH 20
682 isonsap_string(netdissect_options *ndo, const u_char *nsap,
683 register u_int nsap_length)
685 register u_int nsap_idx;
687 register struct enamemem *tp;
689 if (nsap_length < 1 || nsap_length > ISONSAP_MAX_LENGTH)
690 return ("isonsap_string: illegal length");
692 tp = lookup_nsap(ndo, nsap, nsap_length);
696 tp->e_name = cp = (char *)malloc(sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx"));
698 (*ndo->ndo_error)(ndo, "isonsap_string: malloc");
700 for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
701 *cp++ = hex[*nsap >> 4];
702 *cp++ = hex[*nsap++ & 0xf];
703 if (((nsap_idx & 1) == 0) &&
704 (nsap_idx + 1 < nsap_length)) {
713 tcpport_string(netdissect_options *ndo, u_short port)
715 register struct hnamemem *tp;
716 register uint32_t i = port;
717 char buf[sizeof("00000")];
719 for (tp = &tporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
724 tp->nxt = newhnamemem(ndo);
726 (void)snprintf(buf, sizeof(buf), "%u", i);
727 tp->name = strdup(buf);
728 if (tp->name == NULL)
729 (*ndo->ndo_error)(ndo, "tcpport_string: strdup(buf)");
734 udpport_string(netdissect_options *ndo, register u_short port)
736 register struct hnamemem *tp;
737 register uint32_t i = port;
738 char buf[sizeof("00000")];
740 for (tp = &uporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
745 tp->nxt = newhnamemem(ndo);
747 (void)snprintf(buf, sizeof(buf), "%u", i);
748 tp->name = strdup(buf);
749 if (tp->name == NULL)
750 (*ndo->ndo_error)(ndo, "udpport_string: strdup(buf)");
755 ipxsap_string(netdissect_options *ndo, u_short port)
758 register struct hnamemem *tp;
759 register uint32_t i = port;
760 char buf[sizeof("0000")];
762 for (tp = &ipxsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
767 tp->nxt = newhnamemem(ndo);
771 *cp++ = hex[port >> 12 & 0xf];
772 *cp++ = hex[port >> 8 & 0xf];
773 *cp++ = hex[port >> 4 & 0xf];
774 *cp++ = hex[port & 0xf];
776 tp->name = strdup(buf);
777 if (tp->name == NULL)
778 (*ndo->ndo_error)(ndo, "ipxsap_string: strdup(buf)");
783 init_servarray(netdissect_options *ndo)
786 register struct hnamemem *table;
788 char buf[sizeof("0000000000")];
790 while ((sv = getservent()) != NULL) {
791 int port = ntohs(sv->s_port);
792 i = port & (HASHNAMESIZE-1);
793 if (strcmp(sv->s_proto, "tcp") == 0)
794 table = &tporttable[i];
795 else if (strcmp(sv->s_proto, "udp") == 0)
796 table = &uporttable[i];
802 if (ndo->ndo_nflag) {
803 (void)snprintf(buf, sizeof(buf), "%d", port);
804 table->name = strdup(buf);
806 table->name = strdup(sv->s_name);
807 if (table->name == NULL)
808 (*ndo->ndo_error)(ndo, "init_servarray: strdup");
811 table->nxt = newhnamemem(ndo);
816 static const struct eproto {
820 { "pup", ETHERTYPE_PUP },
821 { "xns", ETHERTYPE_NS },
822 { "ip", ETHERTYPE_IP },
823 { "ip6", ETHERTYPE_IPV6 },
824 { "arp", ETHERTYPE_ARP },
825 { "rarp", ETHERTYPE_REVARP },
826 { "sprite", ETHERTYPE_SPRITE },
827 { "mopdl", ETHERTYPE_MOPDL },
828 { "moprc", ETHERTYPE_MOPRC },
829 { "decnet", ETHERTYPE_DN },
830 { "lat", ETHERTYPE_LAT },
831 { "sca", ETHERTYPE_SCA },
832 { "lanbridge", ETHERTYPE_LANBRIDGE },
833 { "vexp", ETHERTYPE_VEXP },
834 { "vprod", ETHERTYPE_VPROD },
835 { "atalk", ETHERTYPE_ATALK },
836 { "atalkarp", ETHERTYPE_AARP },
837 { "loopback", ETHERTYPE_LOOPBACK },
838 { "decdts", ETHERTYPE_DECDTS },
839 { "decdns", ETHERTYPE_DECDNS },
844 init_eprotoarray(netdissect_options *ndo)
847 register struct hnamemem *table;
849 for (i = 0; eproto_db[i].s; i++) {
850 int j = htons(eproto_db[i].p) & (HASHNAMESIZE-1);
851 table = &eprototable[j];
854 table->name = eproto_db[i].s;
855 table->addr = htons(eproto_db[i].p);
856 table->nxt = newhnamemem(ndo);
860 static const struct protoidlist {
861 const u_char protoid[5];
864 {{ 0x00, 0x00, 0x0c, 0x01, 0x07 }, "CiscoMLS" },
865 {{ 0x00, 0x00, 0x0c, 0x20, 0x00 }, "CiscoCDP" },
866 {{ 0x00, 0x00, 0x0c, 0x20, 0x01 }, "CiscoCGMP" },
867 {{ 0x00, 0x00, 0x0c, 0x20, 0x03 }, "CiscoVTP" },
868 {{ 0x00, 0xe0, 0x2b, 0x00, 0xbb }, "ExtremeEDP" },
869 {{ 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL }
873 * SNAP proto IDs with org code 0:0:0 are actually encapsulated Ethernet
877 init_protoidarray(netdissect_options *ndo)
880 register struct protoidmem *tp;
881 const struct protoidlist *pl;
887 for (i = 0; eproto_db[i].s; i++) {
888 u_short etype = htons(eproto_db[i].p);
890 memcpy((char *)&protoid[3], (char *)&etype, 2);
891 tp = lookup_protoid(ndo, protoid);
892 tp->p_name = strdup(eproto_db[i].s);
893 if (tp->p_name == NULL)
894 (*ndo->ndo_error)(ndo,
895 "init_protoidarray: strdup(eproto_db[i].s)");
897 /* Hardwire some SNAP proto ID names */
898 for (pl = protoidlist; pl->name != NULL; ++pl) {
899 tp = lookup_protoid(ndo, pl->protoid);
900 /* Don't override existing name */
901 if (tp->p_name != NULL)
904 tp->p_name = pl->name;
908 static const struct etherlist {
909 const u_char addr[6];
912 {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, "Broadcast" },
913 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL }
917 * Initialize the ethers hash table. We take two different approaches
918 * depending on whether or not the system provides the ethers name
919 * service. If it does, we just wire in a few names at startup,
920 * and etheraddr_string() fills in the table on demand. If it doesn't,
921 * then we suck in the entire /etc/ethers file at startup. The idea
922 * is that parsing the local file will be fast, but spinning through
923 * all the ethers entries via NIS & next_etherent might be very slow.
925 * XXX pcap_next_etherent doesn't belong in the pcap interface, but
926 * since the pcap module already does name-to-address translation,
927 * it's already does most of the work for the ethernet address-to-name
928 * translation, so we just pcap_next_etherent as a convenience.
931 init_etherarray(netdissect_options *ndo)
933 register const struct etherlist *el;
934 register struct enamemem *tp;
935 #ifdef USE_ETHER_NTOHOST
938 register struct pcap_etherent *ep;
941 /* Suck in entire ethers file */
942 fp = fopen(PCAP_ETHERS_FILE, "r");
944 while ((ep = pcap_next_etherent(fp)) != NULL) {
945 tp = lookup_emem(ndo, ep->addr);
946 tp->e_name = strdup(ep->name);
947 if (tp->e_name == NULL)
948 (*ndo->ndo_error)(ndo,
949 "init_etherarray: strdup(ep->addr)");
955 /* Hardwire some ethernet names */
956 for (el = etherlist; el->name != NULL; ++el) {
957 tp = lookup_emem(ndo, el->addr);
958 /* Don't override existing name */
959 if (tp->e_name != NULL)
962 #ifdef USE_ETHER_NTOHOST
964 * Use YP/NIS version of name if available.
966 if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) {
967 tp->e_name = strdup(name);
968 if (tp->e_name == NULL)
969 (*ndo->ndo_error)(ndo,
970 "init_etherarray: strdup(name)");
974 tp->e_name = el->name;
978 static const struct tok ipxsap_db[] = {
979 { 0x0000, "Unknown" },
981 { 0x0002, "User Group" },
982 { 0x0003, "PrintQueue" },
983 { 0x0004, "FileServer" },
984 { 0x0005, "JobServer" },
985 { 0x0006, "Gateway" },
986 { 0x0007, "PrintServer" },
987 { 0x0008, "ArchiveQueue" },
988 { 0x0009, "ArchiveServer" },
989 { 0x000a, "JobQueue" },
990 { 0x000b, "Administration" },
991 { 0x000F, "Novell TI-RPC" },
992 { 0x0017, "Diagnostics" },
993 { 0x0020, "NetBIOS" },
994 { 0x0021, "NAS SNA Gateway" },
995 { 0x0023, "NACS AsyncGateway" },
996 { 0x0024, "RemoteBridge/RoutingService" },
997 { 0x0026, "BridgeServer" },
998 { 0x0027, "TCP/IP Gateway" },
999 { 0x0028, "Point-to-point X.25 BridgeServer" },
1000 { 0x0029, "3270 Gateway" },
1001 { 0x002a, "CHI Corp" },
1002 { 0x002c, "PC Chalkboard" },
1003 { 0x002d, "TimeSynchServer" },
1004 { 0x002e, "ARCserve5.0/PalindromeBackup" },
1005 { 0x0045, "DI3270 Gateway" },
1006 { 0x0047, "AdvertisingPrintServer" },
1007 { 0x004a, "NetBlazerModems" },
1008 { 0x004b, "BtrieveVAP" },
1009 { 0x004c, "NetwareSQL" },
1010 { 0x004d, "XtreeNetwork" },
1011 { 0x0050, "BtrieveVAP4.11" },
1012 { 0x0052, "QuickLink" },
1013 { 0x0053, "PrintQueueUser" },
1014 { 0x0058, "Multipoint X.25 Router" },
1015 { 0x0060, "STLB/NLM" },
1016 { 0x0064, "ARCserve" },
1017 { 0x0066, "ARCserve3.0" },
1018 { 0x0072, "WAN CopyUtility" },
1019 { 0x007a, "TES-NetwareVMS" },
1020 { 0x0092, "WATCOM Debugger/EmeraldTapeBackupServer" },
1021 { 0x0095, "DDA OBGYN" },
1022 { 0x0098, "NetwareAccessServer" },
1023 { 0x009a, "Netware for VMS II/NamedPipeServer" },
1024 { 0x009b, "NetwareAccessServer" },
1025 { 0x009e, "PortableNetwareServer/SunLinkNVT" },
1026 { 0x00a1, "PowerchuteAPC UPS" },
1027 { 0x00aa, "LAWserve" },
1028 { 0x00ac, "CompaqIDA StatusMonitor" },
1029 { 0x0100, "PIPE STAIL" },
1030 { 0x0102, "LAN ProtectBindery" },
1031 { 0x0103, "OracleDataBaseServer" },
1032 { 0x0107, "Netware386/RSPX RemoteConsole" },
1033 { 0x010f, "NovellSNA Gateway" },
1034 { 0x0111, "TestServer" },
1035 { 0x0112, "HP PrintServer" },
1036 { 0x0114, "CSA MUX" },
1037 { 0x0115, "CSA LCA" },
1038 { 0x0116, "CSA CM" },
1039 { 0x0117, "CSA SMA" },
1040 { 0x0118, "CSA DBA" },
1041 { 0x0119, "CSA NMA" },
1042 { 0x011a, "CSA SSA" },
1043 { 0x011b, "CSA STATUS" },
1044 { 0x011e, "CSA APPC" },
1045 { 0x0126, "SNA TEST SSA Profile" },
1046 { 0x012a, "CSA TRACE" },
1047 { 0x012b, "NetwareSAA" },
1048 { 0x012e, "IKARUS VirusScan" },
1049 { 0x0130, "CommunicationsExecutive" },
1050 { 0x0133, "NNS DomainServer/NetwareNamingServicesDomain" },
1051 { 0x0135, "NetwareNamingServicesProfile" },
1052 { 0x0137, "Netware386 PrintQueue/NNS PrintQueue" },
1053 { 0x0141, "LAN SpoolServer" },
1054 { 0x0152, "IRMALAN Gateway" },
1055 { 0x0154, "NamedPipeServer" },
1056 { 0x0166, "NetWareManagement" },
1057 { 0x0168, "Intel PICKIT CommServer/Intel CAS TalkServer" },
1058 { 0x0173, "Compaq" },
1059 { 0x0174, "Compaq SNMP Agent" },
1060 { 0x0175, "Compaq" },
1061 { 0x0180, "XTreeServer/XTreeTools" },
1062 { 0x018A, "NASI ServicesBroadcastServer" },
1063 { 0x01b0, "GARP Gateway" },
1064 { 0x01b1, "Binfview" },
1065 { 0x01bf, "IntelLanDeskManager" },
1066 { 0x01ca, "AXTEC" },
1067 { 0x01cb, "ShivaNetModem/E" },
1068 { 0x01cc, "ShivaLanRover/E" },
1069 { 0x01cd, "ShivaLanRover/T" },
1070 { 0x01ce, "ShivaUniversal" },
1071 { 0x01d8, "CastelleFAXPressServer" },
1072 { 0x01da, "CastelleLANPressPrintServer" },
1073 { 0x01dc, "CastelleFAX/Xerox7033 FaxServer/ExcelLanFax" },
1074 { 0x01f0, "LEGATO" },
1075 { 0x01f5, "LEGATO" },
1076 { 0x0233, "NMS Agent/NetwareManagementAgent" },
1077 { 0x0237, "NMS IPX Discovery/LANternReadWriteChannel" },
1078 { 0x0238, "NMS IP Discovery/LANternTrapAlarmChannel" },
1079 { 0x023a, "LANtern" },
1080 { 0x023c, "MAVERICK" },
1081 { 0x023f, "NovellSMDR" },
1082 { 0x024e, "NetwareConnect" },
1083 { 0x024f, "NASI ServerBroadcast Cisco" },
1084 { 0x026a, "NMS ServiceConsole" },
1085 { 0x026b, "TimeSynchronizationServer Netware 4.x" },
1086 { 0x0278, "DirectoryServer Netware 4.x" },
1087 { 0x027b, "NetwareManagementAgent" },
1088 { 0x0280, "Novell File and Printer Sharing Service for PC" },
1089 { 0x0304, "NovellSAA Gateway" },
1090 { 0x0308, "COM/VERMED" },
1091 { 0x030a, "GalacticommWorldgroupServer" },
1092 { 0x030c, "IntelNetport2/HP JetDirect/HP Quicksilver" },
1093 { 0x0320, "AttachmateGateway" },
1094 { 0x0327, "MicrosoftDiagnostiocs" },
1095 { 0x0328, "WATCOM SQL Server" },
1096 { 0x0335, "MultiTechSystems MultisynchCommServer" },
1097 { 0x0343, "Xylogics RemoteAccessServer/LANModem" },
1098 { 0x0355, "ArcadaBackupExec" },
1099 { 0x0358, "MSLCD1" },
1100 { 0x0361, "NETINELO" },
1101 { 0x037e, "Powerchute UPS Monitoring" },
1102 { 0x037f, "ViruSafeNotify" },
1103 { 0x0386, "HP Bridge" },
1104 { 0x0387, "HP Hub" },
1105 { 0x0394, "NetWare SAA Gateway" },
1106 { 0x039b, "LotusNotes" },
1107 { 0x03b7, "CertusAntiVirus" },
1108 { 0x03c4, "ARCserve4.0" },
1109 { 0x03c7, "LANspool3.5" },
1110 { 0x03d7, "LexmarkPrinterServer" },
1111 { 0x03d8, "LexmarkXLE PrinterServer" },
1112 { 0x03dd, "BanyanENS NetwareClient" },
1113 { 0x03de, "GuptaSequelBaseServer/NetWareSQL" },
1114 { 0x03e1, "UnivelUnixware" },
1115 { 0x03e4, "UnivelUnixware" },
1116 { 0x03fc, "IntelNetport" },
1117 { 0x03fd, "PrintServerQueue" },
1118 { 0x040A, "ipnServer" },
1119 { 0x040D, "LVERRMAN" },
1120 { 0x040E, "LVLIC" },
1121 { 0x0414, "NET Silicon (DPI)/Kyocera" },
1122 { 0x0429, "SiteLockVirus" },
1123 { 0x0432, "UFHELPR???" },
1124 { 0x0433, "Synoptics281xAdvancedSNMPAgent" },
1125 { 0x0444, "MicrosoftNT SNA Server" },
1126 { 0x0448, "Oracle" },
1127 { 0x044c, "ARCserve5.01" },
1128 { 0x0457, "CanonGP55" },
1129 { 0x045a, "QMS Printers" },
1130 { 0x045b, "DellSCSI Array" },
1131 { 0x0491, "NetBlazerModems" },
1132 { 0x04ac, "OnTimeScheduler" },
1133 { 0x04b0, "CD-Net" },
1134 { 0x0513, "EmulexNQA" },
1135 { 0x0520, "SiteLockChecks" },
1136 { 0x0529, "SiteLockChecks" },
1137 { 0x052d, "CitrixOS2 AppServer" },
1138 { 0x0535, "Tektronix" },
1139 { 0x0536, "Milan" },
1140 { 0x055d, "Attachmate SNA gateway" },
1141 { 0x056b, "IBM8235 ModemServer" },
1142 { 0x056c, "ShivaLanRover/E PLUS" },
1143 { 0x056d, "ShivaLanRover/T PLUS" },
1144 { 0x0580, "McAfeeNetShield" },
1145 { 0x05B8, "NLM to workstation communication (Revelation Software)" },
1146 { 0x05BA, "CompatibleSystemsRouters" },
1147 { 0x05BE, "CheyenneHierarchicalStorageManager" },
1148 { 0x0606, "JCWatermarkImaging" },
1149 { 0x060c, "AXISNetworkPrinter" },
1150 { 0x0610, "AdaptecSCSIManagement" },
1151 { 0x0621, "IBM AntiVirus" },
1152 { 0x0640, "Windows95 RemoteRegistryService" },
1153 { 0x064e, "MicrosoftIIS" },
1154 { 0x067b, "Microsoft Win95/98 File and Print Sharing for NetWare" },
1155 { 0x067c, "Microsoft Win95/98 File and Print Sharing for NetWare" },
1156 { 0x076C, "Xerox" },
1157 { 0x079b, "ShivaLanRover/E 115" },
1158 { 0x079c, "ShivaLanRover/T 115" },
1159 { 0x07B4, "CubixWorldDesk" },
1160 { 0x07c2, "Quarterdeck IWare Connect V2.x NLM" },
1161 { 0x07c1, "Quarterdeck IWare Connect V3.x NLM" },
1162 { 0x0810, "ELAN License Server Demo" },
1163 { 0x0824, "ShivaLanRoverAccessSwitch/E" },
1164 { 0x086a, "ISSC Collector" },
1165 { 0x087f, "ISSC DAS AgentAIX" },
1166 { 0x0880, "Intel Netport PRO" },
1167 { 0x0881, "Intel Netport PRO" },
1168 { 0x0b29, "SiteLock" },
1169 { 0x0c29, "SiteLockApplications" },
1170 { 0x0c2c, "LicensingServer" },
1171 { 0x2101, "PerformanceTechnologyInstantInternet" },
1172 { 0x2380, "LAI SiteLock" },
1173 { 0x238c, "MeetingMaker" },
1174 { 0x4808, "SiteLockServer/SiteLockMetering" },
1175 { 0x5555, "SiteLockUser" },
1176 { 0x6312, "Tapeware" },
1177 { 0x6f00, "RabbitGateway" },
1178 { 0x7703, "MODEM" },
1179 { 0x8002, "NetPortPrinters" },
1180 { 0x8008, "WordPerfectNetworkVersion" },
1181 { 0x85BE, "Cisco EIGRP" },
1182 { 0x8888, "WordPerfectNetworkVersion/QuickNetworkManagement" },
1183 { 0x9000, "McAfeeNetShield" },
1184 { 0x9604, "CSA-NT_MON" },
1185 { 0xb6a8, "OceanIsleReachoutRemoteControl" },
1186 { 0xf11f, "SiteLockMetering" },
1187 { 0xf1ff, "SiteLock" },
1188 { 0xf503, "Microsoft SQL Server" },
1189 { 0xF905, "IBM TimeAndPlace" },
1190 { 0xfbfb, "TopCallIII FaxServer" },
1191 { 0xffff, "AnyService/Wildcard" },
1196 init_ipxsaparray(netdissect_options *ndo)
1199 register struct hnamemem *table;
1201 for (i = 0; ipxsap_db[i].s != NULL; i++) {
1202 int j = htons(ipxsap_db[i].v) & (HASHNAMESIZE-1);
1203 table = &ipxsaptable[j];
1206 table->name = ipxsap_db[i].s;
1207 table->addr = htons(ipxsap_db[i].v);
1208 table->nxt = newhnamemem(ndo);
1213 * Initialize the address to name translation machinery. We map all
1214 * non-local IP addresses to numeric addresses if ndo->ndo_fflag is true
1215 * (i.e., to prevent blocking on the nameserver). localnet is the IP address
1216 * of the local network. mask is its subnet mask.
1219 init_addrtoname(netdissect_options *ndo, uint32_t localnet, uint32_t mask)
1221 if (ndo->ndo_fflag) {
1222 f_localnet = localnet;
1227 * Simplest way to suppress names.
1231 init_etherarray(ndo);
1232 init_servarray(ndo);
1233 init_eprotoarray(ndo);
1234 init_protoidarray(ndo);
1235 init_ipxsaparray(ndo);
1239 dnaddr_string(netdissect_options *ndo, u_short dnaddr)
1241 register struct hnamemem *tp;
1243 for (tp = &dnaddrtable[dnaddr & (HASHNAMESIZE-1)]; tp->nxt != NULL;
1245 if (tp->addr == dnaddr)
1249 tp->nxt = newhnamemem(ndo);
1250 tp->name = dnnum_string(ndo, dnaddr);
1255 /* Return a zero'ed hnamemem struct and cuts down on calloc() overhead */
1257 newhnamemem(netdissect_options *ndo)
1259 register struct hnamemem *p;
1260 static struct hnamemem *ptr = NULL;
1261 static u_int num = 0;
1265 ptr = (struct hnamemem *)calloc(num, sizeof (*ptr));
1267 (*ndo->ndo_error)(ndo, "newhnamemem: calloc");
1274 /* Return a zero'ed h6namemem struct and cuts down on calloc() overhead */
1276 newh6namemem(netdissect_options *ndo)
1278 register struct h6namemem *p;
1279 static struct h6namemem *ptr = NULL;
1280 static u_int num = 0;
1284 ptr = (struct h6namemem *)calloc(num, sizeof (*ptr));
1286 (*ndo->ndo_error)(ndo, "newh6namemem: calloc");
1293 /* Represent TCI part of the 802.1Q 4-octet tag as text. */
1295 ieee8021q_tci_string(const uint16_t tci)
1297 static char buf[128];
1298 snprintf(buf, sizeof(buf), "vlan %u, p %u%s",
1301 (tci & 0x1000) ? ", DEI" : "");