Closed GoogleCodeExporter closed 9 years ago
Ok, here's a small file which implements inet_ntop only, and should return the
same results as socket.inet_ntop on unix.
Best to only use it if necessary, I guess by checking hasattr(socket,
'inet_ntop')?
Original comment by mike.auty@gmail.com
on 5 Feb 2011 at 4:54
Attachments:
Original comment by mike.auty@gmail.com
on 5 Feb 2011 at 4:55
This looks good Mike. So here I've attached a patched version of netscan.py
which imports your inet_ntop if socket.inet_ntop causes an AttributeError. I'm
not sure if you want to leave inet_ntop.py as a separate file or just copy the
function into netscan.py - up to you.
Also, a friend helped me write another platform-independent version of
inet_ntop so we have some benchmarking tools.
Run on a Linux/OS X system...
$ python inet_ntop_tests.py
Test 1 fe80::a7:938d:274:35ea
Test 2 fe80::a7:938d:274:35ea
Test 3 fe80::a7:938d:274:35ea
Test 1 fe80::6c1e:9e5d:acdd:4f95
Test 2 fe80::6c1e:9e5d:acdd:4f95
Test 3 fe80::6c1e:9e5d:acdd:4f95
Test 1 fe80::819:3442:3f57:ef7c
Test 2 fe80::819:3442:3f57:ef7c
Test 3 fe80::819:3442:3f57:ef7c
Test 1 172.16.237.155
Test 2 172.16.237.155
Test 3 172.16.237.155
Test 1
Test 2 ::
Test 3 ::
In the output, "Test 3" is using the real socket.inet_ntop. "Test 1" is the one
from my side, and "Test 2" is from your inet_ntop.py. So they all match except
my output for the last test is "" instead of "::".
Just attaching it here in case we need to further benchmark things in the
future.
Test 1 0.0.0.0
Test 2 0.0.0.0
Test 3 0.0.0.0
Original comment by michael.hale@gmail.com
on 5 Feb 2011 at 5:32
Attachments:
This issue was closed by revision r690.
Original comment by mike.auty@gmail.com
on 5 Feb 2011 at 6:26
Thanks, the first half of your implementation looks like glibc's
implementation, but doesn't match towards the end. I ended up going with my
implementation because of the final Test where the results deviated from the
canon implementation, and I did copy the function into the file, so that when
windows does support it, we can just ditch the try/except bit. Hope that's all
ok?
Original comment by mike.auty@gmail.com
on 5 Feb 2011 at 6:41
Original issue reported on code.google.com by
michael.hale@gmail.com
on 5 Feb 2011 at 2:32