Skip to content

Instantly share code, notes, and snippets.

@boxofrad
Created November 3, 2016 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxofrad/4511ba4357401a0ea7a04e4d394b9609 to your computer and use it in GitHub Desktop.
Save boxofrad/4511ba4357401a0ea7a04e4d394b9609 to your computer and use it in GitHub Desktop.
# Receive every packet
ETH_P_ALL = 0x0300
# Size in bytes of a C `sockaddr_ll` structure on a 64-bit system
#
# struct sockaddr_ll {
# unsigned short sll_family; /* Always AF_PACKET */
# unsigned short sll_protocol; /* Physical-layer protocol */
# int sll_ifindex; /* Interface number */
# unsigned short sll_hatype; /* ARP hardware type */
# unsigned char sll_pkttype; /* Packet type */
# unsigned char sll_halen; /* Length of address */
# unsigned char sll_addr[8]; /* Physical-layer address */
# };
#
SOCKADDR_LL_SIZE = 0x0014
sockaddr_ll = [Socket::AF_PACKET].pack('s')
sockaddr_ll << [ETH_P_ALL].pack('s')
sockaddr_ll << index
sockaddr_ll << ("\x00" * (SOCKADDR_LL_SIZE - sockaddr_ll.length))
socket.bind(sockaddr_ll)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment