Re: socket.getsockname is returning junk!!



En Wed, 05 Oct 2011 08:56:08 -0300, Wong Wah Meng-R32813 <r32813@xxxxxxxxxxxxx> escribió:

I am migrating my application from python 1.5.2 to 2.7.1. One of the existing code breaks. The getsockname method from socket object somehow returns me with some number which I deem as junk, rather than the listening port as I would have expected in the older python. Has anyone seen the same thing or is it due to my python is built with some corrupted library or something?


$ python
Python 2.7.1 (r271:86832, Oct 5 2011, 18:34:15) [C] on hp-ux11
Type "help", "copyright", "credits" or "license" for more information.
import socket
sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 )
sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1 )
sock.setsockopt( socket.IPPROTO_TCP, 1, 1 )
server_address=('zmy02hp3', 11111)
sock.bind(server_address)
sock.getsockname()
(0, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

In python 1.5.2
server_address=('zmy02aix04', 11111)
sock.bind(server_address)
sock.getsockname()
('10.228.51.41', 11111)

I'd say it's a problem with the _socket module; did the unit tests flag anything when you built Python?

On Windows, Python 2.7.1:

server_address=('lepton', 11111)
sock.bind(server_address)
sock.getsockname()
('127.0.0.1', 11111)

--
Gabriel Genellina

.