MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pcap_thread_entry

Function pcap_thread_entry

bsp/simulator/pcap/pcap_netif.c:51–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49static rt_mailbox_t packet_mb = RT_NULL;
50
51static void pcap_thread_entry(void* parameter)
52{
53 pcap_if_t *netif;
54 pcap_t *tap;
55 char errbuf[PCAP_ERRBUF_SIZE];
56 struct pcap_pkthdr *header;
57 const u_char *pkt_data;
58 int res;
59
60 netif = (pcap_if_t *) parameter;
61
62 /* Open the adapter */
63 if ((tap = pcap_open_live(netif->name,
64 65536, // portion of the packet to capture.
65 1, // promiscuous mode (nonzero means promiscuous)
66 1, // read timeout, 0 blocked, -1 no timeout
67 errbuf )) == NULL)
68 {
69 rt_kprintf("Unable to open the adapter. %s is not supported by WinPcap\n", netif->name);
70 return;
71 }
72
73 NETIF_PCAP(&pcap_netif_device) = tap;
74
75 /* Read the packets */
76 while (1)
77 {
78 struct eth_device* eth;
79 struct pbuf *p;
80
81 rt_enter_critical();
82 res = pcap_next_ex(tap, &header, &pkt_data);
83 rt_exit_critical();
84
85 if (res == 0) continue;
86
87 eth = (struct eth_device*) &pcap_netif_device;
88
89 p = pbuf_alloc(PBUF_LINK, header->len, PBUF_RAM);
90 pbuf_take(p, pkt_data, header->len);
91
92 /* send to packet mailbox */
93 rt_mb_send_wait(packet_mb, (rt_uint32_t)p, RT_WAITING_FOREVER);
94 /* notify eth rx thread to receive packet */
95 eth_device_ready(eth);
96 }
97}
98
99static rt_err_t pcap_netif_init(rt_device_t dev)
100{

Callers

nothing calls this directly

Calls 7

rt_kprintfFunction · 0.85
rt_mb_send_waitFunction · 0.85
eth_device_readyFunction · 0.85
rt_enter_criticalFunction · 0.50
rt_exit_criticalFunction · 0.50
pbuf_allocFunction · 0.50
pbuf_takeFunction · 0.50

Tested by

no test coverage detected