[issue27612] socket.gethostbyname resolving octal IP addresses incorrectly
Matt Robenolt
report at bugs.python.org
Mon Jul 25 11:22:37 EDT 2016
Matt Robenolt added the comment:
Sorry, to add a data point, in C, `gethostbyname` also does the correct thing on macOS.
See:
```
#include <stdio.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[]) {
int i;
struct hostent *lh = gethostbyname("0177.0000.0000.0001");
struct in_addr **addr_list;
if (lh) {
addr_list = (struct in_addr **)lh->h_addr_list;
for (i=0; addr_list[i] != NULL; i++) {
printf("%s", inet_ntoa(*addr_list[i]));
}
printf("\n");
} else {
herror("gethostbyname");
}
return 0;
}
```
So I'm not sure this is platform specific.
Either way, `socket.gethostbyname` is wrong on both linux and macOS. I'm a bit lost with what's going on here though, admittedly. :)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27612>
_______________________________________
More information about the Python-bugs-list
mailing list