[Patch] Stop using inet_ntoa() when possible.
| BPO | 28619 |
|---|---|
| Nosy | @EdSchouten |
| Files |
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 = None
created_at = <Date 2016-11-05.11:37:21.542>
labels = ['extension-modules', '3.7']
title = '[Patch] Stop using inet_ntoa() when possible.'
updated_at = <Date 2016-11-05.11:37:21.542>
user = 'https://github.com/EdSchouten'
bugs.python.org fields:
activity = <Date 2016-11-05.11:37:21.542>
actor = 'EdSchouten'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Extension Modules']
creation = <Date 2016-11-05.11:37:21.542>
creator = 'EdSchouten'
dependencies = []
files = ['45364']
hgrepos = []
issue_num = 28619
keywords = ['patch']
message_count = 1.0
messages = ['280109']
nosy_count = 1.0
nosy_names = ['EdSchouten']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue28619'
versions = ['Python 3.7']
Modern C code should use inet_ntop()/inet_pton() as opposed to inet_addr()/inet_aton()/inet_ntoa().
Though the former functions may typically act as drop-in replacements for the latter, the inet_addr()/inet_aton() functions still have the advantage over inet_pton() of allowing you to parse IPv4 addresses that don't use the dotted quad notation (e.g. '0x0a000001' for 10.0.0.1).
There is no difference between inet_ntop() and inet_ntoa(), as they both always print the address in dotted quad form. inet_ntop() does have the advantage of being thread-safe, as inet_ntoa() uses internal storage for the return value. In other words, we'd better not use inet_ntoa() at all.
Attached is a patch for Python's socketmodule that changes the existing call to inet_ntoa() to use inet_ntop() when available. This has the advantage of fixing the build on CloudABI (https://mail.python.org/pipermail/python-dev/2016-July/145708.html), which intentionally omits any APIs that are thread-unsafe.
I can't see how this is a problem in the current socket module source code. Suggesting closing this issue. cc. @tiran
CloudABI is no more.