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>
37 #define NTOHL(x) (x) = ntohl(x)
38 #define NTOHS(x) (x) = ntohs(x)
39 #define HTONL(x) (x) = htonl(x)
40 #define HTONS(x) (x) = htons(x)
43 #ifdef USE_ETHER_NTOHOST
44 #ifdef HAVE_NETINET_IF_ETHER_H
45 struct mbuf
; /* Squelch compiler warnings on some platforms for */
46 struct rtentry
; /* declarations in <net/if.h> */
47 #include <net/if.h> /* for "struct ifnet" in "struct arpcom" on Solaris */
48 #include <netinet/if_ether.h>
49 #endif /* HAVE_NETINET_IF_ETHER_H */
50 #ifdef NETINET_ETHER_H_DECLARES_ETHER_NTOHOST
51 #include <netinet/ether.h>
52 #endif /* NETINET_ETHER_H_DECLARES_ETHER_NTOHOST */
54 #if !defined(HAVE_DECL_ETHER_NTOHOST) || !HAVE_DECL_ETHER_NTOHOST
55 #ifndef HAVE_STRUCT_ETHER_ADDR
57 unsigned char ether_addr_octet
[6];
60 extern int ether_ntohost(char *, const struct ether_addr
*);
63 #endif /* USE_ETHER_NTOHOST */
66 #include <pcap-namedb.h>
67 #ifndef HAVE_GETSERVENT
68 #include <getservent.h>
75 #include "netdissect.h"
76 #include "addrtoname.h"
77 #include "addrtostr.h"
78 #include "ethertype.h"
84 * hash tables for whatever-to-name translations
86 * ndo_error() called on strdup(3) failure
89 #define HASHNAMESIZE 4096
97 static struct hnamemem hnametable
[HASHNAMESIZE
];
98 static struct hnamemem tporttable
[HASHNAMESIZE
];
99 static struct hnamemem uporttable
[HASHNAMESIZE
];
100 static struct hnamemem eprototable
[HASHNAMESIZE
];
101 static struct hnamemem dnaddrtable
[HASHNAMESIZE
];
102 static struct hnamemem ipxsaptable
[HASHNAMESIZE
];
106 * fake gethostbyaddr for Win2k/XP
107 * gethostbyaddr() returns incorrect value when AF_INET6 is passed
110 * h_name in struct hostent is only valid.
112 static struct hostent
*
113 win32_gethostbyaddr(const char *addr
, int len
, int type
)
115 static struct hostent host
;
116 static char hostbuf
[NI_MAXHOST
];
117 char hname
[NI_MAXHOST
];
118 struct sockaddr_in6 addr6
;
120 host
.h_name
= hostbuf
;
123 return gethostbyaddr(addr
, len
, type
);
126 memset(&addr6
, 0, sizeof(addr6
));
127 addr6
.sin6_family
= AF_INET6
;
128 memcpy(&addr6
.sin6_addr
, addr
, len
);
129 if (getnameinfo((struct sockaddr
*)&addr6
, sizeof(addr6
),
130 hname
, sizeof(hname
), NULL
, 0, 0)) {
133 strcpy(host
.h_name
, hname
);
141 #define gethostbyaddr win32_gethostbyaddr
145 struct in6_addr addr
;
147 struct h6namemem
*nxt
;
150 static struct h6namemem h6nametable
[HASHNAMESIZE
];
157 u_char
*e_nsap
; /* used only for nsaptable[] */
158 struct enamemem
*e_nxt
;
161 static struct enamemem enametable
[HASHNAMESIZE
];
162 static struct enamemem nsaptable
[HASHNAMESIZE
];
170 unsigned int bs_nbytes
;
171 struct bsnamemem
*bs_nxt
;
174 static struct bsnamemem bytestringtable
[HASHNAMESIZE
];
180 struct protoidmem
*p_nxt
;
183 static struct protoidmem protoidtable
[HASHNAMESIZE
];
186 * A faster replacement for inet_ntoa().
194 static char buf
[sizeof(".xxx.xxx.xxx.xxx")];
197 cp
= buf
+ sizeof(buf
);
203 *--cp
= byte
% 10 + '0';
206 *--cp
= byte
% 10 + '0';
218 static uint32_t f_netmask
;
219 static uint32_t f_localnet
;
221 extern cap_channel_t
*capdns
;
225 * Return a name for the IP address pointed to by ap. This address
226 * is assumed to be in network byte order.
228 * NOTE: ap is *NOT* necessarily part of the packet data (not even if
229 * this is being called with the "ipaddr_string()" macro), so you
230 * *CANNOT* use the ND_TCHECK{2}/ND_TTEST{2} macros on it. Furthermore,
231 * even in cases where it *is* part of the packet data, the caller
232 * would still have to check for a null return value, even if it's
233 * just printing the return value with "%s" - not all versions of
234 * printf print "(null)" with "%s" and a null pointer, some of them
235 * don't check for a null pointer and crash in that case.
237 * The callers of this routine should, before handing this routine
238 * a pointer to packet data, be sure that the data is present in
239 * the packet buffer. They should probably do those checks anyway,
240 * as other data at that layer might not be IP addresses, and it
241 * also needs to check whether they're present in the packet buffer.
244 getname(netdissect_options
*ndo
, const u_char
*ap
)
250 memcpy(&addr
, ap
, sizeof(addr
));
251 p
= &hnametable
[addr
& (HASHNAMESIZE
-1)];
252 for (; p
->nxt
; p
= p
->nxt
) {
257 p
->nxt
= newhnamemem(ndo
);
260 * Print names unless:
262 * (2) Address is foreign and -f was given. (If -f was not
263 * given, f_netmask and f_localnet are 0 and the test
266 if (!ndo
->ndo_nflag
&&
267 (addr
& f_netmask
) == f_localnet
) {
269 if (capdns
!= NULL
) {
270 hp
= cap_gethostbyaddr(capdns
, (char *)&addr
, 4,
274 hp
= gethostbyaddr((char *)&addr
, 4, AF_INET
);
278 p
->name
= strdup(hp
->h_name
);
280 (*ndo
->ndo_error
)(ndo
,
281 "getname: strdup(hp->h_name)");
282 if (ndo
->ndo_Nflag
) {
283 /* Remove domain qualifications */
284 dotp
= strchr(p
->name
, '.');
291 p
->name
= strdup(intoa(addr
));
293 (*ndo
->ndo_error
)(ndo
, "getname: strdup(intoa(addr))");
298 * Return a name for the IP6 address pointed to by ap. This address
299 * is assumed to be in network byte order.
302 getname6(netdissect_options
*ndo
, const u_char
*ap
)
306 struct in6_addr addr
;
307 struct for_hash_addr
{
314 char ntop_buf
[INET6_ADDRSTRLEN
];
316 memcpy(&addr
, ap
, sizeof(addr
));
317 p
= &h6nametable
[addr
.addra
.d
& (HASHNAMESIZE
-1)];
318 for (; p
->nxt
; p
= p
->nxt
) {
319 if (memcmp(&p
->addr
, &addr
, sizeof(addr
)) == 0)
323 p
->nxt
= newh6namemem(ndo
);
326 * Do not print names if -n was given.
328 if (!ndo
->ndo_nflag
) {
330 if (capdns
!= NULL
) {
331 hp
= cap_gethostbyaddr(capdns
, (char *)&addr
,
332 sizeof(addr
), AF_INET6
);
335 hp
= gethostbyaddr((char *)&addr
, sizeof(addr
),
340 p
->name
= strdup(hp
->h_name
);
342 (*ndo
->ndo_error
)(ndo
,
343 "getname6: strdup(hp->h_name)");
344 if (ndo
->ndo_Nflag
) {
345 /* Remove domain qualifications */
346 dotp
= strchr(p
->name
, '.');
353 cp
= addrtostr6(ap
, ntop_buf
, sizeof(ntop_buf
));
354 p
->name
= strdup(cp
);
356 (*ndo
->ndo_error
)(ndo
, "getname6: strdup(cp)");
360 static const char hex
[16] = {
361 '0', '1', '2', '3', '4', '5', '6', '7',
362 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
365 /* Find the hash node that corresponds the ether address 'ep' */
367 static inline struct enamemem
*
368 lookup_emem(netdissect_options
*ndo
, const u_char
*ep
)
373 k
= (ep
[0] << 8) | ep
[1];
374 j
= (ep
[2] << 8) | ep
[3];
375 i
= (ep
[4] << 8) | ep
[5];
377 tp
= &enametable
[(i
^ j
) & (HASHNAMESIZE
-1)];
379 if (tp
->e_addr0
== i
&&
388 tp
->e_nxt
= (struct enamemem
*)calloc(1, sizeof(*tp
));
389 if (tp
->e_nxt
== NULL
)
390 (*ndo
->ndo_error
)(ndo
, "lookup_emem: calloc");
396 * Find the hash node that corresponds to the bytestring 'bs'
400 static inline struct bsnamemem
*
401 lookup_bytestring(netdissect_options
*ndo
, const u_char
*bs
,
402 const unsigned int nlen
)
404 struct bsnamemem
*tp
;
408 k
= (bs
[0] << 8) | bs
[1];
409 j
= (bs
[2] << 8) | bs
[3];
410 i
= (bs
[4] << 8) | bs
[5];
411 } else if (nlen
>= 4) {
412 k
= (bs
[0] << 8) | bs
[1];
413 j
= (bs
[2] << 8) | bs
[3];
418 tp
= &bytestringtable
[(i
^ j
) & (HASHNAMESIZE
-1)];
420 if (nlen
== tp
->bs_nbytes
&&
424 memcmp((const char *)bs
, (const char *)(tp
->bs_bytes
), nlen
) == 0)
433 tp
->bs_bytes
= (u_char
*) calloc(1, nlen
);
434 if (tp
->bs_bytes
== NULL
)
435 (*ndo
->ndo_error
)(ndo
, "lookup_bytestring: calloc");
437 memcpy(tp
->bs_bytes
, bs
, nlen
);
438 tp
->bs_nbytes
= nlen
;
439 tp
->bs_nxt
= (struct bsnamemem
*)calloc(1, sizeof(*tp
));
440 if (tp
->bs_nxt
== NULL
)
441 (*ndo
->ndo_error
)(ndo
, "lookup_bytestring: calloc");
446 /* Find the hash node that corresponds the NSAP 'nsap' */
448 static inline struct enamemem
*
449 lookup_nsap(netdissect_options
*ndo
, const u_char
*nsap
,
456 if (nsap_length
> 6) {
457 ensap
= nsap
+ nsap_length
- 6;
458 k
= (ensap
[0] << 8) | ensap
[1];
459 j
= (ensap
[2] << 8) | ensap
[3];
460 i
= (ensap
[4] << 8) | ensap
[5];
465 tp
= &nsaptable
[(i
^ j
) & (HASHNAMESIZE
-1)];
467 if (nsap_length
== tp
->e_nsap
[0] &&
471 memcmp((const char *)nsap
,
472 (char *)&(tp
->e_nsap
[1]), nsap_length
) == 0)
479 tp
->e_nsap
= (u_char
*)malloc(nsap_length
+ 1);
480 if (tp
->e_nsap
== NULL
)
481 (*ndo
->ndo_error
)(ndo
, "lookup_nsap: malloc");
482 tp
->e_nsap
[0] = (u_char
)nsap_length
; /* guaranteed < ISONSAP_MAX_LENGTH */
483 memcpy((char *)&tp
->e_nsap
[1], (const char *)nsap
, nsap_length
);
484 tp
->e_nxt
= (struct enamemem
*)calloc(1, sizeof(*tp
));
485 if (tp
->e_nxt
== NULL
)
486 (*ndo
->ndo_error
)(ndo
, "lookup_nsap: calloc");
491 /* Find the hash node that corresponds the protoid 'pi'. */
493 static inline struct protoidmem
*
494 lookup_protoid(netdissect_options
*ndo
, const u_char
*pi
)
497 struct protoidmem
*tp
;
499 /* 5 octets won't be aligned */
500 i
= (((pi
[0] << 8) + pi
[1]) << 8) + pi
[2];
501 j
= (pi
[3] << 8) + pi
[4];
502 /* XXX should be endian-insensitive, but do big-endian testing XXX */
504 tp
= &protoidtable
[(i
^ j
) & (HASHNAMESIZE
-1)];
506 if (tp
->p_oui
== i
&& tp
->p_proto
== j
)
512 tp
->p_nxt
= (struct protoidmem
*)calloc(1, sizeof(*tp
));
513 if (tp
->p_nxt
== NULL
)
514 (*ndo
->ndo_error
)(ndo
, "lookup_protoid: calloc");
520 etheraddr_string(netdissect_options
*ndo
, const u_char
*ep
)
528 tp
= lookup_emem(ndo
, ep
);
531 #ifdef USE_ETHER_NTOHOST
532 if (!ndo
->ndo_nflag
) {
535 if (ether_ntohost(buf2
, (const struct ether_addr
*)ep
) == 0) {
536 tp
->e_name
= strdup(buf2
);
537 if (tp
->e_name
== NULL
)
538 (*ndo
->ndo_error
)(ndo
,
539 "etheraddr_string: strdup(buf2)");
545 oui
= EXTRACT_BE_U_3(ep
);
546 *cp
++ = hex
[*ep
>> 4 ];
547 *cp
++ = hex
[*ep
++ & 0xf];
548 for (i
= 5; --i
>= 0;) {
550 *cp
++ = hex
[*ep
>> 4 ];
551 *cp
++ = hex
[*ep
++ & 0xf];
554 if (!ndo
->ndo_nflag
) {
555 snprintf(cp
, BUFSIZE
- (2 + 5*3), " (oui %s)",
556 tok2str(oui_values
, "Unknown", oui
));
559 tp
->e_name
= strdup(buf
);
560 if (tp
->e_name
== NULL
)
561 (*ndo
->ndo_error
)(ndo
, "etheraddr_string: strdup(buf)");
566 le64addr_string(netdissect_options
*ndo
, const u_char
*ep
)
568 const unsigned int len
= 8;
571 struct bsnamemem
*tp
;
574 tp
= lookup_bytestring(ndo
, ep
, len
);
576 return (tp
->bs_name
);
579 for (i
= len
; i
> 0 ; --i
) {
580 *cp
++ = hex
[*(ep
+ i
- 1) >> 4];
581 *cp
++ = hex
[*(ep
+ i
- 1) & 0xf];
588 tp
->bs_name
= strdup(buf
);
589 if (tp
->bs_name
== NULL
)
590 (*ndo
->ndo_error
)(ndo
, "le64addr_string: strdup(buf)");
592 return (tp
->bs_name
);
596 linkaddr_string(netdissect_options
*ndo
, const u_char
*ep
,
597 const unsigned int type
, const unsigned int len
)
601 struct bsnamemem
*tp
;
606 if (type
== LINKADDR_ETHER
&& len
== MAC_ADDR_LEN
)
607 return (etheraddr_string(ndo
, ep
));
609 if (type
== LINKADDR_FRELAY
)
610 return (q922_string(ndo
, ep
, len
));
612 tp
= lookup_bytestring(ndo
, ep
, len
);
614 return (tp
->bs_name
);
616 tp
->bs_name
= cp
= (char *)malloc(len
*3);
617 if (tp
->bs_name
== NULL
)
618 (*ndo
->ndo_error
)(ndo
, "linkaddr_string: malloc");
619 *cp
++ = hex
[*ep
>> 4];
620 *cp
++ = hex
[*ep
++ & 0xf];
621 for (i
= len
-1; i
> 0 ; --i
) {
623 *cp
++ = hex
[*ep
>> 4];
624 *cp
++ = hex
[*ep
++ & 0xf];
627 return (tp
->bs_name
);
631 etherproto_string(netdissect_options
*ndo
, u_short port
)
636 char buf
[sizeof("0000")];
638 for (tp
= &eprototable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
643 tp
->nxt
= newhnamemem(ndo
);
647 *cp
++ = hex
[port
>> 12 & 0xf];
648 *cp
++ = hex
[port
>> 8 & 0xf];
649 *cp
++ = hex
[port
>> 4 & 0xf];
650 *cp
++ = hex
[port
& 0xf];
652 tp
->name
= strdup(buf
);
653 if (tp
->name
== NULL
)
654 (*ndo
->ndo_error
)(ndo
, "etherproto_string: strdup(buf)");
658 #define ISONSAP_MAX_LENGTH 20
660 isonsap_string(netdissect_options
*ndo
, const u_char
*nsap
,
667 if (nsap_length
< 1 || nsap_length
> ISONSAP_MAX_LENGTH
)
668 return ("isonsap_string: illegal length");
670 tp
= lookup_nsap(ndo
, nsap
, nsap_length
);
674 tp
->e_name
= cp
= (char *)malloc(sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx"));
676 (*ndo
->ndo_error
)(ndo
, "isonsap_string: malloc");
678 for (nsap_idx
= 0; nsap_idx
< nsap_length
; nsap_idx
++) {
679 *cp
++ = hex
[*nsap
>> 4];
680 *cp
++ = hex
[*nsap
++ & 0xf];
681 if (((nsap_idx
& 1) == 0) &&
682 (nsap_idx
+ 1 < nsap_length
)) {
691 tcpport_string(netdissect_options
*ndo
, u_short port
)
695 char buf
[sizeof("00000")];
697 for (tp
= &tporttable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
702 tp
->nxt
= newhnamemem(ndo
);
704 (void)snprintf(buf
, sizeof(buf
), "%u", i
);
705 tp
->name
= strdup(buf
);
706 if (tp
->name
== NULL
)
707 (*ndo
->ndo_error
)(ndo
, "tcpport_string: strdup(buf)");
712 udpport_string(netdissect_options
*ndo
, u_short port
)
716 char buf
[sizeof("00000")];
718 for (tp
= &uporttable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
723 tp
->nxt
= newhnamemem(ndo
);
725 (void)snprintf(buf
, sizeof(buf
), "%u", i
);
726 tp
->name
= strdup(buf
);
727 if (tp
->name
== NULL
)
728 (*ndo
->ndo_error
)(ndo
, "udpport_string: strdup(buf)");
733 ipxsap_string(netdissect_options
*ndo
, u_short port
)
738 char buf
[sizeof("0000")];
740 for (tp
= &ipxsaptable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
745 tp
->nxt
= newhnamemem(ndo
);
749 *cp
++ = hex
[port
>> 12 & 0xf];
750 *cp
++ = hex
[port
>> 8 & 0xf];
751 *cp
++ = hex
[port
>> 4 & 0xf];
752 *cp
++ = hex
[port
& 0xf];
754 tp
->name
= strdup(buf
);
755 if (tp
->name
== NULL
)
756 (*ndo
->ndo_error
)(ndo
, "ipxsap_string: strdup(buf)");
761 init_servarray(netdissect_options
*ndo
)
764 struct hnamemem
*table
;
766 char buf
[sizeof("0000000000")];
768 while ((sv
= getservent()) != NULL
) {
769 int port
= ntohs(sv
->s_port
);
770 i
= port
& (HASHNAMESIZE
-1);
771 if (strcmp(sv
->s_proto
, "tcp") == 0)
772 table
= &tporttable
[i
];
773 else if (strcmp(sv
->s_proto
, "udp") == 0)
774 table
= &uporttable
[i
];
780 if (ndo
->ndo_nflag
) {
781 (void)snprintf(buf
, sizeof(buf
), "%d", port
);
782 table
->name
= strdup(buf
);
784 table
->name
= strdup(sv
->s_name
);
785 if (table
->name
== NULL
)
786 (*ndo
->ndo_error
)(ndo
, "init_servarray: strdup");
789 table
->nxt
= newhnamemem(ndo
);
794 static const struct eproto
{
798 { "pup", ETHERTYPE_PUP
},
799 { "xns", ETHERTYPE_NS
},
800 { "ip", ETHERTYPE_IP
},
801 { "ip6", ETHERTYPE_IPV6
},
802 { "arp", ETHERTYPE_ARP
},
803 { "rarp", ETHERTYPE_REVARP
},
804 { "sprite", ETHERTYPE_SPRITE
},
805 { "mopdl", ETHERTYPE_MOPDL
},
806 { "moprc", ETHERTYPE_MOPRC
},
807 { "decnet", ETHERTYPE_DN
},
808 { "lat", ETHERTYPE_LAT
},
809 { "sca", ETHERTYPE_SCA
},
810 { "lanbridge", ETHERTYPE_LANBRIDGE
},
811 { "vexp", ETHERTYPE_VEXP
},
812 { "vprod", ETHERTYPE_VPROD
},
813 { "atalk", ETHERTYPE_ATALK
},
814 { "atalkarp", ETHERTYPE_AARP
},
815 { "loopback", ETHERTYPE_LOOPBACK
},
816 { "decdts", ETHERTYPE_DECDTS
},
817 { "decdns", ETHERTYPE_DECDNS
},
822 init_eprotoarray(netdissect_options
*ndo
)
825 struct hnamemem
*table
;
827 for (i
= 0; eproto_db
[i
].s
; i
++) {
828 int j
= htons(eproto_db
[i
].p
) & (HASHNAMESIZE
-1);
829 table
= &eprototable
[j
];
832 table
->name
= eproto_db
[i
].s
;
833 table
->addr
= htons(eproto_db
[i
].p
);
834 table
->nxt
= newhnamemem(ndo
);
838 static const struct protoidlist
{
839 const u_char protoid
[5];
842 {{ 0x00, 0x00, 0x0c, 0x01, 0x07 }, "CiscoMLS" },
843 {{ 0x00, 0x00, 0x0c, 0x20, 0x00 }, "CiscoCDP" },
844 {{ 0x00, 0x00, 0x0c, 0x20, 0x01 }, "CiscoCGMP" },
845 {{ 0x00, 0x00, 0x0c, 0x20, 0x03 }, "CiscoVTP" },
846 {{ 0x00, 0xe0, 0x2b, 0x00, 0xbb }, "ExtremeEDP" },
847 {{ 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL
}
851 * SNAP proto IDs with org code 0:0:0 are actually encapsulated Ethernet
855 init_protoidarray(netdissect_options
*ndo
)
858 struct protoidmem
*tp
;
859 const struct protoidlist
*pl
;
865 for (i
= 0; eproto_db
[i
].s
; i
++) {
866 u_short etype
= htons(eproto_db
[i
].p
);
868 memcpy((char *)&protoid
[3], (char *)&etype
, 2);
869 tp
= lookup_protoid(ndo
, protoid
);
870 tp
->p_name
= strdup(eproto_db
[i
].s
);
871 if (tp
->p_name
== NULL
)
872 (*ndo
->ndo_error
)(ndo
,
873 "init_protoidarray: strdup(eproto_db[i].s)");
875 /* Hardwire some SNAP proto ID names */
876 for (pl
= protoidlist
; pl
->name
!= NULL
; ++pl
) {
877 tp
= lookup_protoid(ndo
, pl
->protoid
);
878 /* Don't override existing name */
879 if (tp
->p_name
!= NULL
)
882 tp
->p_name
= pl
->name
;
886 static const struct etherlist
{
887 const u_char addr
[6];
890 {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, "Broadcast" },
891 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL
}
895 * Initialize the ethers hash table. We take two different approaches
896 * depending on whether or not the system provides the ethers name
897 * service. If it does, we just wire in a few names at startup,
898 * and etheraddr_string() fills in the table on demand. If it doesn't,
899 * then we suck in the entire /etc/ethers file at startup. The idea
900 * is that parsing the local file will be fast, but spinning through
901 * all the ethers entries via NIS & next_etherent might be very slow.
903 * XXX pcap_next_etherent doesn't belong in the pcap interface, but
904 * since the pcap module already does name-to-address translation,
905 * it's already does most of the work for the ethernet address-to-name
906 * translation, so we just pcap_next_etherent as a convenience.
909 init_etherarray(netdissect_options
*ndo
)
911 const struct etherlist
*el
;
913 #ifdef USE_ETHER_NTOHOST
916 struct pcap_etherent
*ep
;
919 /* Suck in entire ethers file */
920 fp
= fopen(PCAP_ETHERS_FILE
, "r");
922 while ((ep
= pcap_next_etherent(fp
)) != NULL
) {
923 tp
= lookup_emem(ndo
, ep
->addr
);
924 tp
->e_name
= strdup(ep
->name
);
925 if (tp
->e_name
== NULL
)
926 (*ndo
->ndo_error
)(ndo
,
927 "init_etherarray: strdup(ep->addr)");
933 /* Hardwire some ethernet names */
934 for (el
= etherlist
; el
->name
!= NULL
; ++el
) {
935 tp
= lookup_emem(ndo
, el
->addr
);
936 /* Don't override existing name */
937 if (tp
->e_name
!= NULL
)
940 #ifdef USE_ETHER_NTOHOST
942 * Use YP/NIS version of name if available.
944 if (ether_ntohost(name
, (const struct ether_addr
*)el
->addr
) == 0) {
945 tp
->e_name
= strdup(name
);
946 if (tp
->e_name
== NULL
)
947 (*ndo
->ndo_error
)(ndo
,
948 "init_etherarray: strdup(name)");
952 tp
->e_name
= el
->name
;
956 static const struct tok ipxsap_db
[] = {
957 { 0x0000, "Unknown" },
959 { 0x0002, "User Group" },
960 { 0x0003, "PrintQueue" },
961 { 0x0004, "FileServer" },
962 { 0x0005, "JobServer" },
963 { 0x0006, "Gateway" },
964 { 0x0007, "PrintServer" },
965 { 0x0008, "ArchiveQueue" },
966 { 0x0009, "ArchiveServer" },
967 { 0x000a, "JobQueue" },
968 { 0x000b, "Administration" },
969 { 0x000F, "Novell TI-RPC" },
970 { 0x0017, "Diagnostics" },
971 { 0x0020, "NetBIOS" },
972 { 0x0021, "NAS SNA Gateway" },
973 { 0x0023, "NACS AsyncGateway" },
974 { 0x0024, "RemoteBridge/RoutingService" },
975 { 0x0026, "BridgeServer" },
976 { 0x0027, "TCP/IP Gateway" },
977 { 0x0028, "Point-to-point X.25 BridgeServer" },
978 { 0x0029, "3270 Gateway" },
979 { 0x002a, "CHI Corp" },
980 { 0x002c, "PC Chalkboard" },
981 { 0x002d, "TimeSynchServer" },
982 { 0x002e, "ARCserve5.0/PalindromeBackup" },
983 { 0x0045, "DI3270 Gateway" },
984 { 0x0047, "AdvertisingPrintServer" },
985 { 0x004a, "NetBlazerModems" },
986 { 0x004b, "BtrieveVAP" },
987 { 0x004c, "NetwareSQL" },
988 { 0x004d, "XtreeNetwork" },
989 { 0x0050, "BtrieveVAP4.11" },
990 { 0x0052, "QuickLink" },
991 { 0x0053, "PrintQueueUser" },
992 { 0x0058, "Multipoint X.25 Router" },
993 { 0x0060, "STLB/NLM" },
994 { 0x0064, "ARCserve" },
995 { 0x0066, "ARCserve3.0" },
996 { 0x0072, "WAN CopyUtility" },
997 { 0x007a, "TES-NetwareVMS" },
998 { 0x0092, "WATCOM Debugger/EmeraldTapeBackupServer" },
999 { 0x0095, "DDA OBGYN" },
1000 { 0x0098, "NetwareAccessServer" },
1001 { 0x009a, "Netware for VMS II/NamedPipeServer" },
1002 { 0x009b, "NetwareAccessServer" },
1003 { 0x009e, "PortableNetwareServer/SunLinkNVT" },
1004 { 0x00a1, "PowerchuteAPC UPS" },
1005 { 0x00aa, "LAWserve" },
1006 { 0x00ac, "CompaqIDA StatusMonitor" },
1007 { 0x0100, "PIPE STAIL" },
1008 { 0x0102, "LAN ProtectBindery" },
1009 { 0x0103, "OracleDataBaseServer" },
1010 { 0x0107, "Netware386/RSPX RemoteConsole" },
1011 { 0x010f, "NovellSNA Gateway" },
1012 { 0x0111, "TestServer" },
1013 { 0x0112, "HP PrintServer" },
1014 { 0x0114, "CSA MUX" },
1015 { 0x0115, "CSA LCA" },
1016 { 0x0116, "CSA CM" },
1017 { 0x0117, "CSA SMA" },
1018 { 0x0118, "CSA DBA" },
1019 { 0x0119, "CSA NMA" },
1020 { 0x011a, "CSA SSA" },
1021 { 0x011b, "CSA STATUS" },
1022 { 0x011e, "CSA APPC" },
1023 { 0x0126, "SNA TEST SSA Profile" },
1024 { 0x012a, "CSA TRACE" },
1025 { 0x012b, "NetwareSAA" },
1026 { 0x012e, "IKARUS VirusScan" },
1027 { 0x0130, "CommunicationsExecutive" },
1028 { 0x0133, "NNS DomainServer/NetwareNamingServicesDomain" },
1029 { 0x0135, "NetwareNamingServicesProfile" },
1030 { 0x0137, "Netware386 PrintQueue/NNS PrintQueue" },
1031 { 0x0141, "LAN SpoolServer" },
1032 { 0x0152, "IRMALAN Gateway" },
1033 { 0x0154, "NamedPipeServer" },
1034 { 0x0166, "NetWareManagement" },
1035 { 0x0168, "Intel PICKIT CommServer/Intel CAS TalkServer" },
1036 { 0x0173, "Compaq" },
1037 { 0x0174, "Compaq SNMP Agent" },
1038 { 0x0175, "Compaq" },
1039 { 0x0180, "XTreeServer/XTreeTools" },
1040 { 0x018A, "NASI ServicesBroadcastServer" },
1041 { 0x01b0, "GARP Gateway" },
1042 { 0x01b1, "Binfview" },
1043 { 0x01bf, "IntelLanDeskManager" },
1044 { 0x01ca, "AXTEC" },
1045 { 0x01cb, "ShivaNetModem/E" },
1046 { 0x01cc, "ShivaLanRover/E" },
1047 { 0x01cd, "ShivaLanRover/T" },
1048 { 0x01ce, "ShivaUniversal" },
1049 { 0x01d8, "CastelleFAXPressServer" },
1050 { 0x01da, "CastelleLANPressPrintServer" },
1051 { 0x01dc, "CastelleFAX/Xerox7033 FaxServer/ExcelLanFax" },
1052 { 0x01f0, "LEGATO" },
1053 { 0x01f5, "LEGATO" },
1054 { 0x0233, "NMS Agent/NetwareManagementAgent" },
1055 { 0x0237, "NMS IPX Discovery/LANternReadWriteChannel" },
1056 { 0x0238, "NMS IP Discovery/LANternTrapAlarmChannel" },
1057 { 0x023a, "LANtern" },
1058 { 0x023c, "MAVERICK" },
1059 { 0x023f, "NovellSMDR" },
1060 { 0x024e, "NetwareConnect" },
1061 { 0x024f, "NASI ServerBroadcast Cisco" },
1062 { 0x026a, "NMS ServiceConsole" },
1063 { 0x026b, "TimeSynchronizationServer Netware 4.x" },
1064 { 0x0278, "DirectoryServer Netware 4.x" },
1065 { 0x027b, "NetwareManagementAgent" },
1066 { 0x0280, "Novell File and Printer Sharing Service for PC" },
1067 { 0x0304, "NovellSAA Gateway" },
1068 { 0x0308, "COM/VERMED" },
1069 { 0x030a, "GalacticommWorldgroupServer" },
1070 { 0x030c, "IntelNetport2/HP JetDirect/HP Quicksilver" },
1071 { 0x0320, "AttachmateGateway" },
1072 { 0x0327, "MicrosoftDiagnostiocs" },
1073 { 0x0328, "WATCOM SQL Server" },
1074 { 0x0335, "MultiTechSystems MultisynchCommServer" },
1075 { 0x0343, "Xylogics RemoteAccessServer/LANModem" },
1076 { 0x0355, "ArcadaBackupExec" },
1077 { 0x0358, "MSLCD1" },
1078 { 0x0361, "NETINELO" },
1079 { 0x037e, "Powerchute UPS Monitoring" },
1080 { 0x037f, "ViruSafeNotify" },
1081 { 0x0386, "HP Bridge" },
1082 { 0x0387, "HP Hub" },
1083 { 0x0394, "NetWare SAA Gateway" },
1084 { 0x039b, "LotusNotes" },
1085 { 0x03b7, "CertusAntiVirus" },
1086 { 0x03c4, "ARCserve4.0" },
1087 { 0x03c7, "LANspool3.5" },
1088 { 0x03d7, "LexmarkPrinterServer" },
1089 { 0x03d8, "LexmarkXLE PrinterServer" },
1090 { 0x03dd, "BanyanENS NetwareClient" },
1091 { 0x03de, "GuptaSequelBaseServer/NetWareSQL" },
1092 { 0x03e1, "UnivelUnixware" },
1093 { 0x03e4, "UnivelUnixware" },
1094 { 0x03fc, "IntelNetport" },
1095 { 0x03fd, "PrintServerQueue" },
1096 { 0x040A, "ipnServer" },
1097 { 0x040D, "LVERRMAN" },
1098 { 0x040E, "LVLIC" },
1099 { 0x0414, "NET Silicon (DPI)/Kyocera" },
1100 { 0x0429, "SiteLockVirus" },
1101 { 0x0432, "UFHELPR???" },
1102 { 0x0433, "Synoptics281xAdvancedSNMPAgent" },
1103 { 0x0444, "MicrosoftNT SNA Server" },
1104 { 0x0448, "Oracle" },
1105 { 0x044c, "ARCserve5.01" },
1106 { 0x0457, "CanonGP55" },
1107 { 0x045a, "QMS Printers" },
1108 { 0x045b, "DellSCSI Array" },
1109 { 0x0491, "NetBlazerModems" },
1110 { 0x04ac, "OnTimeScheduler" },
1111 { 0x04b0, "CD-Net" },
1112 { 0x0513, "EmulexNQA" },
1113 { 0x0520, "SiteLockChecks" },
1114 { 0x0529, "SiteLockChecks" },
1115 { 0x052d, "CitrixOS2 AppServer" },
1116 { 0x0535, "Tektronix" },
1117 { 0x0536, "Milan" },
1118 { 0x055d, "Attachmate SNA gateway" },
1119 { 0x056b, "IBM8235 ModemServer" },
1120 { 0x056c, "ShivaLanRover/E PLUS" },
1121 { 0x056d, "ShivaLanRover/T PLUS" },
1122 { 0x0580, "McAfeeNetShield" },
1123 { 0x05B8, "NLM to workstation communication (Revelation Software)" },
1124 { 0x05BA, "CompatibleSystemsRouters" },
1125 { 0x05BE, "CheyenneHierarchicalStorageManager" },
1126 { 0x0606, "JCWatermarkImaging" },
1127 { 0x060c, "AXISNetworkPrinter" },
1128 { 0x0610, "AdaptecSCSIManagement" },
1129 { 0x0621, "IBM AntiVirus" },
1130 { 0x0640, "Windows95 RemoteRegistryService" },
1131 { 0x064e, "MicrosoftIIS" },
1132 { 0x067b, "Microsoft Win95/98 File and Print Sharing for NetWare" },
1133 { 0x067c, "Microsoft Win95/98 File and Print Sharing for NetWare" },
1134 { 0x076C, "Xerox" },
1135 { 0x079b, "ShivaLanRover/E 115" },
1136 { 0x079c, "ShivaLanRover/T 115" },
1137 { 0x07B4, "CubixWorldDesk" },
1138 { 0x07c2, "Quarterdeck IWare Connect V2.x NLM" },
1139 { 0x07c1, "Quarterdeck IWare Connect V3.x NLM" },
1140 { 0x0810, "ELAN License Server Demo" },
1141 { 0x0824, "ShivaLanRoverAccessSwitch/E" },
1142 { 0x086a, "ISSC Collector" },
1143 { 0x087f, "ISSC DAS AgentAIX" },
1144 { 0x0880, "Intel Netport PRO" },
1145 { 0x0881, "Intel Netport PRO" },
1146 { 0x0b29, "SiteLock" },
1147 { 0x0c29, "SiteLockApplications" },
1148 { 0x0c2c, "LicensingServer" },
1149 { 0x2101, "PerformanceTechnologyInstantInternet" },
1150 { 0x2380, "LAI SiteLock" },
1151 { 0x238c, "MeetingMaker" },
1152 { 0x4808, "SiteLockServer/SiteLockMetering" },
1153 { 0x5555, "SiteLockUser" },
1154 { 0x6312, "Tapeware" },
1155 { 0x6f00, "RabbitGateway" },
1156 { 0x7703, "MODEM" },
1157 { 0x8002, "NetPortPrinters" },
1158 { 0x8008, "WordPerfectNetworkVersion" },
1159 { 0x85BE, "Cisco EIGRP" },
1160 { 0x8888, "WordPerfectNetworkVersion/QuickNetworkManagement" },
1161 { 0x9000, "McAfeeNetShield" },
1162 { 0x9604, "CSA-NT_MON" },
1163 { 0xb6a8, "OceanIsleReachoutRemoteControl" },
1164 { 0xf11f, "SiteLockMetering" },
1165 { 0xf1ff, "SiteLock" },
1166 { 0xf503, "Microsoft SQL Server" },
1167 { 0xF905, "IBM TimeAndPlace" },
1168 { 0xfbfb, "TopCallIII FaxServer" },
1169 { 0xffff, "AnyService/Wildcard" },
1174 init_ipxsaparray(netdissect_options
*ndo
)
1177 struct hnamemem
*table
;
1179 for (i
= 0; ipxsap_db
[i
].s
!= NULL
; i
++) {
1180 int j
= htons(ipxsap_db
[i
].v
) & (HASHNAMESIZE
-1);
1181 table
= &ipxsaptable
[j
];
1184 table
->name
= ipxsap_db
[i
].s
;
1185 table
->addr
= htons(ipxsap_db
[i
].v
);
1186 table
->nxt
= newhnamemem(ndo
);
1191 * Initialize the address to name translation machinery. We map all
1192 * non-local IP addresses to numeric addresses if ndo->ndo_fflag is true
1193 * (i.e., to prevent blocking on the nameserver). localnet is the IP address
1194 * of the local network. mask is its subnet mask.
1197 init_addrtoname(netdissect_options
*ndo
, uint32_t localnet
, uint32_t mask
)
1199 if (ndo
->ndo_fflag
) {
1200 f_localnet
= localnet
;
1205 * Simplest way to suppress names.
1209 init_etherarray(ndo
);
1210 init_servarray(ndo
);
1211 init_eprotoarray(ndo
);
1212 init_protoidarray(ndo
);
1213 init_ipxsaparray(ndo
);
1217 dnaddr_string(netdissect_options
*ndo
, u_short dnaddr
)
1219 struct hnamemem
*tp
;
1221 for (tp
= &dnaddrtable
[dnaddr
& (HASHNAMESIZE
-1)]; tp
->nxt
!= NULL
;
1223 if (tp
->addr
== dnaddr
)
1227 tp
->nxt
= newhnamemem(ndo
);
1229 tp
->name
= dnnum_string(ndo
, dnaddr
);
1231 tp
->name
= dnname_string(ndo
, dnaddr
);
1236 /* Return a zero'ed hnamemem struct and cuts down on calloc() overhead */
1238 newhnamemem(netdissect_options
*ndo
)
1241 static struct hnamemem
*ptr
= NULL
;
1242 static u_int num
= 0;
1246 ptr
= (struct hnamemem
*)calloc(num
, sizeof (*ptr
));
1248 (*ndo
->ndo_error
)(ndo
, "newhnamemem: calloc");
1255 /* Return a zero'ed h6namemem struct and cuts down on calloc() overhead */
1257 newh6namemem(netdissect_options
*ndo
)
1259 struct h6namemem
*p
;
1260 static struct h6namemem
*ptr
= NULL
;
1261 static u_int num
= 0;
1265 ptr
= (struct h6namemem
*)calloc(num
, sizeof (*ptr
));
1267 (*ndo
->ndo_error
)(ndo
, "newh6namemem: calloc");
1274 /* Represent TCI part of the 802.1Q 4-octet tag as text. */
1276 ieee8021q_tci_string(const uint16_t tci
)
1278 static char buf
[128];
1279 snprintf(buf
, sizeof(buf
), "vlan %u, p %u%s",
1282 (tci
& 0x1000) ? ", DEI" : "");