| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -189,8 +189,11 @@ created. Socket addresses are represented as follows: | |||
| 189 | 189 | ``(ifname, proto[, pkttype[, hatype[, addr]]])`` where: | |
| 190 | 190 | ||
| 191 | 191 | - *ifname* - String specifying the device name. | |
| 192 | - - *proto* - An in network-byte-order integer specifying the Ethernet | ||
| 193 | - protocol number. | ||
| 192 | + - *proto* - The Ethernet protocol number. | ||
| 193 | + May be :data:`ETH_P_ALL` to capture all protocols, | ||
| 194 | + one of the :ref:`ETHERTYPE_* constants <socket-ethernet-types>` | ||
| 195 | + or any other Ethernet protocol number. | ||
| 196 | + Value must be in network-byte-order. | ||
| 194 | 197 | - *pkttype* - Optional integer specifying the packet type: | |
| 195 | 198 | ||
| 196 | 199 | - ``PACKET_HOST`` (the default) - Packet addressed to the local host. | |
@@ -508,6 +511,19 @@ Constants | |||
| 508 | 511 | .. availability:: Linux >= 2.2. | |
| 509 | 512 | ||
| 510 | 513 | ||
| 514 | + .. data:: ETH_P_ALL | ||
| 515 | + | ||
| 516 | + :data:`!ETH_P_ALL` can be used in the :class:`~socket.socket` | ||
| 517 | + constructor as *proto* for the :const:`AF_PACKET` family in order to | ||
| 518 | + capture every packet, regardless of protocol. | ||
| 519 | + | ||
| 520 | + For more information, see the :manpage:`packet(7)` manpage. | ||
| 521 | + | ||
| 522 | + .. availability:: Linux. | ||
| 523 | + | ||
| 524 | + .. versionadded:: 3.12 | ||
| 525 | + | ||
| 526 | + | ||
| 511 | 527 | .. data:: AF_RDS | |
| 512 | 528 | PF_RDS | |
| 513 | 529 | SOL_RDS | |
@@ -638,6 +654,22 @@ Constants | |||
| 638 | 654 | ||
| 639 | 655 | .. versionadded:: 3.12 | |
| 640 | 656 | ||
| 657 | + .. _socket-ethernet-types: | ||
| 658 | + | ||
| 659 | + .. data:: ETHERTYPE_ARP | ||
| 660 | + ETHERTYPE_IP | ||
| 661 | + ETHERTYPE_IPV6 | ||
| 662 | + ETHERTYPE_VLAN | ||
| 663 | + | ||
| 664 | + `IEEE 802.3 protocol number | ||
| 665 | + <https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.txt>`_. | ||
| 666 | + constants. | ||
| 667 | + | ||
| 668 | + .. availability:: Linux, FreeBSD, macOS. | ||
| 669 | + | ||
| 670 | + .. versionadded:: 3.12 | ||
| 671 | + | ||
| 672 | + | ||
| 641 | 673 | Functions | |
| 642 | 674 | ^^^^^^^^^ | |
| 643 | 675 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Expose :data:`~socket.ETH_P_ALL` and some of the | ||
| 2 | + :ref:`ETHERTYPE_* constants <socket-ethernet-types>` in :mod:`socket`. | ||
| 3 | + Patch by Noam Cohen. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -247,6 +247,10 @@ shutdown(how) -- shut down traffic in one or both directions\n\ | |||
| 247 | 247 | #include <net/if.h> | |
| 248 | 248 | #endif | |
| 249 | 249 | ||
| 250 | + #ifdef HAVE_NET_ETHERNET_H | ||
| 251 | + #include <net/ethernet.h> | ||
| 252 | + #endif | ||
| 253 | + | ||
| 250 | 254 | /* Generic socket object definitions and includes */ | |
| 251 | 255 | #define PySocket_BUILDING_SOCKET | |
| 252 | 256 | #include "socketmodule.h" | |
@@ -7711,6 +7715,25 @@ PyInit__socket(void) | |||
| 7711 | 7715 | PyModule_AddIntMacro(m, ALG_OP_VERIFY); | |
| 7712 | 7716 | #endif | |
| 7713 | 7717 | ||
| 7718 | + /* IEEE 802.3 protocol numbers required for a standard TCP/IP network stack */ | ||
| 7719 | + #ifdef ETHERTYPE_ARP | ||
| 7720 | + PyModule_AddIntMacro(m, ETHERTYPE_ARP); | ||
| 7721 | + #endif | ||
| 7722 | + #ifdef ETHERTYPE_IP | ||
| 7723 | + PyModule_AddIntMacro(m, ETHERTYPE_IP); | ||
| 7724 | + #endif | ||
| 7725 | + #ifdef ETHERTYPE_IPV6 | ||
| 7726 | + PyModule_AddIntMacro(m, ETHERTYPE_IPV6); | ||
| 7727 | + #endif | ||
| 7728 | + #ifdef ETHERTYPE_VLAN | ||
| 7729 | + PyModule_AddIntMacro(m, ETHERTYPE_VLAN); | ||
| 7730 | + #endif | ||
| 7731 | + | ||
| 7732 | + /* Linux pseudo-protocol for sniffing every packet */ | ||
| 7733 | + #ifdef ETH_P_ALL | ||
| 7734 | + PyModule_AddIntMacro(m, ETH_P_ALL); | ||
| 7735 | + #endif | ||
| 7736 | + | ||
| 7714 | 7737 | /* Socket types */ | |
| 7715 | 7738 | PyModule_AddIntMacro(m, SOCK_STREAM); | |
| 7716 | 7739 | PyModule_AddIntMacro(m, SOCK_DGRAM); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2708,7 +2708,7 @@ AC_CHECK_HEADERS([ \ | |||
| 2708 | 2708 | alloca.h asm/types.h bluetooth.h conio.h crypt.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \ | |
| 2709 | 2709 | ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/fs.h linux/memfd.h \ | |
| 2710 | 2710 | linux/random.h linux/soundcard.h \ | |
| 2711 | - linux/tipc.h linux/wait.h netdb.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \ | ||
| 2711 | + linux/tipc.h linux/wait.h netdb.h net/ethernet.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \ | ||
| 2712 | 2712 | sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \ | |
| 2713 | 2713 | sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \ | |
| 2714 | 2714 | sys/loadavg.h sys/lock.h sys/memfd.h sys/mkdev.h sys/mman.h sys/modem.h sys/param.h sys/poll.h \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -844,6 +844,9 @@ | |||
| 844 | 844 | /* Define to 1 if you have the <netpacket/packet.h> header file. */ | |
| 845 | 845 | #undef HAVE_NETPACKET_PACKET_H | |
| 846 | 846 | ||
| 847 | + /* Define to 1 if you have the <net/ethernet.h> header file. */ | ||
| 848 | + #undef HAVE_NET_ETHERNET_H | ||
| 849 | + | ||
| 847 | 850 | /* Define to 1 if you have the <net/if.h> header file. */ | |
| 848 | 851 | #undef HAVE_NET_IF_H | |
| 849 | 852 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments