add winpcap 4.0.2 from url http://www.winpcap.org/
[natblaster.git] / winpcap / dox / wpcap_tut4.txt
blobac1677a61b3bcbaa5bb397c8e5322a223c4065f9
1 /** @ingroup wpcap_tut\r
2  */\r
3 \r
4 \r
5 /** @defgroup wpcap_tut4 Capturing the packets without the callback\r
6  *  @{\r
7 \r
8 The example program in this lesson behaves exactly like the previous program (\ref wpcap_tut3), but it uses pcap_next_ex() instead of pcap_loop().\r
9 \r
10 The callback-based capture mechanism of pcap_loop() is elegant and it could be a good choice in some situations. However, handling a callback is sometimes not practical -- it often makes the program more complex especially in situations with multithreaded applications or C++ classes.\r
12 In these cases, pcap_next_ex() retrievs a packet with a direct call -- using pcap_next_ex() packets are received only when the programmer wants them.\r
14 The parameters of this function are the same as a capture callback -- it takes an adapter descriptor and a couple of pointers that will be initialized and returned to the user (one to a pcap_pkthdr structure and another to a buffer with the packet data). \r
16 In the following program, we recycle the callback code of the previous lesson's example and move it inside main() right after the call to pcap_next_ex().\r
19 \include misc/basic_dump_ex.c\r
21 Why do we use pcap_next_ex() instead of the old pcap_next()? Because pcap_next() has some drawbacks. First of all, it is inefficient because it hides the callback method but still relies on pcap_dispatch(). Second, it is not able to detect EOF, so it's not very useful when gathering packets from a file.\r
23 Notice also that pcap_next_ex() returns different values for success, timeout elapsed, error and EOF conditions. \r
25 \ref wpcap_tut3 "<<< Previous" \ref wpcap_tut5 "Next >>>"\r
27 @}*/\r