[issue25041] document AF_PACKET socket address format
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
New submission from Tim Tisdall: As mentioned in #24984, I'm making another issue to document the address format for AF_PACKET. In this case there's already documentation in Modules/socketmodule.c that says: - an AF_PACKET socket address is a tuple containing a string specifying the ethernet interface and an integer specifying the Ethernet protocol number to be received. For example: ("eth0",0x1234). Optional 3rd,4th,5th elements in the tuple specify packet-type and ha-type/addr. But nothing has been added to Doc/library/socket.rst . The documentation needs to be confirmed with the code. (It probably should be altered somewhat to state how you "specify packet-type and ha-type/addr"... and maybe what a "ha-type/addr" is... A quick Google search found this very useful reference: https://books.google.ca/books?id=Chr1NDlUcI8C&pg=PA472&ots=OCEwyjdXJo&sig=PuNG72WIvv4-A924f9MvzPtgQDc&hl=en&sa=X&ved=0CE8Q6AEwCGoVChMI6IiTyoDqxwIVCTs-Ch3bCAXy#v=onepage&q&f=false ) ---------- assignee: docs@python components: Documentation messages: 250306 nosy: Tim.Tisdall, docs@python priority: normal severity: normal status: open title: document AF_PACKET socket address format type: enhancement versions: Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Changes by STINNER Victor <victor.stinner@gmail.com>: ---------- nosy: +haypo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Tim Tisdall added the comment: Right now the docs say "Certain other address families (:const:`AF_PACKET`, :const:`AF_CAN`) support specific representations.". I was going to create a separate issue for AF_CAN, but it seems that it's already documented... When documentation is added for AF_PACKET, please remove the above mentioned line entirely as AF_CAN is already documented. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Changes by Berker Peksag <berker.peksag@gmail.com>: ---------- keywords: +easy stage: -> needs patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Changes by Adam <azsorkin@gmail.com>: ---------- nosy: +azsorkin _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Camilla Montonen added the comment: Provided patch provides documentation for the AF_PACKET address_family. ---------- keywords: +patch nosy: +Winterflower Added file: http://bugs.python.org/file40898/af_packet_doc.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Berker Peksag added the comment: Thanks! The patch looks good to me. I left a few minor comments on Rietveld: http://bugs.python.org/review/25041/ ---------- nosy: +berker.peksag stage: needs patch -> patch review _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Martin Panter added the comment: Quickly looking through the history (annotate function on Mercurial web frontend): * Revisions 3d4a7cd0bf17, c8ef864ba861 (2001): AF_PACKET support added on Linux. Partially documented in C comment and socket.bind() docstring. AF/PF_PACKET, PACKET_* constants also added. * #947352 (Python 2.4), 8b3288f607e1: Support specifying hardware address, for sendto(). Here are some more things might be good to tease out: 1. Please don’t invent new parameter names without a good reason. I suggest (ifname, proto, pkttype, hatype, addr). These are already used in the bind() doc string, most are consistent with Linux’s struct sockaddr_ll fields, and “proto” is consistent with Python’s socket() constructor. 2. There is an error message mentioning “protoNumber” which could also be adjusted for consistency 3. When Python generates the ifname string, it uses the empty string for ifindex zero (matching any interface), although it does not look like parsing this back is supported 4. proto is endian-corrected, in contrast with Linux’s version being in network byte-order 5. Default pkttype is zero. This is equal to PACKET_HOST, so could be useful. Might also be worth changing the source code to explicitly use PACKET_HOST. 6. addr has to be a bytes-like object 7. Packet support is specific to Linux, and may not be compiled in 8. Existence of *_PACKET and PACKET_* constants 9. socket.bind() doc string needs updating since revision c8ef864ba861 (missing fifth parameter, addr) ---------- nosy: +martin.panter _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Camilla Montonen added the comment: Thank you very much for the feedback, Martin and Berker! I'll start working on the revised patch. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Cheryl Sabella added the comment: Hello Camilla, Would you like to create a Github pull request for your patch? ---------- nosy: +csabella _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Changes by Mariatta Wijaya <mariatta.wijaya@gmail.com>: ---------- stage: patch review -> needs patch versions: +Python 3.7 -Python 3.4, Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Change by Cheryl Sabella <chekat2@gmail.com>: ---------- pull_requests: +4062 stage: needs patch -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Benjamin Peterson <benjamin@python.org> added the comment: New changeset 731ff68eeef58babdf2b32dc9a73b141760c2be9 by Benjamin Peterson (Cheryl Sabella) in branch 'master': closes bpo-25041: Document AF_PACKET socket address format. (GH-4092) https://github.com/python/cpython/commit/731ff68eeef58babdf2b32dc9a73b141760... ---------- nosy: +benjamin.peterson resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Change by Benjamin Peterson <benjamin@python.org>: ---------- pull_requests: +8641 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Change by Benjamin Peterson <benjamin@python.org>: ---------- pull_requests: +8643 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Benjamin Peterson <benjamin@python.org> added the comment: New changeset cadb66e173ded86ebc85b54889db48f66e7af592 by Benjamin Peterson in branch '3.7': [3.7] closes bpo-25041: Document AF_PACKET socket address format. (GH-9207) https://github.com/python/cpython/commit/cadb66e173ded86ebc85b54889db48f66e7... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25041> _______________________________________
![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Benjamin Peterson <benjamin@python.org> added the comment: New changeset a00de685c11cf8bdca1f8efa7aab80552d80ddfb by Benjamin Peterson in branch '3.6': [3.6] closes bpo-25041: Document AF_PACKET socket address format. (GH-9209) https://github.com/python/cpython/commit/a00de685c11cf8bdca1f8efa7aab80552d8... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue25041> _______________________________________
participants (9)
-
Adam
-
Benjamin Peterson
-
Berker Peksag
-
Camilla Montonen
-
Cheryl Sabella
-
Mariatta Wijaya
-
Martin Panter
-
STINNER Victor
-
Tim Tisdall