socket.getfqdn() returns unqualifed hostname if the resolver is configured to trim local domains
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Lib/socket.py から始め、gethostname() と gethostbyaddr() を経由する getfqdn() の処理を追跡します。この動作を、hostname コマンドが getaddrinfo と ai_canonname を使用する場合と比較します。/etc/host.conf で trim を設定した状態を再現し、getfqdn() がそのディレクティブを削除しなくても完全修飾ホスト名を保持すれば、結果は完了とみなします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- networking
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100