This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: example code does not work
Type: behavior Stage:
Components: IO Versions: Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: Neil Muller, fogus, georg.brandl, hodgestar, loewis, mrm
Priority: normal Keywords: patch

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

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
gives an example that uses socket.getaddrinfo that has this code

   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/<module>()
-> 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/<module>()

but setting 
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 <> 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
     socket.gaierror: (-2, 'Name or service not known')

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 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

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 .

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.
Date User Action Args
2022-04-11 14:56:33adminsetgithub: 46991
2009-05-30 00:01:19fogussetversions: - Python 2.5, Python 2.4
nosy: + fogus

messages: + msg88555

components: + IO, - Documentation
2008-05-11 07:06:33georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg66606
2008-05-11 07:04:36georg.brandllinkissue2763 superseder
2008-05-10 11:34:58Neil Mullersetfiles: + socketmodule.diff
nosy: + Neil Muller
messages: + msg66513
2008-05-10 11:33:10hodgestarsetfiles: + getaddrinfo-doesnt-treat-empty-string-as-none.diff
keywords: + patch
messages: + msg66512
2008-05-10 11:20:59hodgestarsetnosy: + hodgestar
messages: + msg66511
versions: + Python 2.6, Python 2.4
2008-05-03 06:53:23loewissetmessages: + msg66142
2008-05-02 23:55:19mrmsetmessages: + msg66132
2008-05-02 19:32:07loewissetnosy: + loewis
messages: + msg66106
2008-05-02 18:57:58mrmcreate