Name
pcap_loop — Prototype: int pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
Synopsis
Purpose: pcap_loop enters a loop for processing
cnt packets from the opened capture (live or saved
file). Unlike pcap_dispatch,
pcap_loop does not observe read timeouts. If
cnt is set to a negative number, the loop
continues forever. The function specified by
callback is the name of a function of the
prototype void
callback
(u_char
*user,
const
struct
pcap_pkthdr
*header,
const
u_char*
packet). This function is called for each packet
captured. The user parameter is a user-specifiable
value that is passed to the callback function when it is invoked, and
can be NULL. The function
pcap_loop returns 0 if
cnt packets were successfully read,
-1 on an error, and -2 if a
call to pcap_breakloop occurred before packets
have been captured. If an error has occurred, you can use
pcap_perror( ) or pcap_geterr( )
to obtain the error message. You can find an example of
using the pcap_loop function in the Section 10.2.5
section earlier in this chapter.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access