Skip to content

Commit

Permalink
Don't require IPv6 library support in order to support IPv6 addresses.
Browse files Browse the repository at this point in the history
Have our own routines to convert between IPv4/IPv6 addresses and
strings; that helps if, for example, we want to build binary versions of
tcpdump for Windows that can run both on NT 5 (W2K/WXP), which doesn't
have inet_ntop() or inet_pton(), and NT 6 (Vista/7/8/10), which do.  It
also means that we don't require IPv6 library support on UN*X to print
addresses (if somebody wants to build tcpdump for older UN*Xes lacking
IPv6 support in the system library or in add-on libraries).

Get rid of files in the missing directory that we don't need, and
various no-longer-necessary autoconf tests.
  • Loading branch information
guyharris committed Sep 17, 2015
1 parent 2a85a1b commit 11f73ad
Show file tree
Hide file tree
Showing 54 changed files with 547 additions and 2,046 deletions.
35 changes: 13 additions & 22 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ CSRC = setsignal.c tcpdump.c util.c

LIBNETDISSECT_SRC=\
addrtoname.c \
addrtostr.c \
af.c \
ascii_strcasecmp.c \
checksum.c \
Expand All @@ -100,6 +101,7 @@ LIBNETDISSECT_SRC=\
print-ascii.c \
print-atalk.c \
print-atm.c \
print-babel.c \
print-beep.c \
print-bfd.c \
print-bgp.c \
Expand All @@ -114,6 +116,7 @@ LIBNETDISSECT_SRC=\
print-cnfp.c \
print-dccp.c \
print-decnet.c \
print-dhcp6.c \
print-domain.c \
print-dtp.c \
print-dvmrp.c \
Expand All @@ -126,17 +129,20 @@ LIBNETDISSECT_SRC=\
print-fddi.c \
print-forces.c \
print-fr.c \
print-frag6.c \
print-ftp.c \
print-geneve.c \
print-geonet.c \
print-gre.c \
print-hsrp.c \
print-http.c \
print-icmp.c \
print-icmp6.c \
print-igmp.c \
print-igrp.c \
print-ip.c \
print-ip6.c \
print-ip6opts.c \
print-ipcomp.c \
print-ipfc.c \
print-ipnet.c \
Expand All @@ -158,6 +164,7 @@ LIBNETDISSECT_SRC=\
print-m3ua.c \
print-medsa.c \
print-mobile.c \
print-mobility.c \
print-mpcp.c \
print-mpls.c \
print-mptcp.c \
Expand All @@ -171,6 +178,7 @@ LIBNETDISSECT_SRC=\
print-openflow-1.0.c \
print-openflow.c \
print-ospf.c \
print-ospf6.c \
print-otv.c \
print-pgm.c \
print-pim.c \
Expand All @@ -182,9 +190,11 @@ LIBNETDISSECT_SRC=\
print-radius.c \
print-raw.c \
print-rip.c \
print-ripng.c \
print-rpki-rtr.c \
print-rrcp.c \
print-rsvp.c \
print-rt6.c \
print-rtsp.c \
print-rx.c \
print-sctp.c \
Expand Down Expand Up @@ -218,6 +228,7 @@ LIBNETDISSECT_SRC=\
print-zephyr.c \
print-zeromq.c \
signature.c \
strtoaddr.c \
util-print.c

LOCALSRC = @LOCALSRC@
Expand All @@ -235,6 +246,7 @@ SRC = $(CSRC) $(GENSRC) $(LOCALSRC) $(LIBNETDISSECT_SRC)
OBJ = $(CSRC:.c=.o) $(GENSRC:.c=.o) $(LIBNETDISSECT_OBJ)
HDR = \
addrtoname.h \
addrtostr.h \
af.h \
ah.h \
appletalk.h \
Expand Down Expand Up @@ -275,6 +287,7 @@ HDR = \
signature.h \
slcompress.h \
smb.h \
strtoaddr.h \
tcp.h \
netdissect-stdinc.h \
timeval-operations.h \
Expand Down Expand Up @@ -319,14 +332,9 @@ EXTRA_DIST = \
lbl/os-sunos4.h \
lbl/os-ultrix4.h \
makemib \
missing/addrinfo.h \
missing/dlnames.c \
missing/datalinks.c \
missing/getnameinfo.c \
missing/getopt_long.c \
missing/inet_aton.c \
missing/inet_ntop.c \
missing/inet_pton.c \
missing/snprintf.c \
missing/strdup.c \
missing/strlcat.c \
Expand All @@ -335,16 +343,7 @@ EXTRA_DIST = \
mkdep \
packetdat.awk \
pcap_dump_ftell.c \
print-babel.c \
print-dhcp6.c \
print-frag6.c \
print-icmp6.c \
print-ip6opts.c \
print-mobility.c \
print-ospf6.c \
print-pflog.c \
print-ripng.c \
print-rt6.c \
print-smb.c \
send-ack.awk \
smbutil.c \
Expand Down Expand Up @@ -372,16 +371,8 @@ datalinks.o: $(srcdir)/missing/datalinks.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/datalinks.c
dlnames.o: $(srcdir)/missing/dlnames.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/dlnames.c
getnameinfo.o: $(srcdir)/missing/getnameinfo.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/getnameinfo.c
getopt_long.o: $(srcdir)/missing/getopt_long.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/getopt_long.c
inet_pton.o: $(srcdir)/missing/inet_pton.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/inet_pton.c
inet_ntop.o: $(srcdir)/missing/inet_ntop.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/inet_ntop.c
inet_aton.o: $(srcdir)/missing/inet_aton.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/inet_aton.c
snprintf.o: $(srcdir)/missing/snprintf.c
$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c
strdup.o: $(srcdir)/missing/strdup.c
Expand Down
125 changes: 0 additions & 125 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1149,131 +1149,6 @@ dnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
dnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dnl SUCH DAMAGE.

dnl
dnl Checks to see if AF_INET6 is defined
AC_DEFUN(AC_CHECK_AF_INET6, [
AC_MSG_CHECKING(for AF_INET6)
AC_CACHE_VAL($1,
AC_TRY_COMPILE([
# include <sys/types.h>
# include <sys/socket.h>],
[int a = AF_INET6],
$1=yes,
$1=no))
AC_MSG_RESULT($$1)
if test $$1 = yes ; then
AC_DEFINE(HAVE_AF_INET6)
fi
])

dnl
dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
dnl borrowed from LBL libpcap
AC_DEFUN(AC_CHECK_SA_LEN, [
AC_MSG_CHECKING(if sockaddr struct has sa_len member)
AC_CACHE_VAL($1,
AC_TRY_COMPILE([
# include <sys/types.h>
# include <sys/socket.h>],
[u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
$1=yes,
$1=no))
AC_MSG_RESULT($$1)
if test $$1 = yes ; then
AC_DEFINE(HAVE_SOCKADDR_SA_LEN)
fi
])

dnl
dnl Checks for addrinfo structure
AC_DEFUN(AC_STRUCT_ADDRINFO, [
AC_MSG_CHECKING(for addrinfo)
AC_CACHE_VAL($1,
AC_TRY_COMPILE([
# include <netdb.h>],
[struct addrinfo a],
$1=yes,
$1=no))
AC_MSG_RESULT($$1)
if test $$1 = yes; then
AC_DEFINE(HAVE_ADDRINFO, 1,
[define if you have the addrinfo function])
else
AC_DEFINE(NEED_ADDRINFO_H, 1,
[define if you need to include missing/addrinfo.h])
fi
])

dnl
dnl Checks for NI_MAXSERV
AC_DEFUN(AC_NI_MAXSERV, [
AC_MSG_CHECKING(for NI_MAXSERV)
AC_CACHE_VAL($1,
AC_EGREP_CPP(yes, [#include <netdb.h>
#ifdef NI_MAXSERV
yes
#endif],
$1=yes,
$1=no))
AC_MSG_RESULT($$1)
if test $$1 != yes; then
AC_DEFINE(NEED_ADDRINFO_H)
fi
])

dnl
dnl Checks for NI_NAMEREQD
AC_DEFUN(AC_NI_NAMEREQD, [
AC_MSG_CHECKING(for NI_NAMEREQD)
AC_CACHE_VAL($1,
AC_EGREP_CPP(yes, [#include <netdb.h>
#ifdef NI_NOFQDN
yes
#endif],
$1=yes,
$1=no))
AC_MSG_RESULT($$1)
if test $$1 != yes; then
AC_DEFINE(NEED_ADDRINFO_H)
fi
])

dnl
dnl Checks for sockaddr_storage structure
AC_DEFUN(AC_STRUCT_SA_STORAGE, [
AC_MSG_CHECKING(for sockaddr_storage)
AC_CACHE_VAL($1,
AC_TRY_COMPILE([
# include <sys/types.h>
# include <sys/socket.h>],
[struct sockaddr_storage s],
$1=yes,
$1=no))
AC_MSG_RESULT($$1)
if test $$1 = yes; then
AC_DEFINE(HAVE_SOCKADDR_STORAGE, 1,
[define if you have struct sockaddr_storage])
fi
])

dnl
dnl check for h_errno
AC_DEFUN(AC_VAR_H_ERRNO, [
AC_MSG_CHECKING(for h_errno)
AC_CACHE_VAL(ac_cv_var_h_errno,
AC_TRY_COMPILE([
# include <sys/types.h>
# include <netdb.h>],
[int foo = h_errno;],
ac_cv_var_h_errno=yes,
ac_cv_var_h_errno=no))
AC_MSG_RESULT($ac_cv_var_h_errno)
if test "$ac_cv_var_h_errno" = "yes"; then
AC_DEFINE(HAVE_H_ERRNO, 1,
[define if you have the h_errno variable])
fi
])

dnl
dnl Test for __attribute__
dnl
Expand Down
13 changes: 4 additions & 9 deletions addrtoname.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extern int ether_ntohost(char *, const struct ether_addr *);

#include "netdissect.h"
#include "addrtoname.h"
#include "addrtostr.h"
#include "llc.h"
#include "setsignal.h"
#include "extract.h"
Expand Down Expand Up @@ -89,7 +90,7 @@ static struct hnamemem eprototable[HASHNAMESIZE];
static struct hnamemem dnaddrtable[HASHNAMESIZE];
static struct hnamemem ipxsaptable[HASHNAMESIZE];

#if defined(INET6) && defined(_WIN32)
#ifdef _WIN32
/*
* fake gethostbyaddr for Win2k/XP
* gethostbyaddr() returns incorrect value when AF_INET6 is passed
Expand Down Expand Up @@ -127,17 +128,15 @@ win32_gethostbyaddr(const char *addr, int len, int type)
}
}
#define gethostbyaddr win32_gethostbyaddr
#endif /* INET6 & _WIN32 */
#endif /* _WIN32 */

#ifdef INET6
struct h6namemem {
struct in6_addr addr;
char *name;
struct h6namemem *nxt;
};

static struct h6namemem h6nametable[HASHNAMESIZE];
#endif /* INET6 */

struct enamemem {
u_short e_addr0;
Expand Down Expand Up @@ -265,7 +264,6 @@ getname(netdissect_options *ndo, const u_char *ap)
return (p->name);
}

#ifdef INET6
/*
* Return a name for the IP6 address pointed to by ap. This address
* is assumed to be in network byte order.
Expand Down Expand Up @@ -315,13 +313,12 @@ getname6(netdissect_options *ndo, const u_char *ap)
return (p->name);
}
}
cp = inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf));
cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
p->name = strdup(cp);
if (p->name == NULL)
(*ndo->ndo_error)(ndo, "getname6: strdup(cp)");
return (p->name);
}
#endif /* INET6 */

static const char hex[] = "0123456789abcdef";

Expand Down Expand Up @@ -1225,7 +1222,6 @@ newhnamemem(netdissect_options *ndo)
return (p);
}

#ifdef INET6
/* Return a zero'ed h6namemem struct and cuts down on calloc() overhead */
struct h6namemem *
newh6namemem(netdissect_options *ndo)
Expand All @@ -1244,7 +1240,6 @@ newh6namemem(netdissect_options *ndo)
p = ptr++;
return (p);
}
#endif /* INET6 */

/* Represent TCI part of the 802.1Q 4-octet tag as text. */
const char *
Expand Down
14 changes: 8 additions & 6 deletions addrtoname.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

/*
* Definitions to let us compile most of the IPv6 code even on systems
* without IPv6 support.
*/
#ifndef INET6_ADDRSTRLEN
#define INET6_ADDRSTRLEN 46
#endif

/* Name to address translation routines. */

enum {
Expand All @@ -41,19 +49,13 @@ extern const char *dnaddr_string(netdissect_options *, u_short);
extern const char *protoid_string(netdissect_options *, const u_char *);
extern const char *ipxsap_string(netdissect_options *, u_short);
extern const char *getname(netdissect_options *, const u_char *);
#ifdef INET6
extern const char *getname6(netdissect_options *, const u_char *);
#endif
extern const char *intoa(uint32_t);

extern void init_addrtoname(netdissect_options *, uint32_t, uint32_t);
extern struct hnamemem *newhnamemem(netdissect_options *);
#ifdef INET6
extern struct h6namemem *newh6namemem(netdissect_options *);
#endif
extern const char * ieee8021q_tci_string(const uint16_t);

#define ipaddr_string(ndo, p) getname(ndo, (const u_char *)(p))
#ifdef INET6
#define ip6addr_string(ndo, p) getname6(ndo, (const u_char *)(p))
#endif
Loading

0 comments on commit 11f73ad

Please sign in to comment.