Upgrade to tcpdump 4.7.4.

Bug: http://b/24902618
Change-Id: I7c3605015d90453b0a8c339b1774e285796f8775
diff --git a/addrtoname.c b/addrtoname.c
index 745ffe3..d0437fe 100644
--- a/addrtoname.c
+++ b/addrtoname.c
@@ -21,11 +21,8 @@
  *  Internet, ethernet, port, and protocol string to address
  *  and address to string conversion routines
  */
-#ifndef lint
-static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.119 2007-08-08 14:06:34 hannes Exp $ (LBL)";
-#endif
 
+#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -81,7 +78,7 @@
 #define HASHNAMESIZE 4096
 
 struct hnamemem {
-	u_int32_t addr;
+	uint32_t addr;
 	const char *name;
 	struct hnamemem *nxt;
 };
@@ -158,7 +155,7 @@
 static struct enamemem bytestringtable[HASHNAMESIZE];
 
 struct protoidmem {
-	u_int32_t p_oui;
+	uint32_t p_oui;
 	u_short p_proto;
 	const char *p_name;
 	struct protoidmem *p_nxt;
@@ -170,7 +167,7 @@
  * A faster replacement for inet_ntoa().
  */
 const char *
-intoa(u_int32_t addr)
+intoa(uint32_t addr)
 {
 	register char *cp;
 	register u_int byte;
@@ -199,8 +196,8 @@
 	return cp + 1;
 }
 
-static u_int32_t f_netmask;
-static u_int32_t f_localnet;
+static uint32_t f_netmask;
+static uint32_t f_localnet;
 
 /*
  * Return a name for the IP address pointed to by ap.  This address
@@ -222,10 +219,10 @@
  * also needs to check whether they're present in the packet buffer.
  */
 const char *
-getname(const u_char *ap)
+getname(netdissect_options *ndo, const u_char *ap)
 {
 	register struct hostent *hp;
-	u_int32_t addr;
+	uint32_t addr;
 	static struct hnamemem *p;		/* static for longjmp() */
 
 	memcpy(&addr, ap, sizeof(addr));
@@ -244,14 +241,14 @@
 	 *	    given, f_netmask and f_localnet are 0 and the test
 	 *	    evaluates to true)
 	 */
-	if (!nflag &&
+	if (!ndo->ndo_nflag &&
 	    (addr & f_netmask) == f_localnet) {
 		hp = gethostbyaddr((char *)&addr, 4, AF_INET);
 		if (hp) {
 			char *dotp;
 
 			p->name = strdup(hp->h_name);
-			if (Nflag) {
+			if (ndo->ndo_Nflag) {
 				/* Remove domain qualifications */
 				dotp = strchr(p->name, '.');
 				if (dotp)
@@ -270,14 +267,14 @@
  * is assumed to be in network byte order.
  */
 const char *
-getname6(const u_char *ap)
+getname6(netdissect_options *ndo, const u_char *ap)
 {
 	register struct hostent *hp;
 	union {
 		struct in6_addr addr;
 		struct for_hash_addr {
 			char fill[14];
-			u_int16_t d;
+			uint16_t d;
 		} addra;
 	} addr;
 	static struct h6namemem *p;		/* static for longjmp() */
@@ -296,13 +293,13 @@
 	/*
 	 * Do not print names if -n was given.
 	 */
-	if (!nflag) {
+	if (!ndo->ndo_nflag) {
 		hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET6);
 		if (hp) {
 			char *dotp;
 
 			p->name = strdup(hp->h_name);
-			if (Nflag) {
+			if (ndo->ndo_Nflag) {
 				/* Remove domain qualifications */
 				dotp = strchr(p->name, '.');
 				if (dotp)
@@ -470,7 +467,7 @@
 }
 
 const char *
-etheraddr_string(register const u_char *ep)
+etheraddr_string(netdissect_options *ndo, register const u_char *ep)
 {
 	register int i;
 	register char *cp;
@@ -482,7 +479,7 @@
 	if (tp->e_name)
 		return (tp->e_name);
 #ifdef USE_ETHER_NTOHOST
-	if (!nflag) {
+	if (!ndo->ndo_nflag) {
 		char buf2[BUFSIZE];
 
 		/*
@@ -507,7 +504,7 @@
 		*cp++ = hex[*ep++ & 0xf];
 	}
 
-	if (!nflag) {
+	if (!ndo->ndo_nflag) {
 		snprintf(cp, BUFSIZE - (2 + 5*3), " (oui %s)",
 		    tok2str(oui_values, "Unknown", oui));
 	} else
@@ -545,7 +542,7 @@
 }
 
 const char *
-linkaddr_string(const u_char *ep, const unsigned int type, const unsigned int len)
+linkaddr_string(netdissect_options *ndo, const u_char *ep, const unsigned int type, const unsigned int len)
 {
 	register u_int i;
 	register char *cp;
@@ -555,10 +552,10 @@
 		return ("<empty>");
 
 	if (type == LINKADDR_ETHER && len == ETHER_ADDR_LEN)
-		return (etheraddr_string(ep));
+		return (etheraddr_string(ndo, ep));
 
 	if (type == LINKADDR_FRELAY)
-		return (q922_string(ep));
+		return (q922_string(ndo, ep, len));
 
 	tp = lookup_bytestring(ep, len);
 	if (tp->e_name)
@@ -583,7 +580,7 @@
 {
 	register char *cp;
 	register struct hnamemem *tp;
-	register u_int32_t i = port;
+	register uint32_t i = port;
 	char buf[sizeof("0000")];
 
 	for (tp = &eprototable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
@@ -666,7 +663,7 @@
 tcpport_string(u_short port)
 {
 	register struct hnamemem *tp;
-	register u_int32_t i = port;
+	register uint32_t i = port;
 	char buf[sizeof("00000")];
 
 	for (tp = &tporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
@@ -685,7 +682,7 @@
 udpport_string(register u_short port)
 {
 	register struct hnamemem *tp;
-	register u_int32_t i = port;
+	register uint32_t i = port;
 	char buf[sizeof("00000")];
 
 	for (tp = &uporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
@@ -705,7 +702,7 @@
 {
 	register char *cp;
 	register struct hnamemem *tp;
-	register u_int32_t i = port;
+	register uint32_t i = port;
 	char buf[sizeof("0000")];
 
 	for (tp = &ipxsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
@@ -727,7 +724,7 @@
 }
 
 static void
-init_servarray(void)
+init_servarray(netdissect_options *ndo)
 {
 	struct servent *sv;
 	register struct hnamemem *table;
@@ -746,7 +743,7 @@
 
 		while (table->name)
 			table = table->nxt;
-		if (nflag) {
+		if (ndo->ndo_nflag) {
 			(void)snprintf(buf, sizeof(buf), "%d", port);
 			table->name = strdup(buf);
 		} else
@@ -759,7 +756,7 @@
 
 /* in libpcap.a (nametoaddr.c) */
 #if defined(WIN32) && !defined(USE_STATIC_LIBPCAP)
-__declspec(dllimport)
+extern __declspec(dllimport)
 #else
 extern
 #endif
@@ -1135,32 +1132,32 @@
 
 /*
  * Initialize the address to name translation machinery.  We map all
- * non-local IP addresses to numeric addresses if fflag is true (i.e.,
- * to prevent blocking on the nameserver).  localnet is the IP address
+ * non-local IP addresses to numeric addresses if ndo->ndo_fflag is true
+ * (i.e., to prevent blocking on the nameserver).  localnet is the IP address
  * of the local network.  mask is its subnet mask.
  */
 void
-init_addrtoname(u_int32_t localnet, u_int32_t mask)
+init_addrtoname(netdissect_options *ndo, uint32_t localnet, uint32_t mask)
 {
-	if (fflag) {
+	if (ndo->ndo_fflag) {
 		f_localnet = localnet;
 		f_netmask = mask;
 	}
-	if (nflag)
+	if (ndo->ndo_nflag)
 		/*
 		 * Simplest way to suppress names.
 		 */
 		return;
 
 	init_etherarray();
-	init_servarray();
+	init_servarray(ndo);
 	init_eprotoarray();
 	init_protoidarray();
 	init_ipxsaparray();
 }
 
 const char *
-dnaddr_string(u_short dnaddr)
+dnaddr_string(netdissect_options *ndo, u_short dnaddr)
 {
 	register struct hnamemem *tp;
 
@@ -1171,7 +1168,7 @@
 
 	tp->addr = dnaddr;
 	tp->nxt = newhnamemem();
-	if (nflag)
+	if (ndo->ndo_nflag)
 		tp->name = dnnum_string(dnaddr);
 	else
 		tp->name = dnname_string(dnaddr);
@@ -1218,3 +1215,15 @@
 	return (p);
 }
 #endif /* INET6 */
+
+/* Represent TCI part of the 802.1Q 4-octet tag as text. */
+const char *
+ieee8021q_tci_string(const uint16_t tci)
+{
+	static char buf[128];
+	snprintf(buf, sizeof(buf), "vlan %u, p %u%s",
+	         tci & 0xfff,
+	         tci >> 13,
+	         (tci & 0x1000) ? ", DEI" : "");
+	return buf;
+}