mirror of https://github.com/python/cpython.git
gh-100374: Fixed a bug in socket.getfqdn() (gh-100375)
(cherry picked from commit 12be23cf3c
)
Co-authored-by: Dominic Socular <BBH@awsl.rip>
This commit is contained in:
parent
ae8520c709
commit
b2076b0071
|
@ -784,11 +784,11 @@ def getfqdn(name=''):
|
||||||
|
|
||||||
First the hostname returned by gethostbyaddr() is checked, then
|
First the hostname returned by gethostbyaddr() is checked, then
|
||||||
possibly existing aliases. In case no FQDN is available and `name`
|
possibly existing aliases. In case no FQDN is available and `name`
|
||||||
was given, it is returned unchanged. If `name` was empty or '0.0.0.0',
|
was given, it is returned unchanged. If `name` was empty, '0.0.0.0' or '::',
|
||||||
hostname from gethostname() is returned.
|
hostname from gethostname() is returned.
|
||||||
"""
|
"""
|
||||||
name = name.strip()
|
name = name.strip()
|
||||||
if not name or name == '0.0.0.0':
|
if not name or name in ('0.0.0.0', '::'):
|
||||||
name = gethostname()
|
name = gethostname()
|
||||||
try:
|
try:
|
||||||
hostname, aliases, ipaddrs = gethostbyaddr(name)
|
hostname, aliases, ipaddrs = gethostbyaddr(name)
|
||||||
|
|
|
@ -1760,6 +1760,10 @@ def test_getaddrinfo_ipv6_basic(self):
|
||||||
)
|
)
|
||||||
self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, 0))
|
self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, 0))
|
||||||
|
|
||||||
|
def test_getfqdn_filter_localhost(self):
|
||||||
|
self.assertEqual(socket.getfqdn(), socket.getfqdn("0.0.0.0"))
|
||||||
|
self.assertEqual(socket.getfqdn(), socket.getfqdn("::"))
|
||||||
|
|
||||||
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test.')
|
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test.')
|
||||||
@unittest.skipIf(sys.platform == 'win32', 'does not work on Windows')
|
@unittest.skipIf(sys.platform == 'win32', 'does not work on Windows')
|
||||||
@unittest.skipIf(AIX, 'Symbolic scope id does not work')
|
@unittest.skipIf(AIX, 'Symbolic scope id does not work')
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix incorrect result and delay in :func:`socket.getfqdn`. Patch by Dominic Socular.
|
Loading…
Reference in New Issue