python / python/cpython

socket.AF_PACKET doc: proto is *not* in network byte order

オープン
#100,231 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

docs topic-socket
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

Documentation

The documentation of socket.AF_PACKET says that the value of proto in the address representation must be in network-byte-order:

https://github.com/python/cpython/blame/v3.12.0a3/Doc/library/socket.rst#L196

Value must be in network-byte-order.

This is incorrect. It is true that the corresponding Linux field sll_protocol is in network byte order (see packet(7)), but Python automatically converts to/from host byte order:

https://github.com/python/cpython/blob/v3.12.0a3/Modules/socketmodule.c#L1483

https://github.com/python/cpython/blob/v3.12.0a3/Modules/socketmodule.c#L2104

Note: This applies to addresses passed to socket.bind() and returned from socket.recvfrom(), but does not apply to the proto parameter of socket.socket() -- Python doesn't automatically convert it, so the user must supply a value in network byte order (when using AF_PACKET). It might be a good idea to document this, e.g. the documentation of ETH_P_ALL could mention that it needs to be converted using socket.htons() before passing to socket.socket().

Bonus typo:

https://github.com/python/cpython/blame/v3.12.0a3/Doc/library/socket.rst#L188

The packets are represented by the tuple

"packets" is inaccurate and should be changed to "addresses" or "sockets".

Linked PRs
  • gh-154741

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Doc/library/socket.rst の AF_PACKET アドレス表現を開き、バイトオーダーの動作について Modules/socketmodule.c の参照されている箇所を確認してください。bind/recvfrom のアドレスと socket() の proto パラメーターを区別するようにドキュメントを更新し、「packets」という表現を修正してください。ドキュメントに記載された変換と用語が実装と一致すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
documentation, networking
issue の種類
ドキュメント
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。