[Python-checkins] python/dist/src/Modules socketmodule.c,1.261,1.262

anthonybaxter@users.sourceforge.net anthonybaxter@users.sourceforge.net
Fri, 02 May 2003 08:40:53 -0700


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

Modified Files:
	socketmodule.c 
Log Message:
Patch 731209: Restore socketmodule's behaviour with dotted quad addresses 
to that of Python2.1. Such nnn.nnn.nnn.nnn addresses are just used directly,
not passed to the resolver for a pointless lookup.


Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.261
retrieving revision 1.262
diff -C2 -d -r1.261 -r1.262
*** socketmodule.c	1 May 2003 05:20:46 -0000	1.261
--- socketmodule.c	2 May 2003 15:40:46 -0000	1.262
***************
*** 627,630 ****
--- 627,632 ----
  	struct addrinfo hints, *res;
  	int error;
+ 	int d1, d2, d3, d4;
+ 	char ch;
  
  	memset((void *) addr_ret, '\0', sizeof(*addr_ret));
***************
*** 682,685 ****
--- 684,701 ----
  		sin->sin_addr.s_addr = INADDR_BROADCAST;
  		return sizeof(sin->sin_addr);
+ 	}
+ 	if (sscanf(name, "%d.%d.%d.%d%c", &d1, &d2, &d3, &d4, &ch) == 4 &&
+ 	    0 <= d1 && d1 <= 255 && 0 <= d2 && d2 <= 255 &&
+ 	    0 <= d3 && d3 <= 255 && 0 <= d4 && d4 <= 255) {
+ 		struct sockaddr_in *sin;
+ 		sin = (struct sockaddr_in *)addr_ret;
+ 		sin->sin_addr.s_addr = htonl(
+ 			((long) d1 << 24) | ((long) d2 << 16) |
+ 			((long) d3 << 8) | ((long) d4 << 0));
+ 		sin->sin_family = AF_INET;
+ #ifdef HAVE_SOCKADDR_SA_LEN
+ 		sin->sin_len = sizeof(*sin);
+ #endif
+ 		return 4;
  	}
  	memset(&hints, 0, sizeof(hints));