[New-bugs-announce] [issue14758] SMTPServer of smptd does not support binding to an IPv6 address

Ivan Sergeev report at bugs.python.org
Tue May 8 23:15:50 CEST 2012


New submission from Ivan Sergeev <vsergeev at gmail.com>:

The SMTPServer class of the smtpd module creates a server socket with the IPv4 socket.AF_INET address family hardcoded, and this prevents it from later binding to an IPv6 local address.

This occurs on line 282 of smtpd.py for the Python 2.7 branch:
http://hg.python.org/cpython/file/5319a4bf72e7/Lib/smtpd.py#l282

And on line 435 of smtpd for the Python 3.2 branch ( Lib/smtpd.py:435 ):
http://hg.python.org/cpython/file/d937b527b76e/Lib/smtpd.py#l435

One IPv4/IPv6 agnostic solution is to look up provided local address with getaddrinfo(), and use one of the result's address family, socket type and address tuple for create_socket() and bind() at those lines:

...
try:
    gai_results = socket.getaddrinfo(localaddr[0], localaddr[1])
    self.create_socket(gai_results[0][0], gai_results[0][1])
    # try to re-use a server port if possible
    self.set_reuse_addr()
    self.bind(gai_results[0][4])
    self.listen(5)
...

----------
components: Library (Lib)
messages: 160226
nosy: vsergeev
priority: normal
severity: normal
status: open
title: SMTPServer of smptd does not support binding to an IPv6 address
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14758>
_______________________________________


More information about the New-bugs-announce mailing list