diff --git a/Makefile.am b/Makefile.am index 5cf2e0274b..7bdd14f143 100644 --- a/Makefile.am +++ b/Makefile.am @@ -274,6 +274,7 @@ wireshark_LDADD = \ codecs/libcodec.a \ wiretap/libwiretap.la \ epan/libwireshark.la \ + @INET_PTON_LO@ \ @SNMP_LIBS@ @SSL_LIBS@ \ $(plugin_ldadd) \ @PCRE_LIBS@ \ @@ -294,6 +295,7 @@ tshark_LDADD = \ $(wireshark_optional_objects) \ wiretap/libwiretap.la \ epan/libwireshark.la \ + @INET_PTON_LO@ \ @SNMP_LIBS@ @SSL_LIBS@ \ $(plugin_ldadd) \ @PCRE_LIBS@ \ @@ -350,6 +352,7 @@ dftest_LDADD = \ # Libraries with which to link dumpcap. dumpcap_LDADD = \ wiretap/libwiretap.la \ + @INET_NTOP_LO@ \ @GLIB_LIBS@ \ @PCAP_LIBS@ @SOCKET_LIBS@ @NSL_LIBS@ \ @LIBGCRYPT_LIBS@ diff --git a/Makefile.common b/Makefile.common index 5358531d08..1ff0d2e0f9 100644 --- a/Makefile.common +++ b/Makefile.common @@ -123,6 +123,8 @@ TSHARK_TAP_SRC = \ # helpers already available on some platforms (and on others not) EXTRA_wireshark_SOURCES = \ getopt.c \ + inet_ntop.c \ + inet_pton.c \ mkstemp.c \ strerror.c \ strcasecmp.c \ @@ -132,6 +134,7 @@ EXTRA_wireshark_SOURCES = \ # corresponding headers EXTRA_wireshark_INCLUDES = \ getopt.h \ + inet_v6defs.h \ mkstemp.h \ strerror.h \ strptime.h diff --git a/Makefile.nmake b/Makefile.nmake index 42ad6dbfd8..db69f89287 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -35,6 +35,9 @@ dumpcap_OBJECTS = $(dumpcap_SOURCES:.c=.obj) randpkt_OBJECTS = $(randpkt_SOURCES:.c=.obj) EXTRA_OBJECTS = \ + getopt.obj \ + inet_ntop.obj \ + inet_pton.obj \ mkstemp.obj \ strptime.obj @@ -182,10 +185,10 @@ wiretap\wiretap-$(WTAP_VERSION).lib: image $(ZLIB_DIR)\zlib1.dll wiretap !IFNDEF GTK1_DIR wireshark.exe : !ELSE -wireshark.exe : config.h svnversion.h $(wireshark_OBJECTS) getopt.obj codecs epan gtk image\wireshark.res wiretap\wiretap-$(WTAP_VERSION).lib codecs\codecs.lib gtk\libui.lib plugins +wireshark.exe : config.h svnversion.h $(wireshark_OBJECTS) getopt.obj inet_ntop.obj inet_pton.obj codecs epan gtk image\wireshark.res wiretap\wiretap-$(WTAP_VERSION).lib codecs\codecs.lib gtk\libui.lib plugins @echo Linking $@ $(LINK) @<< - /OUT:wireshark.exe $(guiflags) $(guilibsdll) $(LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:windows $(wireshark_LIBS) getopt.obj $(GTK1_LIBS) codecs\codecs.lib gtk\libui.lib $(wireshark_OBJECTS) image\wireshark.res + /OUT:wireshark.exe $(guiflags) $(guilibsdll) $(LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:windows $(wireshark_LIBS) getopt.obj inet_ntop.obj inet_pton.obj $(GTK1_LIBS) codecs\codecs.lib gtk\libui.lib $(wireshark_OBJECTS) image\wireshark.res << !IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20" mt.exe -nologo -manifest "wireshark.exe.manifest" -outputresource:wireshark.exe;1 @@ -195,20 +198,20 @@ wireshark.exe : config.h svnversion.h $(wireshark_OBJECTS) getopt.obj codecs epa !IFNDEF GTK2_DIR wireshark-gtk2.exe : !ELSE -wireshark-gtk2.exe : config.h svnversion.h $(wireshark_OBJECTS) getopt.obj codecs epan gtk2 image\wireshark.res wiretap\wiretap-$(WTAP_VERSION).lib codecs\codecs.lib gtk2.tmp\libui.lib plugins +wireshark-gtk2.exe : config.h svnversion.h $(wireshark_OBJECTS) getopt.obj inet_ntop.obj inet_pton.obj codecs epan gtk2 image\wireshark.res wiretap\wiretap-$(WTAP_VERSION).lib codecs\codecs.lib gtk2.tmp\libui.lib plugins @echo Linking $@ $(LINK) @<< - /OUT:wireshark-gtk2.exe $(guiflags) $(guilibsdll) $(LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:windows $(wireshark_LIBS) getopt.obj $(GTK2_LIBS) codecs\codecs.lib gtk2.tmp\libui.lib $(wireshark_OBJECTS) image\wireshark.res + /OUT:wireshark-gtk2.exe $(guiflags) $(guilibsdll) $(LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:windows $(wireshark_LIBS) getopt.obj inet_ntop.obj inet_pton.obj $(GTK2_LIBS) codecs\codecs.lib gtk2.tmp\libui.lib $(wireshark_OBJECTS) image\wireshark.res << !IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20" mt.exe -nologo -manifest "wireshark-gtk2.exe.manifest" -outputresource:wireshark-gtk2.exe;1 !ENDIF !ENDIF -tshark.exe : config.h svnversion.h $(tshark_OBJECTS) getopt.obj epan image\tshark.res wiretap\wiretap-$(WTAP_VERSION).lib plugins +tshark.exe : config.h svnversion.h $(tshark_OBJECTS) getopt.obj inet_ntop.obj epan image\tshark.res wiretap\wiretap-$(WTAP_VERSION).lib plugins @echo Linking $@ $(LINK) @<< - /OUT:tshark.exe $(conflags) $(conlibsdll) $(LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:console $(tshark_LIBS) $(tshark_OBJECTS) getopt.obj image\tshark.res + /OUT:tshark.exe $(conflags) $(conlibsdll) $(LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:console $(tshark_LIBS) $(tshark_OBJECTS) getopt.obj inet_ntop.obj image\tshark.res << !IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20" mt.exe -nologo -manifest "tshark.exe.manifest" -outputresource:tshark.exe;1 @@ -268,10 +271,10 @@ randpkt.exe : $(randpkt_OBJECTS) getopt.obj mt.exe -nologo -manifest "randpkt.exe.manifest" -outputresource:randpkt.exe;1 !ENDIF -dumpcap.exe : config.h svnversion.h $(dumpcap_OBJECTS) getopt.obj mkstemp.obj wiretap\wiretap-$(WTAP_VERSION).lib image\dumpcap.res +dumpcap.exe : config.h svnversion.h $(dumpcap_OBJECTS) getopt.obj inet_ntop.obj mkstemp.obj wiretap\wiretap-$(WTAP_VERSION).lib image\dumpcap.res @echo Linking $@ $(LINK) @<< - /OUT:dumpcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console $(dumpcap_LIBS) $(dumpcap_OBJECTS) getopt.obj mkstemp.obj image\dumpcap.res + /OUT:dumpcap.exe $(conflags) $(conlibsdll) $(LDFLAGS) /SUBSYSTEM:console $(dumpcap_LIBS) $(dumpcap_OBJECTS) getopt.obj inet_ntop.obj mkstemp.obj image\dumpcap.res << !IF "$(MSVC_VARIANT)" == "MSVC2005" || "$(MSVC_VARIANT)" == "MSVC2005EE" || "$(MSVC_VARIANT)" == "DOTNET20" mt.exe -nologo -manifest "dumpcap.exe.manifest" -outputresource:dumpcap.exe;1 @@ -360,7 +363,7 @@ clean_gtk2.tmp: clean: clean_gtk2.tmp clean-deps rm -f $(wireshark_OBJECTS) $(tshark_OBJECTS) $(EXTRA_OBJECTS) \ $(EXECUTABLES) *.pdb *.exe.manifest \ - capinfos.obj editcap.obj mergecap.obj text2pcap.obj getopt.obj\ + capinfos.obj editcap.obj mergecap.obj text2pcap.obj \ text2pcap-scanner.obj text2pcap-scanner.c rdps.obj \ rdps.pdb rdps.exe rdps.ilk config.h ps.c AUTHORS-SHORT \ AUTHORS-SHORT-FORMAT \ diff --git a/capture.c b/capture.c index c0e918a70a..d18b1d81cb 100644 --- a/capture.c +++ b/capture.c @@ -48,8 +48,20 @@ #include #endif -#ifdef HAVE_NETDB_H -#include +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#ifdef HAVE_SYS_SOCKET_H +#include /* needed to define AF_ values on UNIX */ +#endif + +#ifdef HAVE_WINSOCK2_H +#include /* needed to define AF_ values on Windows */ +#endif + +#ifdef NEED_INET_V6DEFS_H +# include "inet_v6defs.h" #endif #include @@ -594,9 +606,6 @@ capture_interface_list(int *err, char **err_str) gchar *name; if_info_t *if_info; if_addr_t *if_addr; - struct addrinfo *ai; - struct sockaddr_in *sa4; - struct sockaddr_in6 *sa6; g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface List ..."); @@ -642,27 +651,18 @@ capture_interface_list(int *err, char **err_str) if_info->description = g_strdup(if_parts[1]); addr_parts = g_strsplit(if_parts[2], ",", 0); for (j = 0; addr_parts[j] != NULL; j++) { - /* XXX - We're failing to convert IPv6 addresses (on Ubuntu, at least) */ - if (getaddrinfo(addr_parts[j], NULL, NULL, &ai) == 0) { + if_addr = g_malloc0(sizeof(if_addr_t)); + if (inet_pton(AF_INET, addr_parts[j], &if_addr->ip_addr.ip4_addr)) { + if_addr->type = AT_IPv4; + } else if (inet_pton(AF_INET6, addr_parts[j], + &if_addr->ip_addr.ip6_addr)) { + if_addr->type = AT_IPv6; + } else { + g_free(if_addr); if_addr = NULL; - switch (ai->ai_family) { - case AF_INET: - if_addr = g_malloc0(sizeof(if_addr_t)); - if_addr->type = AT_IPv4; - sa4 = (struct sockaddr_in *) ai->ai_addr; - if_addr->ip_addr.ip4_addr = sa4->sin_addr.s_addr; - break; - case AF_INET6: - if_addr = g_malloc0(sizeof(if_addr_t)); - if_addr->type = AT_IPv6; - sa6 = (struct sockaddr_in6 *) ai->ai_addr; - memcpy(&if_addr->ip_addr.ip6_addr, sa6->sin6_addr.s6_addr, 16); - break; - } - if (if_addr) { - if_info->ip_addr = g_slist_append(if_info->ip_addr, if_addr); - } - freeaddrinfo(ai); + } + if (if_addr) { + if_info->ip_addr = g_slist_append(if_info->ip_addr, if_addr); } } if (strcmp(if_parts[3], "loopback") == 0) diff --git a/capture_opts.c b/capture_opts.c index e3005cea0e..c33d8f1eb7 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -31,8 +31,20 @@ #include #include -#ifdef HAVE_NETDB_H -#include +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#ifdef HAVE_SYS_SOCKET_H +#include /* needed to define AF_ values on UNIX */ +#endif + +#ifdef HAVE_WINSOCK2_H +#include /* needed to define AF_ values on Windows */ +#endif + +#ifdef NEED_INET_V6DEFS_H +# include "inet_v6defs.h" #endif #include @@ -430,6 +442,7 @@ int capture_opts_list_link_layer_types(capture_options *capture_opts) } /* Return an ASCII-formatted list of interfaces. */ +#define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */ int capture_opts_list_interfaces(gboolean verbose) { @@ -441,9 +454,7 @@ capture_opts_list_interfaces(gboolean verbose) int i; GSList *ip_addr; if_addr_t *if_addr; - char addr_str[NI_MAXHOST]; - struct sockaddr_in sa4; - struct sockaddr_in6 sa6; + char addr_str[ADDRSTRLEN]; if_list = get_interface_list(&err, &err_str); if (if_list == NULL) { @@ -490,20 +501,16 @@ capture_opts_list_interfaces(gboolean verbose) if_addr = ip_addr->data; switch(if_addr->type) { case AT_IPv4: - sa4.sin_family = AF_INET; - sa4.sin_addr.s_addr = if_addr->ip_addr.ip4_addr; - if (getnameinfo((struct sockaddr *) &sa4, sizeof(sa4), - addr_str, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) { + if (inet_ntop(AF_INET, &if_addr->ip_addr.ip4_addr, addr_str, + ADDRSTRLEN)) { printf(addr_str); } else { printf(""); } break; case AT_IPv6: - sa6.sin6_family = AF_INET6; - memcpy(&sa6.sin6_addr.s6_addr, &if_addr->ip_addr.ip6_addr, 16); - if (getnameinfo((struct sockaddr *) &sa6, sizeof(sa6), - addr_str, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == 0) { + if (inet_ntop(AF_INET6, &if_addr->ip_addr.ip6_addr, + addr_str, ADDRSTRLEN)) { printf(addr_str); } else { printf(""); diff --git a/epan/Makefile.nmake b/epan/Makefile.nmake index 26f36526bb..7233a26e49 100644 --- a/epan/Makefile.nmake +++ b/epan/Makefile.nmake @@ -128,6 +128,7 @@ clean: # distclean: clean rm -f config.h register.c mkstemp.c strptime.c \ + inet_ntop.c inet_pton.c \ $(LIBWIRESHARK_DISTCLEAN_GENERATED_SRC) \ $(LIBWIRESHARK_NODISTCLEAN_GENERATED_SRC) \ dtd_grammar.out dtd_grammar.h sminmpec.c @@ -249,6 +250,12 @@ mkstemp.c: ..\mkstemp.c strptime.c: ..\strptime.c xcopy ..\strptime.c . /d +inet_ntop.c: ..\inet_ntop.c + xcopy ..\inet_ntop.c . /d + +inet_pton.c: ..\inet_pton.c + xcopy ..\inet_pton.c . /d + radius_dict.c : radius_dict.l $(LEX) radius_dict.l diff --git a/epan/inet_ntop.c b/inet_ntop.c similarity index 100% rename from epan/inet_ntop.c rename to inet_ntop.c diff --git a/epan/inet_pton.c b/inet_pton.c similarity index 100% rename from epan/inet_pton.c rename to inet_pton.c diff --git a/epan/inet_v6defs.h b/inet_v6defs.h similarity index 100% rename from epan/inet_v6defs.h rename to inet_v6defs.h