socket.getfqdn() returns unqualifed hostname if the resolver is configured to trim local domains
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
socket.getfqdn() is returning an unqualified address for my host. I tracked this down to the use of the trim keyword in /etc/host.conf the removal of which would cause other unrelated problems.
Looking at the source code for the system hostname command, they appear to call getaddrinfo with the service parameter set to NULL and pull out the ai_canonname field from the result. See: https://sources.debian.org/src/hostname/3.23/hostname.c lines 332-340 and 386 The python getaddrinfo doesn't especially help with this but perhaps this provides clues as to a more robust implementation.
Looking at Lib/socket.py, gethostname() actually is returning a fully qualified hostname and the gethostbyaddr() step is turning it back into an unqualified address. If this is hard to do portably, perhaps it could check for a dot in the values.
Your environment
Tested on a variety of RHEL based systems - Oracle Linux and CentOS Stream versions 8 and 9 both with distributed Python(s) and a build from source of the latest Python. Can also verify the issue by breaking down and tracing the source code in cpython/Lib/socket.py
/etc/host.conf on these systems includes the trim directive to remove the local domain from returned results.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en Lib/socket.py, siguiendo getfqdn() a través de gethostname() y gethostbyaddr(); compara ese comportamiento con el uso de getaddrinfo y ai_canonname por parte del comando hostname. Reproduce el caso con trim configurado en /etc/host.conf y considera que el resultado está completo cuando getfqdn() conserva el nombre de host plenamente cualificado sin requerir que se elimine esa directiva.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- networking
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100