Fix compilation under VS6 (hopefully without breaking compilation
authorGerald Combs <gerald@wireshark.org>
Mon, 11 Jun 2007 18:26:09 +0000 (18:26 -0000)
committerGerald Combs <gerald@wireshark.org>
Mon, 11 Jun 2007 18:26:09 +0000 (18:26 -0000)
anywhere else).  Instead of using getaddrinfo() and getnameinfo(),
promote inet_pton.c and inet_ntop.c to the top level and use those
routines instead.

(It's 2007, for crying out loud.  Why is this even an issue?)

svn path=/trunk/; revision=22075

Makefile.am
Makefile.common
Makefile.nmake
capture.c
capture_opts.c
epan/Makefile.nmake
inet_ntop.c [moved from epan/inet_ntop.c with 100% similarity]
inet_pton.c [moved from epan/inet_pton.c with 100% similarity]
inet_v6defs.h [moved from epan/inet_v6defs.h with 100% similarity]

index 5cf2e0274bf26900508a20b0f4b6ee3ebf6fcd63..7bdd14f143f1e18431f39e46edd41f1008c9fde1 100644 (file)
@@ -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@
index 5358531d08e0ded909c27917e8b11d8cb337363d..1ff0d2e0f941a20bf5cb59e8975002cb22fd8ac3 100644 (file)
@@ -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
index 42ad6dbfd82df611f6bd0ab56d02dc3bacddf7dd..db69f892875d2619df68c128d2026407cd17f83a 100644 (file)
@@ -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 \
index c0e918a70a6739b57465756bacd0caa68c2f2f0e..d18b1d81cb843a1ff7429dc56bc1c29155e48c5e 100644 (file)
--- a/capture.c
+++ b/capture.c
 #include <sys/socket.h>
 #endif
 
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>         /* needed to define AF_ values on UNIX */
+#endif
+
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>           /* needed to define AF_ values on Windows */
+#endif
+
+#ifdef NEED_INET_V6DEFS_H
+# include "inet_v6defs.h"
 #endif
 
 #include <signal.h>
@@ -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)
index e3005cea0e7ad60808e3f23e50a7af6735d6f013..c33d8f1eb756a70b273cc22719928faa1b344a77 100644 (file)
 #include <string.h>
 #include <ctype.h>
 
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>         /* needed to define AF_ values on UNIX */
+#endif
+
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>           /* needed to define AF_ values on Windows */
+#endif
+
+#ifdef NEED_INET_V6DEFS_H
+# include "inet_v6defs.h"
 #endif
 
 #include <glib.h>
@@ -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("<unknown IPv4>");
                     }
                     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("<unknown IPv6>");
index 26f36526bb63f8ec15a1abe258e0ef26fa9c3d2c..7233a26e493492829bd060ade48d1b2dcc9e38f8 100644 (file)
@@ -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
 
similarity index 100%
rename from epan/inet_ntop.c
rename to inet_ntop.c
similarity index 100%
rename from epan/inet_pton.c
rename to inet_pton.c
similarity index 100%
rename from epan/inet_v6defs.h
rename to inet_v6defs.h