Зависит от того, какую подсистему ROS использует для этого. Но представим, что использует стандартный метод, который используют все libpcap совместимые синферы:
- It first opens a PF_PACKET/SOCK_RAW socket (activate_new() function)
- then binds the socket using a "struct sockaddr_ll" - a link-layer socket address containing family AF_PACKET, ifindex, and protocol (iface_bind())
- In the kernel this bind action results in a call to dev_add_pack() which adds the packet socket protocol handler to networking stack. this is the key step as with the handler in place the generic send and receive routines will deliver skbs to our packet socket for processing.
- switches on promiscuous mode if requested, pushes a filter if specified
- Once the socket is open, attempt to activate mmap access to packets (activate_mmap())
– PACKET_MMAP uses a shared kernel/userspace ring buffer eliminating the need for system calls to read each packet. Previously libpcap required two system calls per-packet - one to read, another to get the capture time. Now a poll() can be used and multiple packets can be gathered at a time.
- Now we can start reading packets; see pcap_read_linux_mmap_*().
- Data is passed to the tap socket at device-agnostic layer on send, receive
– see net/core/dev.c