[Python-checkins] python/dist/src/Modules socketmodule.c,1.252,1.253

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 12 Feb 2003 15:08:25 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv5865

Modified Files:
	socketmodule.c 
Log Message:
Addressing SF bug #643005, implement socket.inet_aton() using
inet_aton() rather than inet_addr() -- the latter is obsolete because
it has a problem: "255.255.255.255" is a valid address but
indistinguishable from an error.

(I'm not sure if inet_aton() exists everywhere -- in case it doesn't,
I've left the old code in with an #ifdef.)


Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.252
retrieving revision 1.253
diff -C2 -d -r1.252 -r1.253
*** socketmodule.c	31 Jan 2003 18:15:58 -0000	1.252
--- socketmodule.c	12 Feb 2003 23:08:22 -0000	1.253
***************
*** 2714,2722 ****
  	/* Have to use inet_addr() instead */
  	char *ip_addr;
! 	unsigned long packed_addr;
  
  	if (!PyArg_ParseTuple(args, "s:inet_aton", &ip_addr)) {
  		return NULL;
  	}
  	packed_addr = inet_addr(ip_addr);
  
--- 2714,2737 ----
  	/* Have to use inet_addr() instead */
  	char *ip_addr;
! #if 1
! 	struct in_addr buf;
  
  	if (!PyArg_ParseTuple(args, "s:inet_aton", &ip_addr)) {
  		return NULL;
  	}
+ 
+ 	if (inet_aton(ip_addr, &buf))
+ 		return PyString_FromStringAndSize((char *)(&buf),
+ 						  sizeof(buf));
+ 
+ 	PyErr_SetString(socket_error,
+ 			"illegal IP address string passed to inet_aton");
+ 	return NULL;
+ 
+ #else /* In case you don't have inet_aton() */
+ 	/* XXX Problem here: inet_aton('255.255.255.255') raises
+ 	   an exception while it should be a valid address. */
+ 	unsigned long packed_addr;
+ 
  	packed_addr = inet_addr(ip_addr);
  
***************
*** 2729,2732 ****
--- 2744,2748 ----
  	return PyString_FromStringAndSize((char *) &packed_addr,
  					  sizeof(packed_addr));
+ #endif
  }