]> The Tcpdump Group git mirrors - tcpdump/commitdiff
last resort functions for inet_{aton,pton,ntop}.
authoritojun <itojun>
Sat, 30 Oct 1999 07:53:37 +0000 (07:53 +0000)
committeritojun <itojun>
Sat, 30 Oct 1999 07:53:37 +0000 (07:53 +0000)
only works for IPv4-only build.

Makefile.in
configure
configure.in
missing/getaddrinfo.c
missing/inet_aton.c [new file with mode: 0644]
missing/inet_ntop.c [new file with mode: 0644]
missing/inet_pton.c [new file with mode: 0644]

index 228f0820322ba48560d901dcb8f8445d47c73e98..a7f9b49aa0b7f3b2ffa959c7d79d66e0421c58d6 100644 (file)
@@ -17,7 +17,7 @@
 #  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 #
-# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.211 1999-10-30 07:36:34 itojun Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.212 1999-10-30 07:53:37 itojun Exp $ (LBL)
 
 #
 # Various configurable paths (remember to edit Makefile.in, not Makefile)
@@ -116,6 +116,12 @@ getnameinfo.o: $(srcdir)/missing/getnameinfo.c
        $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/getnameinfo.c
 getaddrinfo.o: $(srcdir)/missing/getaddrinfo.c
        $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/getaddrinfo.c
+inet_pton.o: $(srcdir)/missing/inet_pton.c
+       $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/inet_pton.c
+inet_ntop.o: $(srcdir)/missing/inet_ntop.c
+       $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/inet_ntop.c
+inet_aton.o: $(srcdir)/missing/inet_aton.c
+       $(CC) $(CFLAGS) -o $@ -c $(srcdir)/missing/inet_aton.c
 
 version.o: version.c
        $(CC) $(CFLAGS) -c version.c
index be4a5be7c74ba2cdd90425973ecbfa774b227d2a..41faef33c83eb87b9d38ef5827eeea0ead84aca5 100755 (executable)
--- a/configure
+++ b/configure
@@ -1662,7 +1662,7 @@ if test "$buggygetaddrinfo" = "yes"; then
                echo '         of GNU C library (aka glibc).'
        fi
 fi
-for ac_func in getaddrinfo getnameinfo
+for ac_func in getaddrinfo getnameinfo inet_ntop inet_pton inet_aton
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:1669: checking for $ac_func" >&5
index 06c0afddf26ead1fb5da4d010de1998a993c8e47..ffef6da6df49de817d1a00a7227a6732170bd9f4 100644 (file)
@@ -1,4 +1,4 @@
-dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.77 1999-10-30 07:45:38 itojun Exp $ (LBL)
+dnl @(#) $Header: /tcpdump/master/tcpdump/configure.in,v 1.78 1999-10-30 07:53:38 itojun Exp $ (LBL)
 dnl
 dnl Copyright (c) 1994, 1995, 1996, 1997
 dnl    The Regents of the University of California.  All rights reserved.
@@ -299,7 +299,7 @@ if test "$buggygetaddrinfo" = "yes"; then
                echo '         of GNU C library (aka glibc).'
        fi
 fi
-AC_REPLACE_FUNCS(getaddrinfo getnameinfo)
+AC_REPLACE_FUNCS(getaddrinfo getnameinfo inet_ntop inet_pton inet_aton)
 
 dnl portability macros for getaddrinfo/getnameinfo
 dnl
index 59568c2ccb8f78e9754f8f81dc9c1a16445f3546..cdbd9e8aa2d1ed78559a280b080aa7aaf47da22b 100644 (file)
@@ -60,6 +60,7 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <errno.h>
 
 #ifndef HAVE_PORTABLE_PROTOTYPE
 #include "cdecl_ext.h"
@@ -364,11 +365,18 @@ getaddrinfo(hostname, servname, hints, res)
         * for raw and other inet{,6} sockets.
         */
        if (MATCH_FAMILY(pai->ai_family, PF_INET, 1)
-        || MATCH_FAMILY(pai->ai_family, PF_INET6, 1)) {
+#ifdef PF_INET6
+        || MATCH_FAMILY(pai->ai_family, PF_INET6, 1)
+#endif
+           ) {
                ai0 = *pai;
 
                if (pai->ai_family == PF_UNSPEC)
+#ifdef PF_INET6
                        pai->ai_family = PF_INET6;
+#else
+                       pai->ai_family = PF_INET;
+#endif
                error = get_portmatch(pai, servname);
                if (error)
                        ERR(error);
@@ -529,9 +537,14 @@ explore_fqdn(pai, hostname, servname, res)
 
 #ifdef USE_GETIPNODEBY
        hp = getipnodebyname(hostname, pai->ai_family, AI_ADDRCONFIG, &h_error);
-#else
+#elif defined(HAVE_GETHOSTBYNAME2)
        hp = gethostbyname2(hostname, pai->ai_family);
        h_error = h_errno;
+#else
+       if (pai->ai_family != AF_INET)
+               return 0;
+       hp = gethostbyname(hostname);
+       h_error = h_errno;
 #endif
 
        if (hp == NULL) {
@@ -943,7 +956,11 @@ get_port(ai, servname, matchonly)
 
        if (servname == NULL)
                return 0;
-       if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
+       if (ai->ai_family != AF_INET
+#ifdef AF_INET6
+           && ai->ai_family != AF_INET6
+#endif
+           )
                return 0;
 
        switch (ai->ai_socktype) {
diff --git a/missing/inet_aton.c b/missing/inet_aton.c
new file mode 100644 (file)
index 0000000..8be3011
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the Kungliga Tekniska
+ *      Högskolan and its contributors.
+ * 
+ * 4. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $Id: inet_aton.c,v 1.1 1999-10-30 07:53:39 itojun Exp $ */
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+
+/* Minimal implementation of inet_aton.
+ * Cannot distinguish between failure and a local broadcast address. */
+
+#ifndef INADDR_NONE
+#define INADDR_NONE 0xffffffff
+#endif
+
+int
+inet_aton(const char *cp, struct in_addr *addr)
+{
+  addr->s_addr = inet_addr(cp);
+  return (addr->s_addr == INADDR_NONE) ? 0 : 1;
+}
diff --git a/missing/inet_ntop.c b/missing/inet_ntop.c
new file mode 100644 (file)
index 0000000..ce6ecaa
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 1999 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the Kungliga Tekniska
+ *      Högskolan and its contributors.
+ * 
+ * 4. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $Id: inet_ntop.c,v 1.1 1999-10-30 07:53:39 itojun Exp $ */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+/*
+ *
+ */
+
+#ifndef INET_ADDRSTRLEN
+#define INET_ADDRSTRLEN    16
+#endif
+
+static const char *
+inet_ntop_v4 (const void *src, char *dst, size_t size)
+{
+    const char digits[] = "0123456789";
+    int i;
+    struct in_addr *addr = (struct in_addr *)src;
+    u_long a = ntohl(addr->s_addr);
+    const char *orig_dst = dst;
+
+    if (size < INET_ADDRSTRLEN) {
+       errno = ENOSPC;
+       return NULL;
+    }
+    for (i = 0; i < 4; ++i) {
+       int n = (a >> (24 - i * 8)) & 0xFF;
+       int non_zerop = 0;
+
+       if (non_zerop || n / 100 > 0) {
+           *dst++ = digits[n / 100];
+           n %= 100;
+           non_zerop = 1;
+       }
+       if (non_zerop || n / 10 > 0) {
+           *dst++ = digits[n / 10];
+           n %= 10;
+           non_zerop = 1;
+       }
+       *dst++ = digits[n];
+       if (i != 3)
+           *dst++ = '.';
+    }
+    *dst++ = '\0';
+    return orig_dst;
+}
+
+const char *
+inet_ntop(int af, const void *src, char *dst, size_t size)
+{
+    switch (af) {
+    case AF_INET :
+       return inet_ntop_v4 (src, dst, size);
+    default :
+       errno = EAFNOSUPPORT;
+       return NULL;
+    }
+}
diff --git a/missing/inet_pton.c b/missing/inet_pton.c
new file mode 100644 (file)
index 0000000..c62bdcd
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 1999 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the Kungliga Tekniska
+ *      Högskolan and its contributors.
+ * 
+ * 4. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* $Id: inet_pton.c,v 1.1 1999-10-30 07:53:39 itojun Exp $ */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+int
+inet_pton(int af, const char *src, void *dst)
+{
+    if (af != AF_INET) {
+       errno = EAFNOSUPPORT;
+       return -1;
+    }
+    return inet_aton (src, dst);
+}