Skip to content

socket.getfqdn() does gethostbyaddr() lookup for own hostname #106505

Description

@bluelhf

Bug report

cpython/Lib/socket.py

Lines 791 to 795 in e1d45b8

name = name.strip()
if not name or name in ('0.0.0.0', '::'):
name = gethostname()
try:
hostname, aliases, ipaddrs = gethostbyaddr(name)

When 0.0.0.0, ::, or empty string is passed into socket.get_fqdn(name), instead of returning gethostname(), it performs a host name lookup using the hostname retrieved from gethostname(), and returns the result.

This differs from the documentation, which states

If name was empty, '0.0.0.0' or '::', hostname from gethostname() is returned.

Your environment

  • CPython versions tested on: Python 3.13.0a0 (heads/main:01e1a60, Jul 7 2023, 11:22:09)
  • Operating system and architecture: Pop!_OS 22.04 on x86_64

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-socketRelated to the socket, socketserver and selectors modulestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions