socket.getfqdn() returns unqualifed hostname if the resolver is configured to trim local domains
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece em Lib/socket.py, rastreando getfqdn() por meio de gethostname() e gethostbyaddr(); compare esse comportamento com o uso de getaddrinfo e ai_canonname pelo comando hostname. Reproduza o caso com trim configurado em /etc/host.conf e considere o resultado concluído quando getfqdn() preservar o nome de host totalmente qualificado sem exigir que essa diretiva seja removida.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- networking
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 38/100