Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket module htonl/ntohl bug #36742

Closed
davidma mannequin opened this issue Jun 13, 2002 · 3 comments
Closed

socket module htonl/ntohl bug #36742

davidma mannequin opened this issue Jun 13, 2002 · 3 comments
Labels
stdlib Python modules in the Lib dir

Comments

@davidma
Copy link
Mannequin

davidma mannequin commented Jun 13, 2002

BPO 568322

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2002-07-25.16:08:00.000>
created_at = <Date 2002-06-13.01:56:51.000>
labels = ['library']
title = 'socket module htonl/ntohl bug'
updated_at = <Date 2002-07-25.16:08:00.000>
user = 'https://bugs.python.org/davidma'

bugs.python.org fields:

activity = <Date 2002-07-25.16:08:00.000>
actor = 'jhylton'
assignee = 'jhylton'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2002-06-13.01:56:51.000>
creator = 'davidma'
dependencies = []
files = []
hgrepos = []
issue_num = 568322
keywords = []
message_count = 3.0
messages = ['11188', '11189', '11190']
nosy_count = 2.0
nosy_names = ['jhylton', 'davidma']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue568322'
versions = ['Python 2.2']

@davidma
Copy link
Mannequin Author

davidma mannequin commented Jun 13, 2002

Hello,

The following statement should work, but does not, on
python 1.5.2 and python 2.2:

>>> socket.htonl(pow(2L,32)-1)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
OverflowError: long int too long to convert

2^32-1 is a valid 32-bit value, equal to 32 1s in
binary, and htonl
should be able to handle it.

By way of comparison, the following simple C program
works properly:

#include <stdio.h>
#include <sys/socket.h>

int main(void)
{
        printf ("%u\n", htonl(4294967295));
}

When run, it prints out '4294967295' as expected.

Dave

@davidma davidma mannequin closed this as completed Jun 13, 2002
@davidma davidma mannequin assigned jhylton Jun 13, 2002
@davidma davidma mannequin added the stdlib Python modules in the Lib dir label Jun 13, 2002
@jhylton
Copy link
Mannequin

jhylton mannequin commented Jul 25, 2002

Logged In: YES
user_id=31392

The problem here is that the functions are currently
implemented to only accept integers. Note that you can pass
0xffffffff == -1 and get the result you expect. If you're
using the struct module to unpack the raw bytes, you'll be
getting -1 anyway. But it seems reasonable enough to extend
the functions to accept longs that are < 2**32.

@jhylton
Copy link
Mannequin

jhylton mannequin commented Jul 25, 2002

Logged In: YES
user_id=31392

Fixed in rev. 1.236 of socketmodule.c.
These functions will now accepts a long L such that 0 <= L <
2**32.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

0 participants