diff options
author | Benjamin Peterson <benjamin@python.org> | 2018-09-12 05:36:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 05:36:09 (GMT) |
commit | a00de685c11cf8bdca1f8efa7aab80552d80ddfb (patch) | |
tree | a071deb35e426b7ddb35f13b9876083118de5644 /Doc/library | |
parent | 6539b9136f4ffe73a8942a835d84fc218fb97967 (diff) | |
download | cpython-a00de685c11cf8bdca1f8efa7aab80552d80ddfb.zip cpython-a00de685c11cf8bdca1f8efa7aab80552d80ddfb.tar.gz cpython-a00de685c11cf8bdca1f8efa7aab80552d80ddfb.tar.bz2 |
[3.6] closes bpo-25041: Document AF_PACKET socket address format. (GH-9209)
(cherry picked from commit 731ff68eeef58babdf2b32dc9a73b141760c2be9)
Co-authored-by: Cheryl Sabella <cheryl.sabella@gmail.com>
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/socket.rst | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst index 974df4c..f4e5af9 100644 --- a/Doc/library/socket.rst +++ b/Doc/library/socket.rst @@ -156,10 +156,25 @@ created. Socket addresses are represented as follows: .. versionadded:: 3.6 -- Certain other address families (:const:`AF_PACKET`, :const:`AF_CAN`) - support specific representations. - - .. XXX document them! +- :const:`AF_PACKET` is a low-level interface directly to network devices. + The packets are represented by the tuple + ``(ifname, proto[, pkttype[, hatype[, addr]]])`` where: + + - *ifname* - String specifying the device name. + - *proto* - An in network-byte-order integer specifying the Ethernet + protocol number. + - *pkttype* - Optional integer specifying the packet type: + + - ``PACKET_HOST`` (the default) - Packet addressed to the local host. + - ``PACKET_BROADCAST`` - Physical-layer broadcast packet. + - ``PACKET_MULTIHOST`` - Packet sent to a physical-layer multicast address. + - ``PACKET_OTHERHOST`` - Packet to some other host that has been caught by + a device driver in promiscuous mode. + - ``PACKET_OUTGOING`` - Packet originating from the local host that is + looped back to a packet socket. + - *hatype* - Optional integer specifying the ARP hardware address type. + - *addr* - Optional bytes-like object specifying the hardware physical + address, whose interpretation depends on the device. If you use a hostname in the *host* portion of IPv4/v6 socket address, the program may show a nondeterministic behavior, as Python uses the first address @@ -343,6 +358,17 @@ Constants .. versionadded:: 3.5 + +.. data:: AF_PACKET + PF_PACKET + PACKET_* + + Many constants of these forms, documented in the Linux documentation, are + also defined in the socket module. + + Availability: Linux >= 2.2. + + .. data:: AF_RDS PF_RDS SOL_RDS @@ -424,16 +450,16 @@ The following functions all create :ref:`socket objects <socket-objects>`. Create a new socket using the given address family, socket type and protocol number. The address family should be :const:`AF_INET` (the default), - :const:`AF_INET6`, :const:`AF_UNIX`, :const:`AF_CAN` or :const:`AF_RDS`. The - socket type should be :const:`SOCK_STREAM` (the default), - :const:`SOCK_DGRAM`, :const:`SOCK_RAW` or perhaps one of the other ``SOCK_`` - constants. The protocol number is usually zero and may be omitted or in the - case where the address family is :const:`AF_CAN` the protocol should be one - of :const:`CAN_RAW` or :const:`CAN_BCM`. If *fileno* is specified, the other - arguments are ignored, causing the socket with the specified file descriptor - to return. Unlike :func:`socket.fromfd`, *fileno* will return the same - socket and not a duplicate. This may help close a detached socket using - :meth:`socket.close()`. + :const:`AF_INET6`, :const:`AF_UNIX`, :const:`AF_CAN`, :const:`AF_PACKET`, or + :const:`AF_RDS`. The socket type should be :const:`SOCK_STREAM` (the + default), :const:`SOCK_DGRAM`, :const:`SOCK_RAW` or perhaps one of the other + ``SOCK_`` constants. The protocol number is usually zero and may be omitted + or in the case where the address family is :const:`AF_CAN` the protocol + should be one of :const:`CAN_RAW` or :const:`CAN_BCM`. If *fileno* is + specified, the other arguments are ignored, causing the socket with the + specified file descriptor to return. Unlike :func:`socket.fromfd`, *fileno* + will return the same socket and not a duplicate. This may help close a + detached socket using :meth:`socket.close()`. The newly created socket is :ref:`non-inheritable <fd_inheritance>`. |