summaryrefslogtreecommitdiffstats
path: root/contrib/tcpdump/addrtoname.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tcpdump/addrtoname.c')
-rw-r--r--contrib/tcpdump/addrtoname.c87
1 files changed, 52 insertions, 35 deletions
diff --git a/contrib/tcpdump/addrtoname.c b/contrib/tcpdump/addrtoname.c
index 5995d23..c8ad891 100644
--- a/contrib/tcpdump/addrtoname.c
+++ b/contrib/tcpdump/addrtoname.c
@@ -25,7 +25,7 @@
*/
#ifndef lint
static const char rcsid[] _U_ =
- "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.96.2.6 2004/03/24 04:14:31 guy Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.108 2005/03/27 22:38:09 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@@ -41,11 +41,15 @@ struct rtentry; /* declarations in <net/if.h> */
#include <net/if.h> /* for "struct ifnet" in "struct arpcom" on Solaris */
#include <netinet/if_ether.h>
#endif /* HAVE_NETINET_IF_ETHER_H */
-#ifdef HAVE_NETINET_ETHER_H
-#include <netinet/ether.h> /* ether_ntohost on linux */
-#endif /* HAVE_NETINET_ETHER_H */
+#ifdef NETINET_ETHER_H_DECLARES_ETHER_NTOHOST
+#include <netinet/ether.h>
+#endif /* NETINET_ETHER_H_DECLARES_ETHER_NTOHOST */
#endif /* USE_ETHER_NTOHOST */
+#if !defined(HAVE_DECL_ETHER_NTOHOST) || !HAVE_DECL_ETHER_NTOHOST
+extern int ether_ntohost(char *, const struct ether_addr *);
+#endif
+
#include <pcap.h>
#include <pcap-namedb.h>
#include <signal.h>
@@ -105,25 +109,20 @@ win32_gethostbyaddr(const char *addr, int len, int type)
memset(&addr6, 0, sizeof(addr6));
addr6.sin6_family = AF_INET6;
memcpy(&addr6.sin6_addr, addr, len);
-#ifdef __MINGW32__
- /* MinGW doesn't provide getnameinfo */
- return NULL;
-#else
if (getnameinfo((struct sockaddr *)&addr6, sizeof(addr6),
- hname, sizeof(hname), NULL, 0, 0)) {
- return NULL;
+ hname, sizeof(hname), NULL, 0, 0)) {
+ return NULL;
} else {
strcpy(host.h_name, hname);
return &host;
}
-#endif /* __MINGW32__ */
break;
default:
return NULL;
}
}
#define gethostbyaddr win32_gethostbyaddr
-#endif /* INET6 & WIN32*/
+#endif /* INET6 & WIN32 */
#ifdef INET6
struct h6namemem {
@@ -466,18 +465,25 @@ etheraddr_string(register const u_char *ep)
#ifdef USE_ETHER_NTOHOST
if (!nflag) {
char buf2[128];
- if (ether_ntohost(buf2, (const struct ether_addr *)ep) == 0) {
+
+ /*
+ * We don't cast it to "const struct ether_addr *"
+ * because some systems don't modify the Ethernet
+ * address but fail to declare the second argument
+ * as a "const" pointer.
+ */
+ if (ether_ntohost(buf2, (struct ether_addr *)ep) == 0) {
tp->e_name = strdup(buf2);
return (tp->e_name);
}
}
#endif
cp = buf;
- *cp++ = hex[*ep >> 4 ];
+ *cp++ = hex[*ep >> 4 ];
*cp++ = hex[*ep++ & 0xf];
for (i = 5; (int)--i >= 0;) {
*cp++ = ':';
- *cp++ = hex[*ep >> 4 ];
+ *cp++ = hex[*ep >> 4 ];
*cp++ = hex[*ep++ & 0xf];
}
*cp = '\0';
@@ -488,7 +494,7 @@ etheraddr_string(register const u_char *ep)
const char *
linkaddr_string(const u_char *ep, const unsigned int len)
{
- register u_int i, j;
+ register u_int i;
register char *cp;
register struct enamemem *tp;
@@ -502,13 +508,11 @@ linkaddr_string(const u_char *ep, const unsigned int len)
tp->e_name = cp = (char *)malloc(len*3);
if (tp->e_name == NULL)
error("linkaddr_string: malloc");
- if ((j = *ep >> 4) != 0)
- *cp++ = hex[j];
+ *cp++ = hex[*ep >> 4];
*cp++ = hex[*ep++ & 0xf];
for (i = len-1; i > 0 ; --i) {
*cp++ = ':';
- if ((j = *ep >> 4) != 0)
- *cp++ = hex[j];
+ *cp++ = hex[*ep >> 4];
*cp++ = hex[*ep++ & 0xf];
}
*cp = '\0';
@@ -587,27 +591,32 @@ llcsap_string(u_char sap)
return (tp->name);
}
+#define ISONSAP_MAX_LENGTH 20
const char *
-isonsap_string(const u_char *nsap)
+isonsap_string(const u_char *nsap, register u_int nsap_length)
{
- register u_int i, nlen = nsap[0];
+ register u_int nsap_idx;
register char *cp;
register struct enamemem *tp;
+ if (nsap_length < 1 || nsap_length > ISONSAP_MAX_LENGTH)
+ error("isonsap_string: illegal length");
+
tp = lookup_nsap(nsap);
if (tp->e_name)
return tp->e_name;
- tp->e_name = cp = (char *)malloc(nlen * 2 + 2 + (nlen>>1));
+ tp->e_name = cp = (char *)malloc(sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx"));
if (cp == NULL)
error("isonsap_string: malloc");
- nsap++;
- for (i = 0; i < nlen; i++) {
+ for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
*cp++ = hex[*nsap >> 4];
*cp++ = hex[*nsap++ & 0xf];
- if (((i & 1) == 0) && (i + 1 < nlen))
- *cp++ = '.';
+ if (((nsap_idx & 1) == 0) &&
+ (nsap_idx + 1 < nsap_length)) {
+ *cp++ = '.';
+ }
}
*cp = '\0';
return (tp->e_name);
@@ -708,13 +717,14 @@ init_servarray(void)
endservent();
}
-/*XXX from libbpfc.a */
-#ifndef WIN32
-extern struct eproto {
+/* in libpcap.a (nametoaddr.c) */
+#if defined(WIN32) && !defined(USE_STATIC_LIBPCAP)
+__declspec(dllimport)
#else
-__declspec( dllimport) struct eproto {
+extern
#endif
- char *s;
+const struct eproto {
+ const char *s;
u_short p;
} eproto_db[];
@@ -832,9 +842,16 @@ init_etherarray(void)
continue;
#ifdef USE_ETHER_NTOHOST
- /* Use yp/nis version of name if available */
- if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) {
- tp->e_name = strdup(name);
+ /*
+ * Use YP/NIS version of name if available.
+ *
+ * We don't cast it to "const struct ether_addr *"
+ * because some systems don't modify the Ethernet
+ * address but fail to declare the second argument
+ * as a "const" pointer.
+ */
+ if (ether_ntohost(name, (struct ether_addr *)el->addr) == 0) {
+ tp->e_name = strdup(name);
continue;
}
#endif
OpenPOWER on IntegriCloud