xref: /freebsd/contrib/tcpdump/addrtoname.c (revision ee67461e56828dd1f8de165947ba83f6d9148a87)
14edb46e9SPaul Traina /*
2699fc314SBill Fenner  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
34edb46e9SPaul Traina  *	The Regents of the University of California.  All rights reserved.
44edb46e9SPaul Traina  *
54edb46e9SPaul Traina  * Redistribution and use in source and binary forms, with or without
64edb46e9SPaul Traina  * modification, are permitted provided that: (1) source code distributions
74edb46e9SPaul Traina  * retain the above copyright notice and this paragraph in its entirety, (2)
84edb46e9SPaul Traina  * distributions including binary code include the above copyright notice and
94edb46e9SPaul Traina  * this paragraph in its entirety in the documentation or other materials
104edb46e9SPaul Traina  * provided with the distribution, and (3) all advertising materials mentioning
114edb46e9SPaul Traina  * features or use of this software display the following acknowledgement:
124edb46e9SPaul Traina  * ``This product includes software developed by the University of California,
134edb46e9SPaul Traina  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
144edb46e9SPaul Traina  * the University nor the names of its contributors may be used to endorse
154edb46e9SPaul Traina  * or promote products derived from this software without specific prior
164edb46e9SPaul Traina  * written permission.
174edb46e9SPaul Traina  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
184edb46e9SPaul Traina  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
194edb46e9SPaul Traina  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
204edb46e9SPaul Traina  *
214edb46e9SPaul Traina  *  Internet, ethernet, port, and protocol string to address
224edb46e9SPaul Traina  *  and address to string conversion routines
234edb46e9SPaul Traina  */
24a88113a8SBill Fenner 
25a88113a8SBill Fenner #ifdef HAVE_CONFIG_H
26*ee67461eSJoseph Mingrone #include <config.h>
274edb46e9SPaul Traina #endif
284edb46e9SPaul Traina 
29b01988a5SMariusz Zaborski #ifdef HAVE_CASPER
30c501d73cSMariusz Zaborski #include <libcasper.h>
31c501d73cSMariusz Zaborski #include <casper/cap_dns.h>
32b01988a5SMariusz Zaborski #endif /* HAVE_CASPER */
333340d773SGleb Smirnoff 
34*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
350e0def19SBill Fenner 
360e0def19SBill Fenner #ifdef USE_ETHER_NTOHOST
37*ee67461eSJoseph Mingrone   #if defined(NET_ETHERNET_H_DECLARES_ETHER_NTOHOST)
38*ee67461eSJoseph Mingrone     /*
39*ee67461eSJoseph Mingrone      * OK, just include <net/ethernet.h>.
40*ee67461eSJoseph Mingrone      */
41*ee67461eSJoseph Mingrone     #include <net/ethernet.h>
42*ee67461eSJoseph Mingrone   #elif defined(NETINET_ETHER_H_DECLARES_ETHER_NTOHOST)
43*ee67461eSJoseph Mingrone     /*
44*ee67461eSJoseph Mingrone      * OK, just include <netinet/ether.h>
45*ee67461eSJoseph Mingrone      */
46c1ad1296SSam Leffler     #include <netinet/ether.h>
47*ee67461eSJoseph Mingrone   #elif defined(SYS_ETHERNET_H_DECLARES_ETHER_NTOHOST)
48*ee67461eSJoseph Mingrone     /*
49*ee67461eSJoseph Mingrone      * OK, just include <sys/ethernet.h>
50*ee67461eSJoseph Mingrone      */
51*ee67461eSJoseph Mingrone     #include <sys/ethernet.h>
52*ee67461eSJoseph Mingrone   #elif defined(ARPA_INET_H_DECLARES_ETHER_NTOHOST)
53*ee67461eSJoseph Mingrone     /*
54*ee67461eSJoseph Mingrone      * OK, just include <arpa/inet.h>
55*ee67461eSJoseph Mingrone      */
56*ee67461eSJoseph Mingrone     #include <arpa/inet.h>
57*ee67461eSJoseph Mingrone   #elif defined(NETINET_IF_ETHER_H_DECLARES_ETHER_NTOHOST)
58*ee67461eSJoseph Mingrone     /*
59*ee67461eSJoseph Mingrone      * OK, include <netinet/if_ether.h>, after all the other stuff we
60*ee67461eSJoseph Mingrone      * need to include or define for its benefit.
61*ee67461eSJoseph Mingrone      */
62*ee67461eSJoseph Mingrone     #define NEED_NETINET_IF_ETHER_H
63*ee67461eSJoseph Mingrone   #else
64*ee67461eSJoseph Mingrone     /*
65*ee67461eSJoseph Mingrone      * We'll have to declare it ourselves.
66*ee67461eSJoseph Mingrone      * If <netinet/if_ether.h> defines struct ether_addr, include
67*ee67461eSJoseph Mingrone      * it.  Otherwise, define it ourselves.
68*ee67461eSJoseph Mingrone      */
69*ee67461eSJoseph Mingrone     #ifdef HAVE_STRUCT_ETHER_ADDR
70*ee67461eSJoseph Mingrone       #define NEED_NETINET_IF_ETHER_H
71*ee67461eSJoseph Mingrone     #else /* HAVE_STRUCT_ETHER_ADDR */
7229292c17SSam Leffler 	struct ether_addr {
73*ee67461eSJoseph Mingrone 		/* Beware FreeBSD calls this "octet". */
74*ee67461eSJoseph Mingrone 		unsigned char ether_addr_octet[MAC_ADDR_LEN];
7529292c17SSam Leffler 	};
76*ee67461eSJoseph Mingrone     #endif /* HAVE_STRUCT_ETHER_ADDR */
77*ee67461eSJoseph Mingrone   #endif /* what declares ether_ntohost() */
78c1ad1296SSam Leffler 
79*ee67461eSJoseph Mingrone   #ifdef NEED_NETINET_IF_ETHER_H
80*ee67461eSJoseph Mingrone     /*
81*ee67461eSJoseph Mingrone      * Include diag-control.h before <net/if.h>, which too defines a macro
82*ee67461eSJoseph Mingrone      * named ND_UNREACHABLE.
83*ee67461eSJoseph Mingrone      */
84*ee67461eSJoseph Mingrone     #include "diag-control.h"
85*ee67461eSJoseph Mingrone     #include <net/if.h>		/* Needed on some platforms */
86*ee67461eSJoseph Mingrone     #include <netinet/in.h>	/* Needed on some platforms */
87*ee67461eSJoseph Mingrone     #include <netinet/if_ether.h>
88*ee67461eSJoseph Mingrone   #endif /* NEED_NETINET_IF_ETHER_H */
89*ee67461eSJoseph Mingrone 
90*ee67461eSJoseph Mingrone   #ifndef HAVE_DECL_ETHER_NTOHOST
91*ee67461eSJoseph Mingrone     /*
92*ee67461eSJoseph Mingrone      * No header declares it, so declare it ourselves.
93*ee67461eSJoseph Mingrone      */
94*ee67461eSJoseph Mingrone     extern int ether_ntohost(char *, const struct ether_addr *);
95*ee67461eSJoseph Mingrone   #endif /* !defined(HAVE_DECL_ETHER_NTOHOST) */
9629292c17SSam Leffler #endif /* USE_ETHER_NTOHOST */
9729292c17SSam Leffler 
984edb46e9SPaul Traina #include <pcap.h>
994edb46e9SPaul Traina #include <pcap-namedb.h>
100*ee67461eSJoseph Mingrone #ifndef HAVE_GETSERVENT
101*ee67461eSJoseph Mingrone #include <getservent.h>
102*ee67461eSJoseph Mingrone #endif
1034edb46e9SPaul Traina #include <signal.h>
1044edb46e9SPaul Traina #include <stdio.h>
1054edb46e9SPaul Traina #include <string.h>
1064edb46e9SPaul Traina #include <stdlib.h>
1074edb46e9SPaul Traina 
1083340d773SGleb Smirnoff #include "netdissect.h"
1094edb46e9SPaul Traina #include "addrtoname.h"
1103340d773SGleb Smirnoff #include "addrtostr.h"
1113340d773SGleb Smirnoff #include "ethertype.h"
1124edb46e9SPaul Traina #include "llc.h"
11329292c17SSam Leffler #include "extract.h"
11429292c17SSam Leffler #include "oui.h"
1154edb46e9SPaul Traina 
1164edb46e9SPaul Traina /*
1174edb46e9SPaul Traina  * hash tables for whatever-to-name translations
118cc391cceSBruce M Simpson  *
119*ee67461eSJoseph Mingrone  * ndo_error() called on strdup(3) failure with S_ERR_ND_MEM_ALLOC status
1204edb46e9SPaul Traina  */
1214edb46e9SPaul Traina 
1224edb46e9SPaul Traina #define HASHNAMESIZE 4096
1234edb46e9SPaul Traina 
1244edb46e9SPaul Traina struct hnamemem {
1253c602fabSXin LI 	uint32_t addr;
126a1c2090eSBill Fenner 	const char *name;
1274edb46e9SPaul Traina 	struct hnamemem *nxt;
1284edb46e9SPaul Traina };
1294edb46e9SPaul Traina 
13027df3f5dSRui Paulo static struct hnamemem hnametable[HASHNAMESIZE];
13127df3f5dSRui Paulo static struct hnamemem tporttable[HASHNAMESIZE];
13227df3f5dSRui Paulo static struct hnamemem uporttable[HASHNAMESIZE];
13327df3f5dSRui Paulo static struct hnamemem eprototable[HASHNAMESIZE];
13427df3f5dSRui Paulo static struct hnamemem dnaddrtable[HASHNAMESIZE];
13527df3f5dSRui Paulo static struct hnamemem ipxsaptable[HASHNAMESIZE];
136cc391cceSBruce M Simpson 
1373340d773SGleb Smirnoff #ifdef _WIN32
138cc391cceSBruce M Simpson /*
139cc391cceSBruce M Simpson  * fake gethostbyaddr for Win2k/XP
140cc391cceSBruce M Simpson  * gethostbyaddr() returns incorrect value when AF_INET6 is passed
141cc391cceSBruce M Simpson  * to 3rd argument.
142cc391cceSBruce M Simpson  *
143cc391cceSBruce M Simpson  * h_name in struct hostent is only valid.
144cc391cceSBruce M Simpson  */
145cc391cceSBruce M Simpson static struct hostent *
146cc391cceSBruce M Simpson win32_gethostbyaddr(const char *addr, int len, int type)
147cc391cceSBruce M Simpson {
148cc391cceSBruce M Simpson 	static struct hostent host;
149cc391cceSBruce M Simpson 	static char hostbuf[NI_MAXHOST];
150cc391cceSBruce M Simpson 	char hname[NI_MAXHOST];
151cc391cceSBruce M Simpson 	struct sockaddr_in6 addr6;
152cc391cceSBruce M Simpson 
153cc391cceSBruce M Simpson 	host.h_name = hostbuf;
154cc391cceSBruce M Simpson 	switch (type) {
155cc391cceSBruce M Simpson 	case AF_INET:
156cc391cceSBruce M Simpson 		return gethostbyaddr(addr, len, type);
157cc391cceSBruce M Simpson 		break;
158cc391cceSBruce M Simpson 	case AF_INET6:
159cc391cceSBruce M Simpson 		memset(&addr6, 0, sizeof(addr6));
160cc391cceSBruce M Simpson 		addr6.sin6_family = AF_INET6;
161cc391cceSBruce M Simpson 		memcpy(&addr6.sin6_addr, addr, len);
162cc391cceSBruce M Simpson 		if (getnameinfo((struct sockaddr *)&addr6, sizeof(addr6),
163cc391cceSBruce M Simpson 		    hname, sizeof(hname), NULL, 0, 0)) {
164cc391cceSBruce M Simpson 			return NULL;
165cc391cceSBruce M Simpson 		} else {
16639e421e8SCy Schubert 			strlcpy(host.h_name, hname, NI_MAXHOST);
167cc391cceSBruce M Simpson 			return &host;
168cc391cceSBruce M Simpson 		}
169cc391cceSBruce M Simpson 		break;
170cc391cceSBruce M Simpson 	default:
171cc391cceSBruce M Simpson 		return NULL;
172cc391cceSBruce M Simpson 	}
173cc391cceSBruce M Simpson }
174cc391cceSBruce M Simpson #define gethostbyaddr win32_gethostbyaddr
1753340d773SGleb Smirnoff #endif /* _WIN32 */
1764edb46e9SPaul Traina 
177a88113a8SBill Fenner struct h6namemem {
178*ee67461eSJoseph Mingrone 	nd_ipv6 addr;
179a88113a8SBill Fenner 	char *name;
180a88113a8SBill Fenner 	struct h6namemem *nxt;
181a88113a8SBill Fenner };
182a88113a8SBill Fenner 
18327df3f5dSRui Paulo static struct h6namemem h6nametable[HASHNAMESIZE];
184a88113a8SBill Fenner 
1854edb46e9SPaul Traina struct enamemem {
1864edb46e9SPaul Traina 	u_short e_addr0;
1874edb46e9SPaul Traina 	u_short e_addr1;
1884edb46e9SPaul Traina 	u_short e_addr2;
189a1c2090eSBill Fenner 	const char *e_name;
1904edb46e9SPaul Traina 	u_char *e_nsap;			/* used only for nsaptable[] */
1914edb46e9SPaul Traina 	struct enamemem *e_nxt;
1924edb46e9SPaul Traina };
1934edb46e9SPaul Traina 
19427df3f5dSRui Paulo static struct enamemem enametable[HASHNAMESIZE];
19527df3f5dSRui Paulo static struct enamemem nsaptable[HASHNAMESIZE];
1960bff6a5aSEd Maste 
1970bff6a5aSEd Maste struct bsnamemem {
1980bff6a5aSEd Maste 	u_short bs_addr0;
1990bff6a5aSEd Maste 	u_short bs_addr1;
2000bff6a5aSEd Maste 	u_short bs_addr2;
2010bff6a5aSEd Maste 	const char *bs_name;
2020bff6a5aSEd Maste 	u_char *bs_bytes;
2030bff6a5aSEd Maste 	unsigned int bs_nbytes;
2040bff6a5aSEd Maste 	struct bsnamemem *bs_nxt;
2050bff6a5aSEd Maste };
2060bff6a5aSEd Maste 
2070bff6a5aSEd Maste static struct bsnamemem bytestringtable[HASHNAMESIZE];
2084edb46e9SPaul Traina 
2094edb46e9SPaul Traina struct protoidmem {
2103c602fabSXin LI 	uint32_t p_oui;
2114edb46e9SPaul Traina 	u_short p_proto;
212a1c2090eSBill Fenner 	const char *p_name;
2134edb46e9SPaul Traina 	struct protoidmem *p_nxt;
2144edb46e9SPaul Traina };
2154edb46e9SPaul Traina 
21627df3f5dSRui Paulo static struct protoidmem protoidtable[HASHNAMESIZE];
2174edb46e9SPaul Traina 
2184edb46e9SPaul Traina /*
2194edb46e9SPaul Traina  * A faster replacement for inet_ntoa().
2204edb46e9SPaul Traina  */
221a1c2090eSBill Fenner const char *
2223c602fabSXin LI intoa(uint32_t addr)
2234edb46e9SPaul Traina {
224*ee67461eSJoseph Mingrone 	char *cp;
225*ee67461eSJoseph Mingrone 	u_int byte;
226*ee67461eSJoseph Mingrone 	int n;
2274edb46e9SPaul Traina 	static char buf[sizeof(".xxx.xxx.xxx.xxx")];
2284edb46e9SPaul Traina 
229*ee67461eSJoseph Mingrone 	addr = ntohl(addr);
23029292c17SSam Leffler 	cp = buf + sizeof(buf);
2314edb46e9SPaul Traina 	*--cp = '\0';
2324edb46e9SPaul Traina 
2334edb46e9SPaul Traina 	n = 4;
2344edb46e9SPaul Traina 	do {
2354edb46e9SPaul Traina 		byte = addr & 0xff;
236*ee67461eSJoseph Mingrone 		*--cp = (char)(byte % 10) + '0';
2374edb46e9SPaul Traina 		byte /= 10;
2384edb46e9SPaul Traina 		if (byte > 0) {
239*ee67461eSJoseph Mingrone 			*--cp = (char)(byte % 10) + '0';
2404edb46e9SPaul Traina 			byte /= 10;
2414edb46e9SPaul Traina 			if (byte > 0)
242*ee67461eSJoseph Mingrone 				*--cp = (char)byte + '0';
2434edb46e9SPaul Traina 		}
2444edb46e9SPaul Traina 		*--cp = '.';
2454edb46e9SPaul Traina 		addr >>= 8;
2464edb46e9SPaul Traina 	} while (--n > 0);
2474edb46e9SPaul Traina 
2484edb46e9SPaul Traina 	return cp + 1;
2494edb46e9SPaul Traina }
2504edb46e9SPaul Traina 
2513c602fabSXin LI static uint32_t f_netmask;
2523c602fabSXin LI static uint32_t f_localnet;
253b01988a5SMariusz Zaborski #ifdef HAVE_CASPER
254*ee67461eSJoseph Mingrone cap_channel_t *capdns;
255197731f6SPawel Jakub Dawidek #endif
2564edb46e9SPaul Traina 
2574edb46e9SPaul Traina /*
2584edb46e9SPaul Traina  * Return a name for the IP address pointed to by ap.  This address
2594edb46e9SPaul Traina  * is assumed to be in network byte order.
260cc391cceSBruce M Simpson  *
261*ee67461eSJoseph Mingrone  * NOTE: ap is *NOT* necessarily part of the packet data, so you
262*ee67461eSJoseph Mingrone  * *CANNOT* use the ND_TCHECK_* or ND_TTEST_* macros on it.  Furthermore,
263cc391cceSBruce M Simpson  * even in cases where it *is* part of the packet data, the caller
264cc391cceSBruce M Simpson  * would still have to check for a null return value, even if it's
265cc391cceSBruce M Simpson  * just printing the return value with "%s" - not all versions of
266cc391cceSBruce M Simpson  * printf print "(null)" with "%s" and a null pointer, some of them
267cc391cceSBruce M Simpson  * don't check for a null pointer and crash in that case.
268cc391cceSBruce M Simpson  *
269cc391cceSBruce M Simpson  * The callers of this routine should, before handing this routine
270cc391cceSBruce M Simpson  * a pointer to packet data, be sure that the data is present in
271cc391cceSBruce M Simpson  * the packet buffer.  They should probably do those checks anyway,
272cc391cceSBruce M Simpson  * as other data at that layer might not be IP addresses, and it
273cc391cceSBruce M Simpson  * also needs to check whether they're present in the packet buffer.
2744edb46e9SPaul Traina  */
275a1c2090eSBill Fenner const char *
276*ee67461eSJoseph Mingrone ipaddr_string(netdissect_options *ndo, const u_char *ap)
2774edb46e9SPaul Traina {
278*ee67461eSJoseph Mingrone 	struct hostent *hp;
2793c602fabSXin LI 	uint32_t addr;
2803340d773SGleb Smirnoff 	struct hnamemem *p;
2814edb46e9SPaul Traina 
282a88113a8SBill Fenner 	memcpy(&addr, ap, sizeof(addr));
2834edb46e9SPaul Traina 	p = &hnametable[addr & (HASHNAMESIZE-1)];
2844edb46e9SPaul Traina 	for (; p->nxt; p = p->nxt) {
2854edb46e9SPaul Traina 		if (p->addr == addr)
2864edb46e9SPaul Traina 			return (p->name);
2874edb46e9SPaul Traina 	}
2884edb46e9SPaul Traina 	p->addr = addr;
2893340d773SGleb Smirnoff 	p->nxt = newhnamemem(ndo);
2904edb46e9SPaul Traina 
2914edb46e9SPaul Traina 	/*
292cc391cceSBruce M Simpson 	 * Print names unless:
293cc391cceSBruce M Simpson 	 *	(1) -n was given.
294699fc314SBill Fenner 	 *      (2) Address is foreign and -f was given. (If -f was not
295cc391cceSBruce M Simpson 	 *	    given, f_netmask and f_localnet are 0 and the test
296699fc314SBill Fenner 	 *	    evaluates to true)
2974edb46e9SPaul Traina 	 */
2983c602fabSXin LI 	if (!ndo->ndo_nflag &&
299cc391cceSBruce M Simpson 	    (addr & f_netmask) == f_localnet) {
300b01988a5SMariusz Zaborski #ifdef HAVE_CASPER
301197731f6SPawel Jakub Dawidek 		if (capdns != NULL) {
302197731f6SPawel Jakub Dawidek 			hp = cap_gethostbyaddr(capdns, (char *)&addr, 4,
303197731f6SPawel Jakub Dawidek 			    AF_INET);
304197731f6SPawel Jakub Dawidek 		} else
305197731f6SPawel Jakub Dawidek #endif
3064edb46e9SPaul Traina 			hp = gethostbyaddr((char *)&addr, 4, AF_INET);
3074edb46e9SPaul Traina 		if (hp) {
3084edb46e9SPaul Traina 			char *dotp;
3094edb46e9SPaul Traina 
310a1c2090eSBill Fenner 			p->name = strdup(hp->h_name);
3113340d773SGleb Smirnoff 			if (p->name == NULL)
312*ee67461eSJoseph Mingrone 				(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
313*ee67461eSJoseph Mingrone 					"%s: strdup(hp->h_name)", __func__);
3143c602fabSXin LI 			if (ndo->ndo_Nflag) {
3154edb46e9SPaul Traina 				/* Remove domain qualifications */
3164edb46e9SPaul Traina 				dotp = strchr(p->name, '.');
3174edb46e9SPaul Traina 				if (dotp)
3184edb46e9SPaul Traina 					*dotp = '\0';
3194edb46e9SPaul Traina 			}
3204edb46e9SPaul Traina 			return (p->name);
3214edb46e9SPaul Traina 		}
3224edb46e9SPaul Traina 	}
323a1c2090eSBill Fenner 	p->name = strdup(intoa(addr));
3243340d773SGleb Smirnoff 	if (p->name == NULL)
325*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
326*ee67461eSJoseph Mingrone 				  "%s: strdup(intoa(addr))", __func__);
3274edb46e9SPaul Traina 	return (p->name);
3284edb46e9SPaul Traina }
3294edb46e9SPaul Traina 
330a88113a8SBill Fenner /*
331a88113a8SBill Fenner  * Return a name for the IP6 address pointed to by ap.  This address
332a88113a8SBill Fenner  * is assumed to be in network byte order.
333a88113a8SBill Fenner  */
334a1c2090eSBill Fenner const char *
335*ee67461eSJoseph Mingrone ip6addr_string(netdissect_options *ndo, const u_char *ap)
336a88113a8SBill Fenner {
337*ee67461eSJoseph Mingrone 	struct hostent *hp;
3383c602fabSXin LI 	union {
339*ee67461eSJoseph Mingrone 		nd_ipv6 addr;
3403c602fabSXin LI 		struct for_hash_addr {
3413c602fabSXin LI 			char fill[14];
3423c602fabSXin LI 			uint16_t d;
3433c602fabSXin LI 		} addra;
3443c602fabSXin LI 	} addr;
3453340d773SGleb Smirnoff 	struct h6namemem *p;
346*ee67461eSJoseph Mingrone 	const char *cp;
347a88113a8SBill Fenner 	char ntop_buf[INET6_ADDRSTRLEN];
348a88113a8SBill Fenner 
349a88113a8SBill Fenner 	memcpy(&addr, ap, sizeof(addr));
3503c602fabSXin LI 	p = &h6nametable[addr.addra.d & (HASHNAMESIZE-1)];
351a88113a8SBill Fenner 	for (; p->nxt; p = p->nxt) {
352a88113a8SBill Fenner 		if (memcmp(&p->addr, &addr, sizeof(addr)) == 0)
353a88113a8SBill Fenner 			return (p->name);
354a88113a8SBill Fenner 	}
355*ee67461eSJoseph Mingrone 	memcpy(p->addr, addr.addr, sizeof(nd_ipv6));
3563340d773SGleb Smirnoff 	p->nxt = newh6namemem(ndo);
357a88113a8SBill Fenner 
358a88113a8SBill Fenner 	/*
359cc391cceSBruce M Simpson 	 * Do not print names if -n was given.
360a88113a8SBill Fenner 	 */
3613c602fabSXin LI 	if (!ndo->ndo_nflag) {
362b01988a5SMariusz Zaborski #ifdef HAVE_CASPER
363197731f6SPawel Jakub Dawidek 		if (capdns != NULL) {
364197731f6SPawel Jakub Dawidek 			hp = cap_gethostbyaddr(capdns, (char *)&addr,
365197731f6SPawel Jakub Dawidek 			    sizeof(addr), AF_INET6);
366197731f6SPawel Jakub Dawidek 		} else
367197731f6SPawel Jakub Dawidek #endif
3683340d773SGleb Smirnoff 			hp = gethostbyaddr((char *)&addr, sizeof(addr),
3693340d773SGleb Smirnoff 			    AF_INET6);
370a88113a8SBill Fenner 		if (hp) {
371a88113a8SBill Fenner 			char *dotp;
372a88113a8SBill Fenner 
373a1c2090eSBill Fenner 			p->name = strdup(hp->h_name);
3743340d773SGleb Smirnoff 			if (p->name == NULL)
375*ee67461eSJoseph Mingrone 				(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
376*ee67461eSJoseph Mingrone 					"%s: strdup(hp->h_name)", __func__);
3773c602fabSXin LI 			if (ndo->ndo_Nflag) {
378a88113a8SBill Fenner 				/* Remove domain qualifications */
379a88113a8SBill Fenner 				dotp = strchr(p->name, '.');
380a88113a8SBill Fenner 				if (dotp)
381a88113a8SBill Fenner 					*dotp = '\0';
382a88113a8SBill Fenner 			}
383a88113a8SBill Fenner 			return (p->name);
384a88113a8SBill Fenner 		}
385a88113a8SBill Fenner 	}
3863340d773SGleb Smirnoff 	cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
387a1c2090eSBill Fenner 	p->name = strdup(cp);
3883340d773SGleb Smirnoff 	if (p->name == NULL)
389*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
390*ee67461eSJoseph Mingrone 				  "%s: strdup(cp)", __func__);
391a88113a8SBill Fenner 	return (p->name);
392a88113a8SBill Fenner }
393a88113a8SBill Fenner 
394*ee67461eSJoseph Mingrone static const char hex[16] = {
395*ee67461eSJoseph Mingrone 	'0', '1', '2', '3', '4', '5', '6', '7',
396*ee67461eSJoseph Mingrone 	'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
397*ee67461eSJoseph Mingrone };
3984edb46e9SPaul Traina 
399*ee67461eSJoseph Mingrone /*
400*ee67461eSJoseph Mingrone  * Convert an octet to two hex digits.
401*ee67461eSJoseph Mingrone  *
402*ee67461eSJoseph Mingrone  * Coverity appears either:
403*ee67461eSJoseph Mingrone  *
404*ee67461eSJoseph Mingrone  *    not to believe the C standard when it asserts that a uint8_t is
405*ee67461eSJoseph Mingrone  *    exactly 8 bits in size;
406*ee67461eSJoseph Mingrone  *
407*ee67461eSJoseph Mingrone  *    not to believe that an unsigned type of exactly 8 bits has a value
408*ee67461eSJoseph Mingrone  *    in the range of 0 to 255;
409*ee67461eSJoseph Mingrone  *
410*ee67461eSJoseph Mingrone  *    not to believe that, for a range of unsigned values, if you shift
411*ee67461eSJoseph Mingrone  *    one of those values right by 4 bits, the maximum result value is
412*ee67461eSJoseph Mingrone  *    the maximum value shifted right by 4 bits, with no stray 1's shifted
413*ee67461eSJoseph Mingrone  *    in;
414*ee67461eSJoseph Mingrone  *
415*ee67461eSJoseph Mingrone  *    not to believe that 255 >> 4 is 15;
416*ee67461eSJoseph Mingrone  *
417*ee67461eSJoseph Mingrone  * so it gets upset that we're taking a "tainted" unsigned value, shifting
418*ee67461eSJoseph Mingrone  * it right 4 bits, and using it as an index into a 16-element array.
419*ee67461eSJoseph Mingrone  *
420*ee67461eSJoseph Mingrone  * So we do a stupid pointless masking of the result of the shift with
421*ee67461eSJoseph Mingrone  * 0xf, to hammer the point home to Coverity.
422*ee67461eSJoseph Mingrone  */
423*ee67461eSJoseph Mingrone static inline char *
424*ee67461eSJoseph Mingrone octet_to_hex(char *cp, uint8_t octet)
425*ee67461eSJoseph Mingrone {
426*ee67461eSJoseph Mingrone 	*cp++ = hex[(octet >> 4) & 0xf];
427*ee67461eSJoseph Mingrone 	*cp++ = hex[(octet >> 0) & 0xf];
428*ee67461eSJoseph Mingrone 	return (cp);
429*ee67461eSJoseph Mingrone }
4304edb46e9SPaul Traina 
4314edb46e9SPaul Traina /* Find the hash node that corresponds the ether address 'ep' */
4324edb46e9SPaul Traina 
433*ee67461eSJoseph Mingrone static struct enamemem *
4343340d773SGleb Smirnoff lookup_emem(netdissect_options *ndo, const u_char *ep)
4354edb46e9SPaul Traina {
436*ee67461eSJoseph Mingrone 	u_int i, j, k;
4374edb46e9SPaul Traina 	struct enamemem *tp;
4384edb46e9SPaul Traina 
4394edb46e9SPaul Traina 	k = (ep[0] << 8) | ep[1];
4404edb46e9SPaul Traina 	j = (ep[2] << 8) | ep[3];
4414edb46e9SPaul Traina 	i = (ep[4] << 8) | ep[5];
4424edb46e9SPaul Traina 
4434edb46e9SPaul Traina 	tp = &enametable[(i ^ j) & (HASHNAMESIZE-1)];
4444edb46e9SPaul Traina 	while (tp->e_nxt)
4454edb46e9SPaul Traina 		if (tp->e_addr0 == i &&
4464edb46e9SPaul Traina 		    tp->e_addr1 == j &&
4474edb46e9SPaul Traina 		    tp->e_addr2 == k)
4484edb46e9SPaul Traina 			return tp;
4494edb46e9SPaul Traina 		else
4504edb46e9SPaul Traina 			tp = tp->e_nxt;
451*ee67461eSJoseph Mingrone 	tp->e_addr0 = (u_short)i;
452*ee67461eSJoseph Mingrone 	tp->e_addr1 = (u_short)j;
453*ee67461eSJoseph Mingrone 	tp->e_addr2 = (u_short)k;
4544edb46e9SPaul Traina 	tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
4554edb46e9SPaul Traina 	if (tp->e_nxt == NULL)
456*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "%s: calloc", __func__);
4574edb46e9SPaul Traina 
4584edb46e9SPaul Traina 	return tp;
4594edb46e9SPaul Traina }
4604edb46e9SPaul Traina 
461a1c2090eSBill Fenner /*
462a1c2090eSBill Fenner  * Find the hash node that corresponds to the bytestring 'bs'
463a1c2090eSBill Fenner  * with length 'nlen'
464a1c2090eSBill Fenner  */
465a1c2090eSBill Fenner 
466*ee67461eSJoseph Mingrone static struct bsnamemem *
467*ee67461eSJoseph Mingrone lookup_bytestring(netdissect_options *ndo, const u_char *bs,
4683340d773SGleb Smirnoff 		  const unsigned int nlen)
469a1c2090eSBill Fenner {
4700bff6a5aSEd Maste 	struct bsnamemem *tp;
471*ee67461eSJoseph Mingrone 	u_int i, j, k;
472a1c2090eSBill Fenner 
473a1c2090eSBill Fenner 	if (nlen >= 6) {
474a1c2090eSBill Fenner 		k = (bs[0] << 8) | bs[1];
475a1c2090eSBill Fenner 		j = (bs[2] << 8) | bs[3];
476a1c2090eSBill Fenner 		i = (bs[4] << 8) | bs[5];
477a1c2090eSBill Fenner 	} else if (nlen >= 4) {
478a1c2090eSBill Fenner 		k = (bs[0] << 8) | bs[1];
479a1c2090eSBill Fenner 		j = (bs[2] << 8) | bs[3];
480a1c2090eSBill Fenner 		i = 0;
481a1c2090eSBill Fenner 	} else
482a1c2090eSBill Fenner 		i = j = k = 0;
483a1c2090eSBill Fenner 
484a1c2090eSBill Fenner 	tp = &bytestringtable[(i ^ j) & (HASHNAMESIZE-1)];
4850bff6a5aSEd Maste 	while (tp->bs_nxt)
4860bff6a5aSEd Maste 		if (nlen == tp->bs_nbytes &&
4870bff6a5aSEd Maste 		    tp->bs_addr0 == i &&
4880bff6a5aSEd Maste 		    tp->bs_addr1 == j &&
4890bff6a5aSEd Maste 		    tp->bs_addr2 == k &&
4900bff6a5aSEd Maste 		    memcmp((const char *)bs, (const char *)(tp->bs_bytes), nlen) == 0)
491a1c2090eSBill Fenner 			return tp;
492a1c2090eSBill Fenner 		else
4930bff6a5aSEd Maste 			tp = tp->bs_nxt;
494a1c2090eSBill Fenner 
495*ee67461eSJoseph Mingrone 	tp->bs_addr0 = (u_short)i;
496*ee67461eSJoseph Mingrone 	tp->bs_addr1 = (u_short)j;
497*ee67461eSJoseph Mingrone 	tp->bs_addr2 = (u_short)k;
498a1c2090eSBill Fenner 
4990bff6a5aSEd Maste 	tp->bs_bytes = (u_char *) calloc(1, nlen);
5000bff6a5aSEd Maste 	if (tp->bs_bytes == NULL)
501*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
502*ee67461eSJoseph Mingrone 				  "%s: calloc", __func__);
503d03c0883SXin LI 
5040bff6a5aSEd Maste 	memcpy(tp->bs_bytes, bs, nlen);
5050bff6a5aSEd Maste 	tp->bs_nbytes = nlen;
5060bff6a5aSEd Maste 	tp->bs_nxt = (struct bsnamemem *)calloc(1, sizeof(*tp));
5070bff6a5aSEd Maste 	if (tp->bs_nxt == NULL)
508*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
509*ee67461eSJoseph Mingrone 				  "%s: calloc", __func__);
510a1c2090eSBill Fenner 
511a1c2090eSBill Fenner 	return tp;
512a1c2090eSBill Fenner }
513a1c2090eSBill Fenner 
5144edb46e9SPaul Traina /* Find the hash node that corresponds the NSAP 'nsap' */
5154edb46e9SPaul Traina 
516*ee67461eSJoseph Mingrone static struct enamemem *
517*ee67461eSJoseph Mingrone lookup_nsap(netdissect_options *ndo, const u_char *nsap,
518*ee67461eSJoseph Mingrone 	    u_int nsap_length)
5194edb46e9SPaul Traina {
520*ee67461eSJoseph Mingrone 	u_int i, j, k;
5214edb46e9SPaul Traina 	struct enamemem *tp;
5223340d773SGleb Smirnoff 	const u_char *ensap;
5234edb46e9SPaul Traina 
5243340d773SGleb Smirnoff 	if (nsap_length > 6) {
5253340d773SGleb Smirnoff 		ensap = nsap + nsap_length - 6;
5264edb46e9SPaul Traina 		k = (ensap[0] << 8) | ensap[1];
5274edb46e9SPaul Traina 		j = (ensap[2] << 8) | ensap[3];
5284edb46e9SPaul Traina 		i = (ensap[4] << 8) | ensap[5];
5294edb46e9SPaul Traina 	}
5304edb46e9SPaul Traina 	else
5314edb46e9SPaul Traina 		i = j = k = 0;
5324edb46e9SPaul Traina 
5334edb46e9SPaul Traina 	tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)];
5344edb46e9SPaul Traina 	while (tp->e_nxt)
5350bff6a5aSEd Maste 		if (nsap_length == tp->e_nsap[0] &&
5360bff6a5aSEd Maste 		    tp->e_addr0 == i &&
5374edb46e9SPaul Traina 		    tp->e_addr1 == j &&
5384edb46e9SPaul Traina 		    tp->e_addr2 == k &&
5390bff6a5aSEd Maste 		    memcmp((const char *)nsap,
5403340d773SGleb Smirnoff 			(char *)&(tp->e_nsap[1]), nsap_length) == 0)
5414edb46e9SPaul Traina 			return tp;
5424edb46e9SPaul Traina 		else
5434edb46e9SPaul Traina 			tp = tp->e_nxt;
544*ee67461eSJoseph Mingrone 	tp->e_addr0 = (u_short)i;
545*ee67461eSJoseph Mingrone 	tp->e_addr1 = (u_short)j;
546*ee67461eSJoseph Mingrone 	tp->e_addr2 = (u_short)k;
5473340d773SGleb Smirnoff 	tp->e_nsap = (u_char *)malloc(nsap_length + 1);
5484edb46e9SPaul Traina 	if (tp->e_nsap == NULL)
549*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "%s: malloc", __func__);
5503340d773SGleb Smirnoff 	tp->e_nsap[0] = (u_char)nsap_length;	/* guaranteed < ISONSAP_MAX_LENGTH */
5513340d773SGleb Smirnoff 	memcpy((char *)&tp->e_nsap[1], (const char *)nsap, nsap_length);
5524edb46e9SPaul Traina 	tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
5534edb46e9SPaul Traina 	if (tp->e_nxt == NULL)
554*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "%s: calloc", __func__);
5554edb46e9SPaul Traina 
5564edb46e9SPaul Traina 	return tp;
5574edb46e9SPaul Traina }
5584edb46e9SPaul Traina 
5594edb46e9SPaul Traina /* Find the hash node that corresponds the protoid 'pi'. */
5604edb46e9SPaul Traina 
561*ee67461eSJoseph Mingrone static struct protoidmem *
5623340d773SGleb Smirnoff lookup_protoid(netdissect_options *ndo, const u_char *pi)
5634edb46e9SPaul Traina {
564*ee67461eSJoseph Mingrone 	u_int i, j;
5654edb46e9SPaul Traina 	struct protoidmem *tp;
5664edb46e9SPaul Traina 
5674edb46e9SPaul Traina 	/* 5 octets won't be aligned */
5684edb46e9SPaul Traina 	i = (((pi[0] << 8) + pi[1]) << 8) + pi[2];
5694edb46e9SPaul Traina 	j =   (pi[3] << 8) + pi[4];
5704edb46e9SPaul Traina 	/* XXX should be endian-insensitive, but do big-endian testing  XXX */
5714edb46e9SPaul Traina 
5724edb46e9SPaul Traina 	tp = &protoidtable[(i ^ j) & (HASHNAMESIZE-1)];
5734edb46e9SPaul Traina 	while (tp->p_nxt)
5744edb46e9SPaul Traina 		if (tp->p_oui == i && tp->p_proto == j)
5754edb46e9SPaul Traina 			return tp;
5764edb46e9SPaul Traina 		else
5774edb46e9SPaul Traina 			tp = tp->p_nxt;
5784edb46e9SPaul Traina 	tp->p_oui = i;
579*ee67461eSJoseph Mingrone 	tp->p_proto = (u_short)j;
5804edb46e9SPaul Traina 	tp->p_nxt = (struct protoidmem *)calloc(1, sizeof(*tp));
5814edb46e9SPaul Traina 	if (tp->p_nxt == NULL)
582*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "%s: calloc", __func__);
5834edb46e9SPaul Traina 
5844edb46e9SPaul Traina 	return tp;
5854edb46e9SPaul Traina }
5864edb46e9SPaul Traina 
587a1c2090eSBill Fenner const char *
588*ee67461eSJoseph Mingrone etheraddr_string(netdissect_options *ndo, const uint8_t *ep)
5894edb46e9SPaul Traina {
590*ee67461eSJoseph Mingrone 	int i;
591*ee67461eSJoseph Mingrone 	char *cp;
592*ee67461eSJoseph Mingrone 	struct enamemem *tp;
59317cb103cSSam Leffler 	int oui;
59429292c17SSam Leffler 	char buf[BUFSIZE];
5954edb46e9SPaul Traina 
5963340d773SGleb Smirnoff 	tp = lookup_emem(ndo, ep);
5974edb46e9SPaul Traina 	if (tp->e_name)
5984edb46e9SPaul Traina 		return (tp->e_name);
599a1c2090eSBill Fenner #ifdef USE_ETHER_NTOHOST
6003c602fabSXin LI 	if (!ndo->ndo_nflag) {
60129292c17SSam Leffler 		char buf2[BUFSIZE];
602*ee67461eSJoseph Mingrone 		/*
603*ee67461eSJoseph Mingrone 		 * This is a non-const copy of ep for ether_ntohost(), which
604*ee67461eSJoseph Mingrone 		 * has its second argument non-const in OpenBSD. Also saves a
605*ee67461eSJoseph Mingrone 		 * type cast.
606*ee67461eSJoseph Mingrone 		 */
607*ee67461eSJoseph Mingrone 		struct ether_addr ea;
608c1ad1296SSam Leffler 
609*ee67461eSJoseph Mingrone 		memcpy (&ea, ep, MAC_ADDR_LEN);
610*ee67461eSJoseph Mingrone 		if (ether_ntohost(buf2, &ea) == 0) {
611cc391cceSBruce M Simpson 			tp->e_name = strdup(buf2);
6123340d773SGleb Smirnoff 			if (tp->e_name == NULL)
613*ee67461eSJoseph Mingrone 				(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
614*ee67461eSJoseph Mingrone 					"%s: strdup(buf2)", __func__);
6154edb46e9SPaul Traina 			return (tp->e_name);
6164edb46e9SPaul Traina 		}
6174edb46e9SPaul Traina 	}
6184edb46e9SPaul Traina #endif
6194edb46e9SPaul Traina 	cp = buf;
620*ee67461eSJoseph Mingrone 	oui = EXTRACT_BE_U_3(ep);
621*ee67461eSJoseph Mingrone 	cp = octet_to_hex(cp, *ep++);
62217cb103cSSam Leffler 	for (i = 5; --i >= 0;) {
6234edb46e9SPaul Traina 		*cp++ = ':';
624*ee67461eSJoseph Mingrone 		cp = octet_to_hex(cp, *ep++);
6254edb46e9SPaul Traina 	}
62629292c17SSam Leffler 
6273c602fabSXin LI 	if (!ndo->ndo_nflag) {
62817cb103cSSam Leffler 		snprintf(cp, BUFSIZE - (2 + 5*3), " (oui %s)",
62929292c17SSam Leffler 		    tok2str(oui_values, "Unknown", oui));
63029292c17SSam Leffler 	} else
6314edb46e9SPaul Traina 		*cp = '\0';
632a1c2090eSBill Fenner 	tp->e_name = strdup(buf);
6333340d773SGleb Smirnoff 	if (tp->e_name == NULL)
634*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
635*ee67461eSJoseph Mingrone 				  "%s: strdup(buf)", __func__);
6364edb46e9SPaul Traina 	return (tp->e_name);
6374edb46e9SPaul Traina }
6384edb46e9SPaul Traina 
639a1c2090eSBill Fenner const char *
640*ee67461eSJoseph Mingrone le64addr_string(netdissect_options *ndo, const uint8_t *ep)
641cac3dcd5SXin LI {
642cac3dcd5SXin LI 	const unsigned int len = 8;
643*ee67461eSJoseph Mingrone 	u_int i;
644*ee67461eSJoseph Mingrone 	char *cp;
645*ee67461eSJoseph Mingrone 	struct bsnamemem *tp;
646cac3dcd5SXin LI 	char buf[BUFSIZE];
647cac3dcd5SXin LI 
6483340d773SGleb Smirnoff 	tp = lookup_bytestring(ndo, ep, len);
6490bff6a5aSEd Maste 	if (tp->bs_name)
6500bff6a5aSEd Maste 		return (tp->bs_name);
651cac3dcd5SXin LI 
652cac3dcd5SXin LI 	cp = buf;
653cac3dcd5SXin LI 	for (i = len; i > 0 ; --i) {
654*ee67461eSJoseph Mingrone 		cp = octet_to_hex(cp, *(ep + i - 1));
655cac3dcd5SXin LI 		*cp++ = ':';
656cac3dcd5SXin LI 	}
657cac3dcd5SXin LI 	cp --;
658cac3dcd5SXin LI 
659cac3dcd5SXin LI 	*cp = '\0';
660cac3dcd5SXin LI 
6610bff6a5aSEd Maste 	tp->bs_name = strdup(buf);
6620bff6a5aSEd Maste 	if (tp->bs_name == NULL)
663*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
664*ee67461eSJoseph Mingrone 				  "%s: strdup(buf)", __func__);
665cac3dcd5SXin LI 
6660bff6a5aSEd Maste 	return (tp->bs_name);
667cac3dcd5SXin LI }
668cac3dcd5SXin LI 
669cac3dcd5SXin LI const char *
670*ee67461eSJoseph Mingrone linkaddr_string(netdissect_options *ndo, const uint8_t *ep,
6713340d773SGleb Smirnoff 		const unsigned int type, const unsigned int len)
672a1c2090eSBill Fenner {
673*ee67461eSJoseph Mingrone 	u_int i;
674*ee67461eSJoseph Mingrone 	char *cp;
675*ee67461eSJoseph Mingrone 	struct bsnamemem *tp;
676a1c2090eSBill Fenner 
67727df3f5dSRui Paulo 	if (len == 0)
67827df3f5dSRui Paulo 		return ("<empty>");
679a5779b6eSRui Paulo 
680*ee67461eSJoseph Mingrone 	if (type == LINKADDR_ETHER && len == MAC_ADDR_LEN)
6813c602fabSXin LI 		return (etheraddr_string(ndo, ep));
68227df3f5dSRui Paulo 
68327df3f5dSRui Paulo 	if (type == LINKADDR_FRELAY)
6848bdc5a62SPatrick Kelsey 		return (q922_string(ndo, ep, len));
685a1c2090eSBill Fenner 
6863340d773SGleb Smirnoff 	tp = lookup_bytestring(ndo, ep, len);
6870bff6a5aSEd Maste 	if (tp->bs_name)
6880bff6a5aSEd Maste 		return (tp->bs_name);
689a1c2090eSBill Fenner 
6900bff6a5aSEd Maste 	tp->bs_name = cp = (char *)malloc(len*3);
6910bff6a5aSEd Maste 	if (tp->bs_name == NULL)
692*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
693*ee67461eSJoseph Mingrone 				  "%s: malloc", __func__);
694*ee67461eSJoseph Mingrone 	cp = octet_to_hex(cp, *ep++);
695a1c2090eSBill Fenner 	for (i = len-1; i > 0 ; --i) {
696a1c2090eSBill Fenner 		*cp++ = ':';
697*ee67461eSJoseph Mingrone 		cp = octet_to_hex(cp, *ep++);
698a1c2090eSBill Fenner 	}
699a1c2090eSBill Fenner 	*cp = '\0';
7000bff6a5aSEd Maste 	return (tp->bs_name);
701a1c2090eSBill Fenner }
702a1c2090eSBill Fenner 
703c1ad1296SSam Leffler #define ISONSAP_MAX_LENGTH 20
704a1c2090eSBill Fenner const char *
705*ee67461eSJoseph Mingrone isonsap_string(netdissect_options *ndo, const uint8_t *nsap,
706*ee67461eSJoseph Mingrone 	       u_int nsap_length)
7074edb46e9SPaul Traina {
708*ee67461eSJoseph Mingrone 	u_int nsap_idx;
709*ee67461eSJoseph Mingrone 	char *cp;
710*ee67461eSJoseph Mingrone 	struct enamemem *tp;
7114edb46e9SPaul Traina 
712c1ad1296SSam Leffler 	if (nsap_length < 1 || nsap_length > ISONSAP_MAX_LENGTH)
71329292c17SSam Leffler 		return ("isonsap_string: illegal length");
714c1ad1296SSam Leffler 
7153340d773SGleb Smirnoff 	tp = lookup_nsap(ndo, nsap, nsap_length);
7164edb46e9SPaul Traina 	if (tp->e_name)
7174edb46e9SPaul Traina 		return tp->e_name;
7184edb46e9SPaul Traina 
719c1ad1296SSam Leffler 	tp->e_name = cp = (char *)malloc(sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx"));
7204edb46e9SPaul Traina 	if (cp == NULL)
721*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
722*ee67461eSJoseph Mingrone 				  "%s: malloc", __func__);
7234edb46e9SPaul Traina 
724c1ad1296SSam Leffler 	for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
725*ee67461eSJoseph Mingrone 		cp = octet_to_hex(cp, *nsap++);
726c1ad1296SSam Leffler 		if (((nsap_idx & 1) == 0) &&
727c1ad1296SSam Leffler 		     (nsap_idx + 1 < nsap_length)) {
72801bd0dbcSPaul Traina 			*cp++ = '.';
7294edb46e9SPaul Traina 		}
730c1ad1296SSam Leffler 	}
7314edb46e9SPaul Traina 	*cp = '\0';
7324edb46e9SPaul Traina 	return (tp->e_name);
7334edb46e9SPaul Traina }
7344edb46e9SPaul Traina 
735a1c2090eSBill Fenner const char *
7363340d773SGleb Smirnoff tcpport_string(netdissect_options *ndo, u_short port)
7374edb46e9SPaul Traina {
738*ee67461eSJoseph Mingrone 	struct hnamemem *tp;
739*ee67461eSJoseph Mingrone 	uint32_t i = port;
7404edb46e9SPaul Traina 	char buf[sizeof("00000")];
7414edb46e9SPaul Traina 
7424edb46e9SPaul Traina 	for (tp = &tporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
7434edb46e9SPaul Traina 		if (tp->addr == i)
7444edb46e9SPaul Traina 			return (tp->name);
7454edb46e9SPaul Traina 
7464edb46e9SPaul Traina 	tp->addr = i;
7473340d773SGleb Smirnoff 	tp->nxt = newhnamemem(ndo);
7484edb46e9SPaul Traina 
7497524a079SKris Kennaway 	(void)snprintf(buf, sizeof(buf), "%u", i);
750a1c2090eSBill Fenner 	tp->name = strdup(buf);
7513340d773SGleb Smirnoff 	if (tp->name == NULL)
752*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
753*ee67461eSJoseph Mingrone 				  "%s: strdup(buf)", __func__);
7544edb46e9SPaul Traina 	return (tp->name);
7554edb46e9SPaul Traina }
7564edb46e9SPaul Traina 
757a1c2090eSBill Fenner const char *
758*ee67461eSJoseph Mingrone udpport_string(netdissect_options *ndo, u_short port)
7594edb46e9SPaul Traina {
760*ee67461eSJoseph Mingrone 	struct hnamemem *tp;
761*ee67461eSJoseph Mingrone 	uint32_t i = port;
7624edb46e9SPaul Traina 	char buf[sizeof("00000")];
7634edb46e9SPaul Traina 
7644edb46e9SPaul Traina 	for (tp = &uporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
7654edb46e9SPaul Traina 		if (tp->addr == i)
7664edb46e9SPaul Traina 			return (tp->name);
7674edb46e9SPaul Traina 
7684edb46e9SPaul Traina 	tp->addr = i;
7693340d773SGleb Smirnoff 	tp->nxt = newhnamemem(ndo);
7704edb46e9SPaul Traina 
7717524a079SKris Kennaway 	(void)snprintf(buf, sizeof(buf), "%u", i);
772a1c2090eSBill Fenner 	tp->name = strdup(buf);
7733340d773SGleb Smirnoff 	if (tp->name == NULL)
774*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
775*ee67461eSJoseph Mingrone 				  "%s: strdup(buf)", __func__);
7764edb46e9SPaul Traina 	return (tp->name);
7774edb46e9SPaul Traina }
7784edb46e9SPaul Traina 
779cc391cceSBruce M Simpson const char *
7803340d773SGleb Smirnoff ipxsap_string(netdissect_options *ndo, u_short port)
781cc391cceSBruce M Simpson {
782*ee67461eSJoseph Mingrone 	char *cp;
783*ee67461eSJoseph Mingrone 	struct hnamemem *tp;
784*ee67461eSJoseph Mingrone 	uint32_t i = port;
785cc391cceSBruce M Simpson 	char buf[sizeof("0000")];
786cc391cceSBruce M Simpson 
787cc391cceSBruce M Simpson 	for (tp = &ipxsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
788cc391cceSBruce M Simpson 		if (tp->addr == i)
789cc391cceSBruce M Simpson 			return (tp->name);
790cc391cceSBruce M Simpson 
791cc391cceSBruce M Simpson 	tp->addr = i;
7923340d773SGleb Smirnoff 	tp->nxt = newhnamemem(ndo);
793cc391cceSBruce M Simpson 
794cc391cceSBruce M Simpson 	cp = buf;
795*ee67461eSJoseph Mingrone 	port = ntohs(port);
796cc391cceSBruce M Simpson 	*cp++ = hex[port >> 12 & 0xf];
797cc391cceSBruce M Simpson 	*cp++ = hex[port >> 8 & 0xf];
798cc391cceSBruce M Simpson 	*cp++ = hex[port >> 4 & 0xf];
799cc391cceSBruce M Simpson 	*cp++ = hex[port & 0xf];
800cc391cceSBruce M Simpson 	*cp++ = '\0';
801cc391cceSBruce M Simpson 	tp->name = strdup(buf);
8023340d773SGleb Smirnoff 	if (tp->name == NULL)
803*ee67461eSJoseph Mingrone 		(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
804*ee67461eSJoseph Mingrone 				  "%s: strdup(buf)", __func__);
805cc391cceSBruce M Simpson 	return (tp->name);
806cc391cceSBruce M Simpson }
807cc391cceSBruce M Simpson 
8084edb46e9SPaul Traina static void
8093c602fabSXin LI init_servarray(netdissect_options *ndo)
8104edb46e9SPaul Traina {
8114edb46e9SPaul Traina 	struct servent *sv;
812*ee67461eSJoseph Mingrone 	struct hnamemem *table;
813*ee67461eSJoseph Mingrone 	int i;
8144edb46e9SPaul Traina 	char buf[sizeof("0000000000")];
8154edb46e9SPaul Traina 
8164edb46e9SPaul Traina 	while ((sv = getservent()) != NULL) {
8174edb46e9SPaul Traina 		int port = ntohs(sv->s_port);
8184edb46e9SPaul Traina 		i = port & (HASHNAMESIZE-1);
8194edb46e9SPaul Traina 		if (strcmp(sv->s_proto, "tcp") == 0)
8204edb46e9SPaul Traina 			table = &tporttable[i];
8214edb46e9SPaul Traina 		else if (strcmp(sv->s_proto, "udp") == 0)
8224edb46e9SPaul Traina 			table = &uporttable[i];
8234edb46e9SPaul Traina 		else
8244edb46e9SPaul Traina 			continue;
8254edb46e9SPaul Traina 
8264edb46e9SPaul Traina 		while (table->name)
8274edb46e9SPaul Traina 			table = table->nxt;
8283c602fabSXin LI 		if (ndo->ndo_nflag) {
8297524a079SKris Kennaway 			(void)snprintf(buf, sizeof(buf), "%d", port);
830a1c2090eSBill Fenner 			table->name = strdup(buf);
8314edb46e9SPaul Traina 		} else
832a1c2090eSBill Fenner 			table->name = strdup(sv->s_name);
8333340d773SGleb Smirnoff 		if (table->name == NULL)
834*ee67461eSJoseph Mingrone 			(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
835*ee67461eSJoseph Mingrone 					  "%s: strdup", __func__);
8363340d773SGleb Smirnoff 
8374edb46e9SPaul Traina 		table->addr = port;
8383340d773SGleb Smirnoff 		table->nxt = newhnamemem(ndo);
8394edb46e9SPaul Traina 	}
8404edb46e9SPaul Traina 	endservent();
8414edb46e9SPaul Traina }
8424edb46e9SPaul Traina 
8433340d773SGleb Smirnoff static const struct eproto {
844c1ad1296SSam Leffler 	const char *s;
8454edb46e9SPaul Traina 	u_short p;
8463340d773SGleb Smirnoff } eproto_db[] = {
847*ee67461eSJoseph Mingrone 	{ "aarp", ETHERTYPE_AARP },
848*ee67461eSJoseph Mingrone 	{ "arp", ETHERTYPE_ARP },
849*ee67461eSJoseph Mingrone 	{ "atalk", ETHERTYPE_ATALK },
850*ee67461eSJoseph Mingrone 	{ "decnet", ETHERTYPE_DN },
8513340d773SGleb Smirnoff 	{ "ip", ETHERTYPE_IP },
8523340d773SGleb Smirnoff 	{ "ip6", ETHERTYPE_IPV6 },
853*ee67461eSJoseph Mingrone 	{ "lat", ETHERTYPE_LAT },
854*ee67461eSJoseph Mingrone 	{ "loopback", ETHERTYPE_LOOPBACK },
8553340d773SGleb Smirnoff 	{ "mopdl", ETHERTYPE_MOPDL },
8563340d773SGleb Smirnoff 	{ "moprc", ETHERTYPE_MOPRC },
857*ee67461eSJoseph Mingrone 	{ "rarp", ETHERTYPE_REVARP },
8583340d773SGleb Smirnoff 	{ "sca", ETHERTYPE_SCA },
8593340d773SGleb Smirnoff 	{ (char *)0, 0 }
8603340d773SGleb Smirnoff };
8614edb46e9SPaul Traina 
8624edb46e9SPaul Traina static void
8633340d773SGleb Smirnoff init_eprotoarray(netdissect_options *ndo)
8644edb46e9SPaul Traina {
865*ee67461eSJoseph Mingrone 	int i;
866*ee67461eSJoseph Mingrone 	struct hnamemem *table;
8674edb46e9SPaul Traina 
8684edb46e9SPaul Traina 	for (i = 0; eproto_db[i].s; i++) {
869cc391cceSBruce M Simpson 		int j = htons(eproto_db[i].p) & (HASHNAMESIZE-1);
8704edb46e9SPaul Traina 		table = &eprototable[j];
8714edb46e9SPaul Traina 		while (table->name)
8724edb46e9SPaul Traina 			table = table->nxt;
8734edb46e9SPaul Traina 		table->name = eproto_db[i].s;
874cc391cceSBruce M Simpson 		table->addr = htons(eproto_db[i].p);
8753340d773SGleb Smirnoff 		table->nxt = newhnamemem(ndo);
8764edb46e9SPaul Traina 	}
8774edb46e9SPaul Traina }
8784edb46e9SPaul Traina 
87927df3f5dSRui Paulo static const struct protoidlist {
880a1c2090eSBill Fenner 	const u_char protoid[5];
881a1c2090eSBill Fenner 	const char *name;
882a1c2090eSBill Fenner } protoidlist[] = {
883a1c2090eSBill Fenner 	{{ 0x00, 0x00, 0x0c, 0x01, 0x07 }, "CiscoMLS" },
884a1c2090eSBill Fenner 	{{ 0x00, 0x00, 0x0c, 0x20, 0x00 }, "CiscoCDP" },
885a1c2090eSBill Fenner 	{{ 0x00, 0x00, 0x0c, 0x20, 0x01 }, "CiscoCGMP" },
886a1c2090eSBill Fenner 	{{ 0x00, 0x00, 0x0c, 0x20, 0x03 }, "CiscoVTP" },
887a1c2090eSBill Fenner 	{{ 0x00, 0xe0, 0x2b, 0x00, 0xbb }, "ExtremeEDP" },
888a1c2090eSBill Fenner 	{{ 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL }
889a1c2090eSBill Fenner };
890a1c2090eSBill Fenner 
8914edb46e9SPaul Traina /*
8924edb46e9SPaul Traina  * SNAP proto IDs with org code 0:0:0 are actually encapsulated Ethernet
8934edb46e9SPaul Traina  * types.
8944edb46e9SPaul Traina  */
8954edb46e9SPaul Traina static void
8963340d773SGleb Smirnoff init_protoidarray(netdissect_options *ndo)
8974edb46e9SPaul Traina {
898*ee67461eSJoseph Mingrone 	int i;
899*ee67461eSJoseph Mingrone 	struct protoidmem *tp;
90027df3f5dSRui Paulo 	const struct protoidlist *pl;
9014edb46e9SPaul Traina 	u_char protoid[5];
9024edb46e9SPaul Traina 
9034edb46e9SPaul Traina 	protoid[0] = 0;
9044edb46e9SPaul Traina 	protoid[1] = 0;
9054edb46e9SPaul Traina 	protoid[2] = 0;
9064edb46e9SPaul Traina 	for (i = 0; eproto_db[i].s; i++) {
9074edb46e9SPaul Traina 		u_short etype = htons(eproto_db[i].p);
9084edb46e9SPaul Traina 
9094edb46e9SPaul Traina 		memcpy((char *)&protoid[3], (char *)&etype, 2);
9103340d773SGleb Smirnoff 		tp = lookup_protoid(ndo, protoid);
911a1c2090eSBill Fenner 		tp->p_name = strdup(eproto_db[i].s);
9123340d773SGleb Smirnoff 		if (tp->p_name == NULL)
913*ee67461eSJoseph Mingrone 			(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
914*ee67461eSJoseph Mingrone 				"%s: strdup(eproto_db[i].s)", __func__);
915a1c2090eSBill Fenner 	}
916a1c2090eSBill Fenner 	/* Hardwire some SNAP proto ID names */
917a1c2090eSBill Fenner 	for (pl = protoidlist; pl->name != NULL; ++pl) {
9183340d773SGleb Smirnoff 		tp = lookup_protoid(ndo, pl->protoid);
919a1c2090eSBill Fenner 		/* Don't override existing name */
920a1c2090eSBill Fenner 		if (tp->p_name != NULL)
921a1c2090eSBill Fenner 			continue;
922a1c2090eSBill Fenner 
923a1c2090eSBill Fenner 		tp->p_name = pl->name;
9244edb46e9SPaul Traina 	}
9254edb46e9SPaul Traina }
9264edb46e9SPaul Traina 
92727df3f5dSRui Paulo static const struct etherlist {
928*ee67461eSJoseph Mingrone 	const nd_mac_addr addr;
929a1c2090eSBill Fenner 	const char *name;
9304edb46e9SPaul Traina } etherlist[] = {
9314edb46e9SPaul Traina 	{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, "Broadcast" },
9324edb46e9SPaul Traina 	{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL }
9334edb46e9SPaul Traina };
9344edb46e9SPaul Traina 
9354edb46e9SPaul Traina /*
9364edb46e9SPaul Traina  * Initialize the ethers hash table.  We take two different approaches
9374edb46e9SPaul Traina  * depending on whether or not the system provides the ethers name
9384edb46e9SPaul Traina  * service.  If it does, we just wire in a few names at startup,
9394edb46e9SPaul Traina  * and etheraddr_string() fills in the table on demand.  If it doesn't,
9404edb46e9SPaul Traina  * then we suck in the entire /etc/ethers file at startup.  The idea
9414edb46e9SPaul Traina  * is that parsing the local file will be fast, but spinning through
9424edb46e9SPaul Traina  * all the ethers entries via NIS & next_etherent might be very slow.
9434edb46e9SPaul Traina  *
9444edb46e9SPaul Traina  * XXX pcap_next_etherent doesn't belong in the pcap interface, but
9454edb46e9SPaul Traina  * since the pcap module already does name-to-address translation,
9464edb46e9SPaul Traina  * it's already does most of the work for the ethernet address-to-name
9474edb46e9SPaul Traina  * translation, so we just pcap_next_etherent as a convenience.
9484edb46e9SPaul Traina  */
9494edb46e9SPaul Traina static void
9503340d773SGleb Smirnoff init_etherarray(netdissect_options *ndo)
9514edb46e9SPaul Traina {
952*ee67461eSJoseph Mingrone 	const struct etherlist *el;
953*ee67461eSJoseph Mingrone 	struct enamemem *tp;
954a1c2090eSBill Fenner #ifdef USE_ETHER_NTOHOST
9554edb46e9SPaul Traina 	char name[256];
9564edb46e9SPaul Traina #else
957*ee67461eSJoseph Mingrone 	struct pcap_etherent *ep;
958*ee67461eSJoseph Mingrone 	FILE *fp;
9594edb46e9SPaul Traina 
9604edb46e9SPaul Traina 	/* Suck in entire ethers file */
9614edb46e9SPaul Traina 	fp = fopen(PCAP_ETHERS_FILE, "r");
9624edb46e9SPaul Traina 	if (fp != NULL) {
9634edb46e9SPaul Traina 		while ((ep = pcap_next_etherent(fp)) != NULL) {
9643340d773SGleb Smirnoff 			tp = lookup_emem(ndo, ep->addr);
965a1c2090eSBill Fenner 			tp->e_name = strdup(ep->name);
9663340d773SGleb Smirnoff 			if (tp->e_name == NULL)
967*ee67461eSJoseph Mingrone 				(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
968*ee67461eSJoseph Mingrone 					"%s: strdup(ep->addr)", __func__);
9694edb46e9SPaul Traina 		}
9704edb46e9SPaul Traina 		(void)fclose(fp);
9714edb46e9SPaul Traina 	}
9724edb46e9SPaul Traina #endif
9734edb46e9SPaul Traina 
9744edb46e9SPaul Traina 	/* Hardwire some ethernet names */
9754edb46e9SPaul Traina 	for (el = etherlist; el->name != NULL; ++el) {
9763340d773SGleb Smirnoff 		tp = lookup_emem(ndo, el->addr);
9774edb46e9SPaul Traina 		/* Don't override existing name */
9784edb46e9SPaul Traina 		if (tp->e_name != NULL)
9794edb46e9SPaul Traina 			continue;
9804edb46e9SPaul Traina 
981a1c2090eSBill Fenner #ifdef USE_ETHER_NTOHOST
982c1ad1296SSam Leffler 		/*
983c1ad1296SSam Leffler 		 * Use YP/NIS version of name if available.
984c1ad1296SSam Leffler 		 */
985*ee67461eSJoseph Mingrone 		/* Same workaround as in etheraddr_string(). */
986*ee67461eSJoseph Mingrone 		struct ether_addr ea;
987*ee67461eSJoseph Mingrone 		memcpy (&ea, el->addr, MAC_ADDR_LEN);
988*ee67461eSJoseph Mingrone 		if (ether_ntohost(name, &ea) == 0) {
989a1c2090eSBill Fenner 			tp->e_name = strdup(name);
9903340d773SGleb Smirnoff 			if (tp->e_name == NULL)
991*ee67461eSJoseph Mingrone 				(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
992*ee67461eSJoseph Mingrone 					"%s: strdup(name)", __func__);
9934edb46e9SPaul Traina 			continue;
9944edb46e9SPaul Traina 		}
9954edb46e9SPaul Traina #endif
9964edb46e9SPaul Traina 		tp->e_name = el->name;
9974edb46e9SPaul Traina 	}
9984edb46e9SPaul Traina }
9994edb46e9SPaul Traina 
1000*ee67461eSJoseph Mingrone static const struct ipxsap_ent {
1001*ee67461eSJoseph Mingrone 	uint16_t	v;
1002*ee67461eSJoseph Mingrone 	const char	*s;
1003*ee67461eSJoseph Mingrone } ipxsap_db[] = {
1004cc391cceSBruce M Simpson 	{ 0x0000, "Unknown" },
1005cc391cceSBruce M Simpson 	{ 0x0001, "User" },
1006cc391cceSBruce M Simpson 	{ 0x0002, "User Group" },
1007cc391cceSBruce M Simpson 	{ 0x0003, "PrintQueue" },
1008cc391cceSBruce M Simpson 	{ 0x0004, "FileServer" },
1009cc391cceSBruce M Simpson 	{ 0x0005, "JobServer" },
1010cc391cceSBruce M Simpson 	{ 0x0006, "Gateway" },
1011cc391cceSBruce M Simpson 	{ 0x0007, "PrintServer" },
1012cc391cceSBruce M Simpson 	{ 0x0008, "ArchiveQueue" },
1013cc391cceSBruce M Simpson 	{ 0x0009, "ArchiveServer" },
1014cc391cceSBruce M Simpson 	{ 0x000a, "JobQueue" },
1015cc391cceSBruce M Simpson 	{ 0x000b, "Administration" },
1016cc391cceSBruce M Simpson 	{ 0x000F, "Novell TI-RPC" },
1017cc391cceSBruce M Simpson 	{ 0x0017, "Diagnostics" },
1018cc391cceSBruce M Simpson 	{ 0x0020, "NetBIOS" },
1019cc391cceSBruce M Simpson 	{ 0x0021, "NAS SNA Gateway" },
1020cc391cceSBruce M Simpson 	{ 0x0023, "NACS AsyncGateway" },
1021cc391cceSBruce M Simpson 	{ 0x0024, "RemoteBridge/RoutingService" },
1022cc391cceSBruce M Simpson 	{ 0x0026, "BridgeServer" },
1023cc391cceSBruce M Simpson 	{ 0x0027, "TCP/IP Gateway" },
1024cc391cceSBruce M Simpson 	{ 0x0028, "Point-to-point X.25 BridgeServer" },
1025cc391cceSBruce M Simpson 	{ 0x0029, "3270 Gateway" },
1026cc391cceSBruce M Simpson 	{ 0x002a, "CHI Corp" },
1027cc391cceSBruce M Simpson 	{ 0x002c, "PC Chalkboard" },
1028cc391cceSBruce M Simpson 	{ 0x002d, "TimeSynchServer" },
1029cc391cceSBruce M Simpson 	{ 0x002e, "ARCserve5.0/PalindromeBackup" },
1030cc391cceSBruce M Simpson 	{ 0x0045, "DI3270 Gateway" },
1031cc391cceSBruce M Simpson 	{ 0x0047, "AdvertisingPrintServer" },
1032cc391cceSBruce M Simpson 	{ 0x004a, "NetBlazerModems" },
1033cc391cceSBruce M Simpson 	{ 0x004b, "BtrieveVAP" },
1034cc391cceSBruce M Simpson 	{ 0x004c, "NetwareSQL" },
1035cc391cceSBruce M Simpson 	{ 0x004d, "XtreeNetwork" },
1036cc391cceSBruce M Simpson 	{ 0x0050, "BtrieveVAP4.11" },
1037cc391cceSBruce M Simpson 	{ 0x0052, "QuickLink" },
1038cc391cceSBruce M Simpson 	{ 0x0053, "PrintQueueUser" },
1039cc391cceSBruce M Simpson 	{ 0x0058, "Multipoint X.25 Router" },
1040cc391cceSBruce M Simpson 	{ 0x0060, "STLB/NLM" },
1041cc391cceSBruce M Simpson 	{ 0x0064, "ARCserve" },
1042cc391cceSBruce M Simpson 	{ 0x0066, "ARCserve3.0" },
1043cc391cceSBruce M Simpson 	{ 0x0072, "WAN CopyUtility" },
1044cc391cceSBruce M Simpson 	{ 0x007a, "TES-NetwareVMS" },
1045cc391cceSBruce M Simpson 	{ 0x0092, "WATCOM Debugger/EmeraldTapeBackupServer" },
1046cc391cceSBruce M Simpson 	{ 0x0095, "DDA OBGYN" },
1047cc391cceSBruce M Simpson 	{ 0x0098, "NetwareAccessServer" },
1048cc391cceSBruce M Simpson 	{ 0x009a, "Netware for VMS II/NamedPipeServer" },
1049cc391cceSBruce M Simpson 	{ 0x009b, "NetwareAccessServer" },
1050cc391cceSBruce M Simpson 	{ 0x009e, "PortableNetwareServer/SunLinkNVT" },
1051cc391cceSBruce M Simpson 	{ 0x00a1, "PowerchuteAPC UPS" },
1052cc391cceSBruce M Simpson 	{ 0x00aa, "LAWserve" },
1053cc391cceSBruce M Simpson 	{ 0x00ac, "CompaqIDA StatusMonitor" },
1054cc391cceSBruce M Simpson 	{ 0x0100, "PIPE STAIL" },
1055cc391cceSBruce M Simpson 	{ 0x0102, "LAN ProtectBindery" },
1056cc391cceSBruce M Simpson 	{ 0x0103, "OracleDataBaseServer" },
1057cc391cceSBruce M Simpson 	{ 0x0107, "Netware386/RSPX RemoteConsole" },
1058cc391cceSBruce M Simpson 	{ 0x010f, "NovellSNA Gateway" },
1059cc391cceSBruce M Simpson 	{ 0x0111, "TestServer" },
1060cc391cceSBruce M Simpson 	{ 0x0112, "HP PrintServer" },
1061cc391cceSBruce M Simpson 	{ 0x0114, "CSA MUX" },
1062cc391cceSBruce M Simpson 	{ 0x0115, "CSA LCA" },
1063cc391cceSBruce M Simpson 	{ 0x0116, "CSA CM" },
1064cc391cceSBruce M Simpson 	{ 0x0117, "CSA SMA" },
1065cc391cceSBruce M Simpson 	{ 0x0118, "CSA DBA" },
1066cc391cceSBruce M Simpson 	{ 0x0119, "CSA NMA" },
1067cc391cceSBruce M Simpson 	{ 0x011a, "CSA SSA" },
1068cc391cceSBruce M Simpson 	{ 0x011b, "CSA STATUS" },
1069cc391cceSBruce M Simpson 	{ 0x011e, "CSA APPC" },
1070cc391cceSBruce M Simpson 	{ 0x0126, "SNA TEST SSA Profile" },
1071cc391cceSBruce M Simpson 	{ 0x012a, "CSA TRACE" },
1072cc391cceSBruce M Simpson 	{ 0x012b, "NetwareSAA" },
1073cc391cceSBruce M Simpson 	{ 0x012e, "IKARUS VirusScan" },
1074cc391cceSBruce M Simpson 	{ 0x0130, "CommunicationsExecutive" },
1075cc391cceSBruce M Simpson 	{ 0x0133, "NNS DomainServer/NetwareNamingServicesDomain" },
1076cc391cceSBruce M Simpson 	{ 0x0135, "NetwareNamingServicesProfile" },
1077cc391cceSBruce M Simpson 	{ 0x0137, "Netware386 PrintQueue/NNS PrintQueue" },
1078cc391cceSBruce M Simpson 	{ 0x0141, "LAN SpoolServer" },
1079cc391cceSBruce M Simpson 	{ 0x0152, "IRMALAN Gateway" },
1080cc391cceSBruce M Simpson 	{ 0x0154, "NamedPipeServer" },
1081cc391cceSBruce M Simpson 	{ 0x0166, "NetWareManagement" },
1082cc391cceSBruce M Simpson 	{ 0x0168, "Intel PICKIT CommServer/Intel CAS TalkServer" },
1083cc391cceSBruce M Simpson 	{ 0x0173, "Compaq" },
1084cc391cceSBruce M Simpson 	{ 0x0174, "Compaq SNMP Agent" },
1085cc391cceSBruce M Simpson 	{ 0x0175, "Compaq" },
1086cc391cceSBruce M Simpson 	{ 0x0180, "XTreeServer/XTreeTools" },
1087cc391cceSBruce M Simpson 	{ 0x018A, "NASI ServicesBroadcastServer" },
1088cc391cceSBruce M Simpson 	{ 0x01b0, "GARP Gateway" },
1089cc391cceSBruce M Simpson 	{ 0x01b1, "Binfview" },
1090cc391cceSBruce M Simpson 	{ 0x01bf, "IntelLanDeskManager" },
1091cc391cceSBruce M Simpson 	{ 0x01ca, "AXTEC" },
1092cc391cceSBruce M Simpson 	{ 0x01cb, "ShivaNetModem/E" },
1093cc391cceSBruce M Simpson 	{ 0x01cc, "ShivaLanRover/E" },
1094cc391cceSBruce M Simpson 	{ 0x01cd, "ShivaLanRover/T" },
1095cc391cceSBruce M Simpson 	{ 0x01ce, "ShivaUniversal" },
1096cc391cceSBruce M Simpson 	{ 0x01d8, "CastelleFAXPressServer" },
1097cc391cceSBruce M Simpson 	{ 0x01da, "CastelleLANPressPrintServer" },
1098cc391cceSBruce M Simpson 	{ 0x01dc, "CastelleFAX/Xerox7033 FaxServer/ExcelLanFax" },
1099cc391cceSBruce M Simpson 	{ 0x01f0, "LEGATO" },
1100cc391cceSBruce M Simpson 	{ 0x01f5, "LEGATO" },
1101cc391cceSBruce M Simpson 	{ 0x0233, "NMS Agent/NetwareManagementAgent" },
1102cc391cceSBruce M Simpson 	{ 0x0237, "NMS IPX Discovery/LANternReadWriteChannel" },
1103cc391cceSBruce M Simpson 	{ 0x0238, "NMS IP Discovery/LANternTrapAlarmChannel" },
1104cc391cceSBruce M Simpson 	{ 0x023a, "LANtern" },
1105cc391cceSBruce M Simpson 	{ 0x023c, "MAVERICK" },
1106cc391cceSBruce M Simpson 	{ 0x023f, "NovellSMDR" },
1107cc391cceSBruce M Simpson 	{ 0x024e, "NetwareConnect" },
1108cc391cceSBruce M Simpson 	{ 0x024f, "NASI ServerBroadcast Cisco" },
1109cc391cceSBruce M Simpson 	{ 0x026a, "NMS ServiceConsole" },
1110cc391cceSBruce M Simpson 	{ 0x026b, "TimeSynchronizationServer Netware 4.x" },
1111cc391cceSBruce M Simpson 	{ 0x0278, "DirectoryServer Netware 4.x" },
1112cc391cceSBruce M Simpson 	{ 0x027b, "NetwareManagementAgent" },
1113cc391cceSBruce M Simpson 	{ 0x0280, "Novell File and Printer Sharing Service for PC" },
1114cc391cceSBruce M Simpson 	{ 0x0304, "NovellSAA Gateway" },
1115cc391cceSBruce M Simpson 	{ 0x0308, "COM/VERMED" },
1116cc391cceSBruce M Simpson 	{ 0x030a, "GalacticommWorldgroupServer" },
1117cc391cceSBruce M Simpson 	{ 0x030c, "IntelNetport2/HP JetDirect/HP Quicksilver" },
1118cc391cceSBruce M Simpson 	{ 0x0320, "AttachmateGateway" },
1119cc391cceSBruce M Simpson 	{ 0x0327, "MicrosoftDiagnostiocs" },
1120cc391cceSBruce M Simpson 	{ 0x0328, "WATCOM SQL Server" },
1121cc391cceSBruce M Simpson 	{ 0x0335, "MultiTechSystems MultisynchCommServer" },
1122cc391cceSBruce M Simpson 	{ 0x0343, "Xylogics RemoteAccessServer/LANModem" },
1123cc391cceSBruce M Simpson 	{ 0x0355, "ArcadaBackupExec" },
1124cc391cceSBruce M Simpson 	{ 0x0358, "MSLCD1" },
1125cc391cceSBruce M Simpson 	{ 0x0361, "NETINELO" },
1126cc391cceSBruce M Simpson 	{ 0x037e, "Powerchute UPS Monitoring" },
1127cc391cceSBruce M Simpson 	{ 0x037f, "ViruSafeNotify" },
1128cc391cceSBruce M Simpson 	{ 0x0386, "HP Bridge" },
1129cc391cceSBruce M Simpson 	{ 0x0387, "HP Hub" },
1130cc391cceSBruce M Simpson 	{ 0x0394, "NetWare SAA Gateway" },
1131cc391cceSBruce M Simpson 	{ 0x039b, "LotusNotes" },
1132cc391cceSBruce M Simpson 	{ 0x03b7, "CertusAntiVirus" },
1133cc391cceSBruce M Simpson 	{ 0x03c4, "ARCserve4.0" },
1134cc391cceSBruce M Simpson 	{ 0x03c7, "LANspool3.5" },
1135cc391cceSBruce M Simpson 	{ 0x03d7, "LexmarkPrinterServer" },
1136cc391cceSBruce M Simpson 	{ 0x03d8, "LexmarkXLE PrinterServer" },
1137cc391cceSBruce M Simpson 	{ 0x03dd, "BanyanENS NetwareClient" },
1138cc391cceSBruce M Simpson 	{ 0x03de, "GuptaSequelBaseServer/NetWareSQL" },
1139cc391cceSBruce M Simpson 	{ 0x03e1, "UnivelUnixware" },
1140cc391cceSBruce M Simpson 	{ 0x03e4, "UnivelUnixware" },
1141cc391cceSBruce M Simpson 	{ 0x03fc, "IntelNetport" },
1142cc391cceSBruce M Simpson 	{ 0x03fd, "PrintServerQueue" },
1143cc391cceSBruce M Simpson 	{ 0x040A, "ipnServer" },
1144cc391cceSBruce M Simpson 	{ 0x040D, "LVERRMAN" },
1145cc391cceSBruce M Simpson 	{ 0x040E, "LVLIC" },
1146cc391cceSBruce M Simpson 	{ 0x0414, "NET Silicon (DPI)/Kyocera" },
1147cc391cceSBruce M Simpson 	{ 0x0429, "SiteLockVirus" },
1148cc391cceSBruce M Simpson 	{ 0x0432, "UFHELPR???" },
1149cc391cceSBruce M Simpson 	{ 0x0433, "Synoptics281xAdvancedSNMPAgent" },
1150cc391cceSBruce M Simpson 	{ 0x0444, "MicrosoftNT SNA Server" },
1151cc391cceSBruce M Simpson 	{ 0x0448, "Oracle" },
1152cc391cceSBruce M Simpson 	{ 0x044c, "ARCserve5.01" },
1153cc391cceSBruce M Simpson 	{ 0x0457, "CanonGP55" },
1154cc391cceSBruce M Simpson 	{ 0x045a, "QMS Printers" },
1155cc391cceSBruce M Simpson 	{ 0x045b, "DellSCSI Array" },
1156cc391cceSBruce M Simpson 	{ 0x0491, "NetBlazerModems" },
1157cc391cceSBruce M Simpson 	{ 0x04ac, "OnTimeScheduler" },
1158cc391cceSBruce M Simpson 	{ 0x04b0, "CD-Net" },
1159cc391cceSBruce M Simpson 	{ 0x0513, "EmulexNQA" },
1160cc391cceSBruce M Simpson 	{ 0x0520, "SiteLockChecks" },
1161cc391cceSBruce M Simpson 	{ 0x0529, "SiteLockChecks" },
1162cc391cceSBruce M Simpson 	{ 0x052d, "CitrixOS2 AppServer" },
1163cc391cceSBruce M Simpson 	{ 0x0535, "Tektronix" },
1164cc391cceSBruce M Simpson 	{ 0x0536, "Milan" },
1165cc391cceSBruce M Simpson 	{ 0x055d, "Attachmate SNA gateway" },
1166cc391cceSBruce M Simpson 	{ 0x056b, "IBM8235 ModemServer" },
1167cc391cceSBruce M Simpson 	{ 0x056c, "ShivaLanRover/E PLUS" },
1168cc391cceSBruce M Simpson 	{ 0x056d, "ShivaLanRover/T PLUS" },
1169cc391cceSBruce M Simpson 	{ 0x0580, "McAfeeNetShield" },
1170cc391cceSBruce M Simpson 	{ 0x05B8, "NLM to workstation communication (Revelation Software)" },
1171cc391cceSBruce M Simpson 	{ 0x05BA, "CompatibleSystemsRouters" },
1172cc391cceSBruce M Simpson 	{ 0x05BE, "CheyenneHierarchicalStorageManager" },
1173cc391cceSBruce M Simpson 	{ 0x0606, "JCWatermarkImaging" },
1174cc391cceSBruce M Simpson 	{ 0x060c, "AXISNetworkPrinter" },
1175cc391cceSBruce M Simpson 	{ 0x0610, "AdaptecSCSIManagement" },
1176cc391cceSBruce M Simpson 	{ 0x0621, "IBM AntiVirus" },
1177cc391cceSBruce M Simpson 	{ 0x0640, "Windows95 RemoteRegistryService" },
1178cc391cceSBruce M Simpson 	{ 0x064e, "MicrosoftIIS" },
1179cc391cceSBruce M Simpson 	{ 0x067b, "Microsoft Win95/98 File and Print Sharing for NetWare" },
1180cc391cceSBruce M Simpson 	{ 0x067c, "Microsoft Win95/98 File and Print Sharing for NetWare" },
1181cc391cceSBruce M Simpson 	{ 0x076C, "Xerox" },
1182cc391cceSBruce M Simpson 	{ 0x079b, "ShivaLanRover/E 115" },
1183cc391cceSBruce M Simpson 	{ 0x079c, "ShivaLanRover/T 115" },
1184cc391cceSBruce M Simpson 	{ 0x07B4, "CubixWorldDesk" },
1185cc391cceSBruce M Simpson 	{ 0x07c2, "Quarterdeck IWare Connect V2.x NLM" },
1186cc391cceSBruce M Simpson 	{ 0x07c1, "Quarterdeck IWare Connect V3.x NLM" },
1187cc391cceSBruce M Simpson 	{ 0x0810, "ELAN License Server Demo" },
1188cc391cceSBruce M Simpson 	{ 0x0824, "ShivaLanRoverAccessSwitch/E" },
1189cc391cceSBruce M Simpson 	{ 0x086a, "ISSC Collector" },
1190cc391cceSBruce M Simpson 	{ 0x087f, "ISSC DAS AgentAIX" },
1191cc391cceSBruce M Simpson 	{ 0x0880, "Intel Netport PRO" },
1192cc391cceSBruce M Simpson 	{ 0x0881, "Intel Netport PRO" },
1193cc391cceSBruce M Simpson 	{ 0x0b29, "SiteLock" },
1194cc391cceSBruce M Simpson 	{ 0x0c29, "SiteLockApplications" },
1195cc391cceSBruce M Simpson 	{ 0x0c2c, "LicensingServer" },
1196cc391cceSBruce M Simpson 	{ 0x2101, "PerformanceTechnologyInstantInternet" },
1197cc391cceSBruce M Simpson 	{ 0x2380, "LAI SiteLock" },
1198cc391cceSBruce M Simpson 	{ 0x238c, "MeetingMaker" },
1199cc391cceSBruce M Simpson 	{ 0x4808, "SiteLockServer/SiteLockMetering" },
1200cc391cceSBruce M Simpson 	{ 0x5555, "SiteLockUser" },
1201cc391cceSBruce M Simpson 	{ 0x6312, "Tapeware" },
1202cc391cceSBruce M Simpson 	{ 0x6f00, "RabbitGateway" },
1203cc391cceSBruce M Simpson 	{ 0x7703, "MODEM" },
1204cc391cceSBruce M Simpson 	{ 0x8002, "NetPortPrinters" },
1205cc391cceSBruce M Simpson 	{ 0x8008, "WordPerfectNetworkVersion" },
1206cc391cceSBruce M Simpson 	{ 0x85BE, "Cisco EIGRP" },
1207cc391cceSBruce M Simpson 	{ 0x8888, "WordPerfectNetworkVersion/QuickNetworkManagement" },
1208cc391cceSBruce M Simpson 	{ 0x9000, "McAfeeNetShield" },
1209cc391cceSBruce M Simpson 	{ 0x9604, "CSA-NT_MON" },
1210cc391cceSBruce M Simpson 	{ 0xb6a8, "OceanIsleReachoutRemoteControl" },
1211cc391cceSBruce M Simpson 	{ 0xf11f, "SiteLockMetering" },
1212cc391cceSBruce M Simpson 	{ 0xf1ff, "SiteLock" },
1213cc391cceSBruce M Simpson 	{ 0xf503, "Microsoft SQL Server" },
1214cc391cceSBruce M Simpson 	{ 0xF905, "IBM TimeAndPlace" },
1215cc391cceSBruce M Simpson 	{ 0xfbfb, "TopCallIII FaxServer" },
1216cc391cceSBruce M Simpson 	{ 0xffff, "AnyService/Wildcard" },
1217cc391cceSBruce M Simpson 	{ 0, (char *)0 }
1218cc391cceSBruce M Simpson };
1219cc391cceSBruce M Simpson 
1220cc391cceSBruce M Simpson static void
12213340d773SGleb Smirnoff init_ipxsaparray(netdissect_options *ndo)
1222cc391cceSBruce M Simpson {
1223*ee67461eSJoseph Mingrone 	int i;
1224*ee67461eSJoseph Mingrone 	struct hnamemem *table;
1225cc391cceSBruce M Simpson 
1226cc391cceSBruce M Simpson 	for (i = 0; ipxsap_db[i].s != NULL; i++) {
1227*ee67461eSJoseph Mingrone 		u_int j = htons(ipxsap_db[i].v) & (HASHNAMESIZE-1);
1228cc391cceSBruce M Simpson 		table = &ipxsaptable[j];
1229cc391cceSBruce M Simpson 		while (table->name)
1230cc391cceSBruce M Simpson 			table = table->nxt;
1231cc391cceSBruce M Simpson 		table->name = ipxsap_db[i].s;
1232cc391cceSBruce M Simpson 		table->addr = htons(ipxsap_db[i].v);
12333340d773SGleb Smirnoff 		table->nxt = newhnamemem(ndo);
1234cc391cceSBruce M Simpson 	}
1235cc391cceSBruce M Simpson }
1236cc391cceSBruce M Simpson 
12374edb46e9SPaul Traina /*
12384edb46e9SPaul Traina  * Initialize the address to name translation machinery.  We map all
12393c602fabSXin LI  * non-local IP addresses to numeric addresses if ndo->ndo_fflag is true
12403c602fabSXin LI  * (i.e., to prevent blocking on the nameserver).  localnet is the IP address
12414edb46e9SPaul Traina  * of the local network.  mask is its subnet mask.
12424edb46e9SPaul Traina  */
12434edb46e9SPaul Traina void
12443c602fabSXin LI init_addrtoname(netdissect_options *ndo, uint32_t localnet, uint32_t mask)
12454edb46e9SPaul Traina {
12463c602fabSXin LI 	if (ndo->ndo_fflag) {
12474edb46e9SPaul Traina 		f_localnet = localnet;
12484edb46e9SPaul Traina 		f_netmask = mask;
12494edb46e9SPaul Traina 	}
12503c602fabSXin LI 	if (ndo->ndo_nflag)
12514edb46e9SPaul Traina 		/*
12524edb46e9SPaul Traina 		 * Simplest way to suppress names.
12534edb46e9SPaul Traina 		 */
12544edb46e9SPaul Traina 		return;
12554edb46e9SPaul Traina 
12563340d773SGleb Smirnoff 	init_etherarray(ndo);
12573c602fabSXin LI 	init_servarray(ndo);
12583340d773SGleb Smirnoff 	init_eprotoarray(ndo);
12593340d773SGleb Smirnoff 	init_protoidarray(ndo);
12603340d773SGleb Smirnoff 	init_ipxsaparray(ndo);
12614edb46e9SPaul Traina }
12624edb46e9SPaul Traina 
1263a1c2090eSBill Fenner const char *
12643c602fabSXin LI dnaddr_string(netdissect_options *ndo, u_short dnaddr)
12654edb46e9SPaul Traina {
1266*ee67461eSJoseph Mingrone 	struct hnamemem *tp;
12674edb46e9SPaul Traina 
12683340d773SGleb Smirnoff 	for (tp = &dnaddrtable[dnaddr & (HASHNAMESIZE-1)]; tp->nxt != NULL;
12694edb46e9SPaul Traina 	     tp = tp->nxt)
12704edb46e9SPaul Traina 		if (tp->addr == dnaddr)
12714edb46e9SPaul Traina 			return (tp->name);
12724edb46e9SPaul Traina 
12734edb46e9SPaul Traina 	tp->addr = dnaddr;
12743340d773SGleb Smirnoff 	tp->nxt = newhnamemem(ndo);
12753340d773SGleb Smirnoff 	tp->name = dnnum_string(ndo, dnaddr);
12764edb46e9SPaul Traina 
12774edb46e9SPaul Traina 	return(tp->name);
12784edb46e9SPaul Traina }
12794edb46e9SPaul Traina 
12804edb46e9SPaul Traina /* Return a zero'ed hnamemem struct and cuts down on calloc() overhead */
12814edb46e9SPaul Traina struct hnamemem *
12823340d773SGleb Smirnoff newhnamemem(netdissect_options *ndo)
12834edb46e9SPaul Traina {
1284*ee67461eSJoseph Mingrone 	struct hnamemem *p;
12854edb46e9SPaul Traina 	static struct hnamemem *ptr = NULL;
12864edb46e9SPaul Traina 	static u_int num = 0;
12874edb46e9SPaul Traina 
1288*ee67461eSJoseph Mingrone 	if (num  == 0) {
12894edb46e9SPaul Traina 		num = 64;
12904edb46e9SPaul Traina 		ptr = (struct hnamemem *)calloc(num, sizeof (*ptr));
12914edb46e9SPaul Traina 		if (ptr == NULL)
1292*ee67461eSJoseph Mingrone 			(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
1293*ee67461eSJoseph Mingrone 					  "%s: calloc", __func__);
12944edb46e9SPaul Traina 	}
12954edb46e9SPaul Traina 	--num;
12964edb46e9SPaul Traina 	p = ptr++;
12974edb46e9SPaul Traina 	return (p);
12984edb46e9SPaul Traina }
1299a88113a8SBill Fenner 
1300a88113a8SBill Fenner /* Return a zero'ed h6namemem struct and cuts down on calloc() overhead */
1301a88113a8SBill Fenner struct h6namemem *
13023340d773SGleb Smirnoff newh6namemem(netdissect_options *ndo)
1303a88113a8SBill Fenner {
1304*ee67461eSJoseph Mingrone 	struct h6namemem *p;
1305a88113a8SBill Fenner 	static struct h6namemem *ptr = NULL;
1306a88113a8SBill Fenner 	static u_int num = 0;
1307a88113a8SBill Fenner 
1308*ee67461eSJoseph Mingrone 	if (num  == 0) {
1309a88113a8SBill Fenner 		num = 64;
1310a88113a8SBill Fenner 		ptr = (struct h6namemem *)calloc(num, sizeof (*ptr));
1311a88113a8SBill Fenner 		if (ptr == NULL)
1312*ee67461eSJoseph Mingrone 			(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
1313*ee67461eSJoseph Mingrone 					  "%s: calloc", __func__);
1314a88113a8SBill Fenner 	}
1315a88113a8SBill Fenner 	--num;
1316a88113a8SBill Fenner 	p = ptr++;
1317a88113a8SBill Fenner 	return (p);
1318a88113a8SBill Fenner }
13198bdc5a62SPatrick Kelsey 
13208bdc5a62SPatrick Kelsey /* Represent TCI part of the 802.1Q 4-octet tag as text. */
13218bdc5a62SPatrick Kelsey const char *
13228bdc5a62SPatrick Kelsey ieee8021q_tci_string(const uint16_t tci)
13238bdc5a62SPatrick Kelsey {
13248bdc5a62SPatrick Kelsey 	static char buf[128];
13258bdc5a62SPatrick Kelsey 	snprintf(buf, sizeof(buf), "vlan %u, p %u%s",
13268bdc5a62SPatrick Kelsey 	         tci & 0xfff,
13278bdc5a62SPatrick Kelsey 	         tci >> 13,
13288bdc5a62SPatrick Kelsey 	         (tci & 0x1000) ? ", DEI" : "");
13298bdc5a62SPatrick Kelsey 	return buf;
13308bdc5a62SPatrick Kelsey }
1331