]> granicus.if.org Git - python/commitdiff
Emulate inet_{pton,ntop} on systems that don't provide it.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 24 Jun 2001 21:18:26 +0000 (21:18 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 24 Jun 2001 21:18:26 +0000 (21:18 +0000)
Modules/socketmodule.c
config.h.in
configure
configure.in

index c3f03b105109b851de23af99bf98a9053d1de37e..507e6aa5c1c098fffcd802951c6e3ad155515695 100644 (file)
@@ -208,6 +208,11 @@ Socket methods:
    in those files, though, which will never compile on Windows. */
 #ifndef MS_WINDOWS
 
+#ifndef HAVE_INET_PTON
+int inet_pton (int af, const char *src, void *dst);
+char *inet_ntop(int af, void *src, char *dst, socklen_t size);
+#endif
+
 /* I know this is a bad practice, but it is the easiest... */
 #ifndef HAVE_GETADDRINFO
 #include "getaddrinfo.c"
@@ -2943,3 +2948,39 @@ init_socket(void)
        gethostbyname_lock = PyThread_allocate_lock();
 #endif
 }
+
+/* Simplistic emulation code for inet_pton that only works for IPv4 */
+#ifndef HAVE_INET_PTON
+int my_inet_pton (int af, char *src, void *dst)
+{
+       if(af == AF_INET){
+               long packed_addr;
+#ifdef USE_GUSI1
+               packed_addr = (long)inet_addr(src).s_addr;
+#else
+               packed_addr = inet_addr(src);
+#endif
+               if (packed_addr == INADDR_NONE)
+                       return 0;
+               memcpy(dst, &packed_addr, 4);
+               return 1;
+       }
+       /* Should set errno to EAFNOSUPPORT */
+       return -1;
+}
+
+char *
+my_inet_ntop(int af, void *src, char *dst, socklen_t size)
+{
+       if (af == AF_INET) {
+               struct in_addr packed_addr;
+               if (size < 16)
+                       /* Should set errno to ENOSPC. */
+                       return NULL;
+               memcpy(&packed_addr, src, sizeof(packed_addr));
+               return strncpy(dst, inet_ntoa(packed_addr), size);
+       }
+       /* Should set errno to EAFNOSUPPORT */
+       return NULL;
+}
+#endif
index 2fd7ed765e999973d1beeb579d4711adb2a65a9a..af3c8151fa4e6e2195c5cec5620c91b23c95595c 100644 (file)
 /* Define if you have the hypot function.  */
 #undef HAVE_HYPOT
 
+/* Define if you have the inet_pton function.  */
+#undef HAVE_INET_PTON
+
 /* Define if you have the kill function.  */
 #undef HAVE_KILL
 
index 0e7ac3b6b9616a1830ec525819683e76102b1ef2..a4ac8d94a2628d5a2e9a30cc2be311413d2423d8 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# From configure.in Revision: 1.219 
+# From configure.in Revision: 1.220 
 
 # Guess values for system-dependent variables and create Makefiles.
 # Generated automatically using autoconf version 2.13 
@@ -4480,7 +4480,7 @@ echo "$ac_t""$DYNLOADFILE" 1>&6
 for ac_func in alarm chown clock confstr ctermid ctermid_r execv \
  flock fork fsync fdatasync fpathconf ftime ftruncate \
  getgroups getlogin getpeername getpid getpwent getwd \
- kill link lstat mkfifo mktime mremap \
inet_pton kill link lstat mkfifo mktime mremap \
  nice pathconf pause plock poll pthread_init \
  putenv readlink \
  select setegid seteuid setgid \
index 8ced0d0e875cd70b62e1a5405deedbd0136bf382..27133360f4c52b350bb75e4631c97c14614587ca 100644 (file)
@@ -1162,7 +1162,7 @@ AC_MSG_RESULT($DYNLOADFILE)
 AC_CHECK_FUNCS(alarm chown clock confstr ctermid ctermid_r execv \
  flock fork fsync fdatasync fpathconf ftime ftruncate \
  getgroups getlogin getpeername getpid getpwent getwd \
- kill link lstat mkfifo mktime mremap \
inet_pton kill link lstat mkfifo mktime mremap \
  nice pathconf pause plock poll pthread_init \
  putenv readlink \
  select setegid seteuid setgid \