PFZheng / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

OSX - Process.get_connections() shows wrong IPv6 address #225

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Run the following script on OSX:

import os, socket
import psutil

s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.bind(('::1', 0))
s.listen(1)
cons = psutil.Process(os.getpid()).get_connections()
s.close()
print cons[0].local_address

What is the expected output?
('::1', 49553)

What do you see instead?
('::', 49553)

Please use labels and text to provide additional information.
To convert the IPv6 address we're passing the in6_addr structure to inet_ntop():
http://code.google.com/p/psutil/source/browse/tags/release-0.3.0/psutil/_psutil_
osx.c#1007
For that part of the code I originally used lsof source code as an example:
http://www.google.com/codesearch#pFm0LxzAWvs/darwinsource/tarballs/other/lsof-28
.tar.gz%7CiuEfJEQnleI/lsof-28/lsof/dialects/darwin/libproc/dsock.c&q=laddr.ina_6
%20lang:c&l=213
Fortunately we have a test showing this problem (test_get_connections_ipv6).
At the moment I have no idea why this happens though.
Assigning to Jeremy for now.

Original issue reported on code.google.com by g.rodola on 22 Oct 2011 at 7:08