diff options
Diffstat (limited to 'contrib/tcpdump/addrtoname.c')
-rw-r--r-- | contrib/tcpdump/addrtoname.c | 89 |
1 files changed, 37 insertions, 52 deletions
diff --git a/contrib/tcpdump/addrtoname.c b/contrib/tcpdump/addrtoname.c index 852c89a..5995d23 100644 --- a/contrib/tcpdump/addrtoname.c +++ b/contrib/tcpdump/addrtoname.c @@ -20,10 +20,12 @@ * * Internet, ethernet, port, and protocol string to address * and address to string conversion routines + * + * $FreeBSD$ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.108 2005/03/27 22:38:09 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.96.2.6 2004/03/24 04:14:31 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -39,15 +41,11 @@ 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 NETINET_ETHER_H_DECLARES_ETHER_NTOHOST -#include <netinet/ether.h> -#endif /* NETINET_ETHER_H_DECLARES_ETHER_NTOHOST */ +#ifdef HAVE_NETINET_ETHER_H +#include <netinet/ether.h> /* ether_ntohost on linux */ +#endif /* HAVE_NETINET_ETHER_H */ #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> @@ -107,20 +105,25 @@ 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 { @@ -463,25 +466,18 @@ etheraddr_string(register const u_char *ep) #ifdef USE_ETHER_NTOHOST if (!nflag) { char buf2[128]; - - /* - * 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) { + if (ether_ntohost(buf2, (const 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'; @@ -492,7 +488,7 @@ etheraddr_string(register const u_char *ep) const char * linkaddr_string(const u_char *ep, const unsigned int len) { - register u_int i; + register u_int i, j; register char *cp; register struct enamemem *tp; @@ -506,11 +502,13 @@ 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"); - *cp++ = hex[*ep >> 4]; + if ((j = *ep >> 4) != 0) + *cp++ = hex[j]; *cp++ = hex[*ep++ & 0xf]; for (i = len-1; i > 0 ; --i) { *cp++ = ':'; - *cp++ = hex[*ep >> 4]; + if ((j = *ep >> 4) != 0) + *cp++ = hex[j]; *cp++ = hex[*ep++ & 0xf]; } *cp = '\0'; @@ -589,32 +587,27 @@ llcsap_string(u_char sap) return (tp->name); } -#define ISONSAP_MAX_LENGTH 20 const char * -isonsap_string(const u_char *nsap, register u_int nsap_length) +isonsap_string(const u_char *nsap) { - register u_int nsap_idx; + register u_int i, nlen = nsap[0]; 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(sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx")); + tp->e_name = cp = (char *)malloc(nlen * 2 + 2 + (nlen>>1)); if (cp == NULL) error("isonsap_string: malloc"); - for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) { + nsap++; + for (i = 0; i < nlen; i++) { *cp++ = hex[*nsap >> 4]; *cp++ = hex[*nsap++ & 0xf]; - if (((nsap_idx & 1) == 0) && - (nsap_idx + 1 < nsap_length)) { - *cp++ = '.'; - } + if (((i & 1) == 0) && (i + 1 < nlen)) + *cp++ = '.'; } *cp = '\0'; return (tp->e_name); @@ -715,14 +708,13 @@ init_servarray(void) endservent(); } -/* in libpcap.a (nametoaddr.c) */ -#if defined(WIN32) && !defined(USE_STATIC_LIBPCAP) -__declspec(dllimport) +/*XXX from libbpfc.a */ +#ifndef WIN32 +extern struct eproto { #else -extern +__declspec( dllimport) struct eproto { #endif -const struct eproto { - const char *s; + char *s; u_short p; } eproto_db[]; @@ -840,16 +832,9 @@ init_etherarray(void) continue; #ifdef USE_ETHER_NTOHOST - /* - * 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); + /* Use yp/nis version of name if available */ + if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) { + tp->e_name = strdup(name); continue; } #endif |