Short answer: packages are used at the very end of the network software stack (for example, on Linux).
Long answer with code in tcpdump, libpcap and linux kernel 3.12:
Both Wireshark and tcpdump use libpcap, for example,
http://sources.debian.net/src/tcpdump/4.5.1-2/tcpdump.c#L1472
if (pcap_setfilter(pd, &fcode) < 0)
which, in turn, set the packet filter through setfilter_op and activate_op. There are many implementations of these operations, and I think that in recent Linux PF_PACKET will be used with pcap_activate_linux libpcap-1.5.3-2 / pcap -linux. C # L1287 :
status = activate_new(handle); ... activate_new(pcap_t *handle) ... sock_fd = is_any_device ? socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL)) : socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
PF_PACKET is implemented in the kernel in the file net / packet / af_packet.c . Initialization of PF_SOCKET is performed in packet_do_bind using the register_prot_hook(sk) function (if the device is in UP state), which calls dev_add_pack from net / core / dev.c to register the hook:
370 382 383 void dev_add_pack(struct packet_type *pt) 384 { 385 struct list_head *head = ptype_head(pt); 386 387 spin_lock(&ptype_lock); 388 list_add_rcu(&pt->list, head); 389 spin_unlock(&ptype_lock); 390 }
I think the pf_packet handler - tpacket_rcv(...) function - will be registered in ptype_all.
Hooks registered in ptype_all are called for outgoing packets from dev_queue_xmit_nit ("Subroutine support. Send outgoing frames to any currently used network cranes") using list_for_each_entry_rcu(ptype, &ptype_all, list) { ... deliver_skb ...} .. func , deliver_skb calls the tpacket_rcv function for libpcap.
dev_queue_xmit_nit is called from dev_hard_start_xmit ( line 2539 in net / core / dev.c ), which is AFAIK at the last stage (for outgoing packets) independent of the packet processing device in the Linux network stack.
The same applies to incoming packets, ptype_all -registered hooks are called from __netif_receive_skb_core with the same list_for_each_entry_rcu(ptype, &ptype_all, list) {.. deliver_skb..} . __netif_receive_skb_core is called from __netif_receive_skb at the very beginning of the processing of incoming packets
At the base of Linux there is a good description of the network stack ( http://www.linuxfoundation.org/collaborate/workgroups/networking/kernel_flow ), you can see dev_hard_start_xmit in the image http://www.linuxfoundation.org/images/1/1c/ Network_data_flow_through_kernel.png (warning, it is huge) on the left side under the legend. And netif_receive_skb is located inside the very right bottom square ("net / core / dev.c"), which is supplied from the IRQ, then a NAPI poll or netif_rx, and the only way out is netif_receive_skb .
The picture shows one of the two pf_packet hooks - the leftmost square under the symbol (net / packet / af_packet.c) - for outgoing packets.
What is your tool? How does it connect to the network stack? If you can find the tool in the Network_data_flow file , you will get a response. For example, Netfilter is connected ( NF_HOOK ) only in ip_rcv (inbound) ip_output (local outbound) and ip_forward (outbound routing) - immediately after netif_receive_skb and immediately before dev_queue_xmit .