python / python/cpython

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

未關閉
#100,231 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 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 摘要。