Issue1895

classification
Title: socket.getaddrinfo() does not return list of all available ip's on the host.
Type: Severity: normal
Components: Library Versions: 2.5.3b1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amak Nosy List: amak, oscar
Priority: Keywords:

Created on 2012-05-24.20:56:53 by oscar, last changed 2012-08-14.21:15:29 by amak.

Messages
msg7143 (view) Author: Oscar (oscar) Date: 2012-05-24.20:56:53
The behaviour is inconsistent with CPython as shown here:

[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_04
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getaddrinfo(None,8888)
[(2, None, 0, 'oscar-linux.local', ('127.0.0.1', 8888))]


Python 2.5.3 (r253:67855, May 24 2012, 13:39:10) 
[GCC 4.5.1 20100924 (Red Hat 4.5.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getaddrinfo(None,8888)
[(10, 1, 6, '', ('::1', 8888, 0, 0)), (10, 2, 17, '', ('::1', 8888, 0, 0)), (10, 3, 0, '', ('::1', 8888, 0, 0)), (
2, 1, 6, '', ('127.0.0.1', 8888)), (2, 2, 17, '', ('127.0.0.1', 8888)), (2, 3, 0, '', ('127.0.0.1', 8888))]


Jython 2.7a1 behaviour is identical to 2.5.3b1.
msg7168 (view) Author: Alan Kennedy (amak) Date: 2012-05-29.22:09:39
There's a couple of aspects to this.

First of all, the jython socket module is defaulting to AF_INET, when it should really be defaulting to AF_UNSPEC, which will return both 
IPv4 and IPv6 addresses. I.e. the signature of the function looks like this

def getaddrinfo(host, port, family=AF_INET, socktype=None, proto=0, flags=0):

and should look like this

def getaddrinfo(host, port, family=AF_UNSPEC, socktype=None, proto=0, flags=0):

I will fix this.

Also what needs to be fixed is returning all possible socket types and protocols, if they are not specified. I will fix this.

Even when the above two fixes are done, you will still not get the 6 results that cpython gives, because it has returned a SOCK_RAW address_info to you: java, and thus jython, does not support SOCK_RAW sockets.

And lastly, there are JVM options that control whether or not the address lookup calls return IPv4 or IPv6, which I will have to document, since they can also have a bearing on what results are returned from java.net.InetAddress.getAllByName()

I will check in these fixes, to 2.5 and 2.7, at the weekend.
msg7169 (view) Author: Alan Kennedy (amak) Date: 2012-05-29.22:11:07
It should be mentioned also that you will get identical results between cpython and jython if you specify all of the family, socktype and proto parameters.

It's just the behaviour in the case of parameter defaults that is buggy.
msg7403 (view) Author: Alan Kennedy (amak) Date: 2012-08-14.21:15:29
Fix checked in at

2.5: http://hg.python.org/jython/rev/d56c4119fed1
tip: http://hg.python.org/jython/rev/a423b9e08626
History
Date User Action Args
2012-08-14 21:15:29amaksetstatus: open -> closed
resolution: fixed
messages: + msg7403
2012-05-29 22:11:07amaksetmessages: + msg7169
2012-05-29 22:09:40amaksetmessages: + msg7168
2012-05-29 21:46:08amaksetassignee: amak
nosy: + amak
2012-05-24 20:56:53oscarcreate