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.
Get Network Security Tools now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.