[ python-Bugs-811295 ] ntohs on Solaris can return negative values

SourceForge.net noreply at sourceforge.net
Mon Apr 12 14:57:41 EDT 2004


Bugs item #811295, was opened at 2003-09-23 20:23
Message generated for change (Comment added) made by sparvu
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=811295&group_id=5470

Category: Extension Modules
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Nobody/Anonymous (nobody)
Summary: ntohs on Solaris can return negative values

Initial Comment:
On Solaris, socket.ntohs() can return a negative number
when the argument has bit 15 set. This is not according
to spec or intention or expectation. The bug is because
on Solaris, ntohs() is defined as a macro that returns
its argument unchanged, roughly:

  #define ntohs(x) (x)

The socket extension casts the argument to (short); it
should use (unsigned short) or something similar.

Here's a program showing the problem (run this on
Solaris, or on another big-endian machine where ntohs()
is defined away):

import socket
print socket.ntohs(-1)

This should print 65535 but prints -1.

(Credit to Andrew Davis for finding this!)

----------------------------------------------------------------------

Comment By: stefanparvu (sparvu)
Date: 2004-04-12 21:57

Message:
Logged In: YES 
user_id=1019660

Hi,

Just checked this on my solaris 9 box:

Python 2.3.3 (#1, Apr 12 2004, 21:32:46) 
[GCC 2.95.3 20010315 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for more
information.
>>> 
>>> 
>>> import socket
>>> print socket.ntohs(-1)
65535


It looks fine. what system are you running on when doing
this test. 
Most likely can be a bug and needs a patch. You can always
check the release number as:

cat /etc/release

Cheers
Stefan Parvu



----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-09-23 20:26

Message:
Logged In: YES 
user_id=6380

Of course, htons has the same problem.  The 'l' versions are
unaffected.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=811295&group_id=5470



More information about the Python-bugs-list mailing list