Issue 2742: example code does not work (original) (raw)

Created on 2008-05-02 18:57 by mrm, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
getaddrinfo-doesnt-treat-empty-string-as-none.diff hodgestar,2008-05-10 11:33
socketmodule.diff Neil Muller,2008-05-10 11:34 Patch to socketmodule.c to add checks for zero length strings
Messages (9)
msg66103 - (view) Author: Mike MacFaden (mrm) Date: 2008-05-02 18:57
the url http://docs.python.org/lib/socket-example.html gives an example that uses socket.getaddrinfo that has this code HOST='' ... for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE) but this fails on freebsd 6.1/python 2.5 as follows > /usr/home/mrm/s2.py(30)() -> for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): (Pdb) p HOST '' (Pdb) n gaierror: (8, 'hostname nor servname provided, or not known') > /usr/home/mrm/s2.py(30)() but setting HOST=None works fine. either this is a doc bug or a code bug, your pick.
msg66106 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-05-02 19:32
What operating system are you using? It could be a bug in the operating system as well.
msg66132 - (view) Author: Mike MacFaden (mrm) Date: 2008-05-02 23:55
Martin v. Löwis wrote: > Martin v. Löwis <martin@v.loewis.de> added the comment: > > What operating system are you using? It could be a bug in the > operating system as well. hi martin, what i've tested so far... freebsd 6.2 - release 12 jan 2007 socket.gaierror: (8, 'hostname nor servname provided, or not known') Red Hat Enterprise Linux Client release 5.1 (Tikanga), gnu/linux 2.6.18-53.el5 socket.gaierror: (-2, 'Name or service not known') mike
msg66142 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-05-03 06:53
I see. I just reread the getaddrinfo man page, and it says you must pass NULL to leave host unspecified, so passing None is correct, and the documentation is wrong.
msg66511 - (view) Author: Simon Cross (hodgestar) Date: 2008-05-10 11:20
This also affects Python 2.4 and 2.6 on Linux systems. Bug http://bugs.python.org/issue2763 is a duplicate of this one. The issue is that socketmodule.c doesn't convert empty strings to NULLs before passing hptr through to the underlying system getaddrinfo(...). The question is whether to fix the documentation and examples or the socketmodule.c code.
msg66512 - (view) Author: Simon Cross (hodgestar) Date: 2008-05-10 11:33
Attached a patch to correct the getaddrinfo(...) documentation and the code example in socket.rst.
msg66513 - (view) Author: Neil Muller (Neil Muller) Date: 2008-05-10 11:34
The documentation says: For *host* and *port*, by passing either an empty string or ``None``, you can pass ``NULL`` to the C API, so the documentation says it should work. This doesn't work because PyString_AsString retruns an empty string, not NULL. The attached patch adds a check in socketmodule.c to fix this for host and port. It's highly debatable whether this is better than fixing the documentation, though.
msg66606 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-11 07:06
Applied the documentation patch in r63039. Thanks for your efforts!
msg88555 - (view) Author: Gordon Fogus (fogus) Date: 2009-05-30 00:01
I am having this issue again with python code running under python 2.6.2 compiled from source on May 28, 2009 in CentOS 5.3. The patch in the socketmodule.diff file does not seem to be applied to the socketmodule.c file in the current 2.6.2 in http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz . I need to be able to bind a port all interfaces to listen to responses from a server. This currently only works under windows due to this issue. Linux does not like the blank "" IP address; it requires a NULL. Please advise on a workaround or new patch for this issue.
History
Date User Action Args
2022-04-11 14:56:33 admin set github: 46991
2009-05-30 00:01:19 fogus set versions: - Python 2.5, Python 2.4nosy: + fogusmessages: + components: + IO, - Documentation
2008-05-11 07:06:33 georg.brandl set status: open -> closedresolution: fixedmessages: +
2008-05-11 07:04:36 georg.brandl link issue2763 superseder
2008-05-10 11:34:58 Neil Muller set files: + socketmodule.diffnosy: + Neil Mullermessages: +
2008-05-10 11:33:10 hodgestar set files: + getaddrinfo-doesnt-treat-empty-string-as-none.diffkeywords: + patchmessages: +
2008-05-10 11:20:59 hodgestar set nosy: + hodgestarmessages: + versions: + Python 2.6, Python 2.4
2008-05-03 06:53:23 loewis set messages: +
2008-05-02 23:55:19 mrm set messages: +
2008-05-02 19:32:07 loewis set nosy: + loewismessages: +
2008-05-02 18:57:58 mrm create