diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/socketmodule.c | 16 |
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); |