[Python-checkins] CVS: python/dist/src/Modules socketmodule.c,1.145,1.146
Martin v. L?wis
loewis@users.sourceforge.net
Sun, 24 Jun 2001 14:18:28 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv18169/Modules
Modified Files:
socketmodule.c
Log Message:
Emulate inet_{pton,ntop} on systems that don't provide it.
Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.145
retrieving revision 1.146
diff -C2 -r1.145 -r1.146
*** socketmodule.c 2001/06/24 05:08:52 1.145
--- socketmodule.c 2001/06/24 21:18:26 1.146
***************
*** 209,212 ****
--- 209,217 ----
#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
***************
*** 2944,2945 ****
--- 2949,2986 ----
#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