python / python/cpython

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

Aperta
#100,231 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

docs topic-socket
Lingua principale
Python
Stelle
77.2k
Fork
36k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Apri Doc/library/socket.rst alla rappresentazione degli indirizzi AF_PACKET ed esamina le posizioni citate in Modules/socketmodule.c per quanto riguarda il comportamento dell’ordine dei byte. Aggiorna la documentazione per distinguere gli indirizzi di bind/recvfrom dal parametro proto di socket(), e correggi la formulazione “packets”; il lavoro è completo quando le conversioni e la terminologia documentate corrispondono all’implementazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
documentation, networking
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.