New submission from Ed Schouten:

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.

----------
components: Extension Modules
files: patch-inet_ntoa.diff
keywords: patch
messages: 280109
nosy: EdSchouten
priority: normal
severity: normal
status: open
title: [Patch] Stop using inet_ntoa() when possible.
versions: Python 3.7
Added file: http://bugs.python.org/file45364/patch-inet_ntoa.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28619>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to