summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAnthony Baxter <anthonybaxter@gmail.com>2003-05-02 15:40:46 (GMT)
committerAnthony Baxter <anthonybaxter@gmail.com>2003-05-02 15:40:46 (GMT)
commit0e85f9d6fdabd4eb4d03424cb1847f8f05ac9cc9 (patch)
tree619e19c50b6be55764224d88a2d0f4b9b1c882b1 /Modules
parent6dc4a8e3fb7c9b290ee867f167af1395643705a1 (diff)
downloadcpython-0e85f9d6fdabd4eb4d03424cb1847f8f05ac9cc9.zip
cpython-0e85f9d6fdabd4eb4d03424cb1847f8f05ac9cc9.tar.gz
cpython-0e85f9d6fdabd4eb4d03424cb1847f8f05ac9cc9.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index b9e9bd4..843c5a9 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -626,6 +626,8 @@ setipaddr(char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int af)
{
struct addrinfo hints, *res;
int error;
+ int d1, d2, d3, d4;
+ char ch;
memset((void *) addr_ret, '\0', sizeof(*addr_ret));
if (name[0] == '\0') {
@@ -682,6 +684,20 @@ setipaddr(char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int af)
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));
hints.ai_family = af;
error = getaddrinfo(name, NULL, &hints, &res);