Issue1844

classification
Title: bad host returned by getsockname
Type: behaviour Severity: normal
Components: Library Versions: 2.5.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amak Nosy List: amak, vleloup
Priority: Keywords:

Created on 2012-02-28.20:52:53 by vleloup, last changed 2012-03-17.22:07:48 by amak.

Messages
msg6785 (view) Author: Vincent Leloup (vleloup) Date: 2012-02-28.20:52:53
Test program :
import socket
sok=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sok.bind(("", 0))
sok.listen(100)
print sok.getsockname()[0]

returned value:
- python: 0.0.0.0
- jython: 0:0:0:0:0:0:0:0

Issue:
The value returned by jython is of the wrong family: AF_INET6 instead of AF_INET as requested.

context:
>jython --version
Jython 2.5.1+

>java -version
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8.9) (6b18-1.8.9-0.1~squeeze1)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)
msg6788 (view) Author: Alan Kennedy (amak) Date: 2012-03-05.22:38:31
The report is accurate: this is indeed a bug.

I will fix it shortly.

In the meantime, it is highly recommended to use the getaddrinfo function when getting IP addresses.

You would call it like this

>>> socket.getaddrinfo(socket.INADDR_ANY, 0, socket.AF_INET)
[(2, None, 0, '0.0.0.0', ('0.0.0.0', 0))]

The tuple at element 4 is the tuple you would pass to bind.
msg6809 (view) Author: Alan Kennedy (amak) Date: 2012-03-17.22:07:48
Fix checked in at

2.5:  http://hg.python.org/jython/rev/74c6db01be43
head: http://hg.python.org/jython/rev/76287b6c2863
History
Date User Action Args
2012-03-17 22:07:48amaksetstatus: open -> closed
resolution: fixed
messages: + msg6809
2012-03-05 22:38:31amaksetassignee: amak
messages: + msg6788
nosy: + amak
2012-02-28 20:52:53vleloupcreate