| 49 | static rt_mailbox_t packet_mb = RT_NULL; |
| 50 | |
| 51 | static 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 | |
| 99 | static rt_err_t pcap_netif_init(rt_device_t dev) |
| 100 | { |
nothing calls this directly
no test coverage detected