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.
This commit is contained in:
Anthony Baxter 2003-05-02 15:40:46 +00:00
parent 6dc4a8e3fb
commit 0e85f9d6fd
1 changed files with 16 additions and 0 deletions

View File

@ -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);