Skip to content Skip to sidebar Skip to footer

Python Error With Socket. Ntohl()

I'm having an issue with the socket.ntohl() function, on some hosts. It is repeatable on all similar hosts; 32bit machines with Python 2.4.2. >>> socket.ntohl(16777215) -

Solution 1:

In older 32-bit Python versions, int was limited to a signed 32-bit number. 16777215 = 0x00FFFFFF and -256 in 32-bit 2s complement is 0xFFFFFF00.

It works correctly in Python 2.7 by upgrading the value to a long:

>>>socket.ntohl(16777215)
4294967040L
>>>hex(4294967040)
'0xffffff00L'

Edit:

Python 2.4 was the first version to unify int and long so what you see might be considered a bug that has been fixed by 2.7.

Looks like this issue fixed it.

Post a Comment for "Python Error With Socket. Ntohl()"