python / python/cpython

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

Offen
#100,231 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

docs topic-socket
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Öffne Doc/library/socket.rst bei der AF_PACKET-Adressdarstellung und überprüfe die zitierten Stellen in Modules/socketmodule.c auf das Byte-Order-Verhalten. Aktualisiere die Dokumentation, um bind/recvfrom-Adressen vom proto-Parameter von socket() zu unterscheiden, und korrigiere die Formulierung „packets“; fertig ist es, wenn die dokumentierten Konvertierungen und die Terminologie mit der Implementierung übereinstimmen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
documentation, networking
Issue-Typ
Dokumentation
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.