kernel - PF SMP work - fix RDR rules
[dragonfly.git] / contrib / libpcap / pcap_next_ex.3pcap
1 .\" @(#) $Header: /tcpdump/master/libpcap/pcap_next_ex.3pcap,v 1.3 2008-04-06 02:53:22 guy Exp $
2 .\"
3 .\" Copyright (c) 1994, 1996, 1997
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that: (1) source code distributions
8 .\" retain the above copyright notice and this paragraph in its entirety, (2)
9 .\" distributions including binary code include the above copyright notice and
10 .\" this paragraph in its entirety in the documentation or other materials
11 .\" provided with the distribution, and (3) all advertising materials mentioning
12 .\" features or use of this software display the following acknowledgement:
13 .\" ``This product includes software developed by the University of California,
14 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 .\" the University nor the names of its contributors may be used to endorse
16 .\" or promote products derived from this software without specific prior
17 .\" written permission.
18 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 .\"
22 .TH PCAP_NEXT_EX 3PCAP "5 April 2008"
23 .SH NAME
24 pcap_next_ex, pcap_next \- read the next packet from a pcap_t
25 .SH SYNOPSIS
26 .nf
27 .ft B
28 #include <pcap/pcap.h>
29 .ft
30 .LP
31 .ft B
32 int pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,
33 .ti +8
34 const u_char **pkt_data);
35 const u_char *pcap_next(pcap_t *p, struct pcap_pkthdr *h);
36 .ft
37 .fi
38 .SH DESCRIPTION
39 .B pcap_next_ex()
40 reads the next packet and returns a success/failure indication.
41 If the packet was read without problems, the pointer pointed to by the
42 .I pkt_header
43 argument is set to point to the
44 .I pcap_pkthdr
45 struct for the packet, and the
46 pointer pointed to by the
47 .I pkt_data
48 argument is set to point to the data in the packet.  The
49 .I struct pcap_pkthdr
50 and the packet data are not to be freed by the caller, and are not
51 guaranteed to be valid after the next call to
52 .BR pcap_next_ex() ,
53 .BR pcap_next() ,
54 .BR pcap_loop() ,
55 or
56 .BR pcap_dispatch() ;
57 if the code needs them to remain valid, it must make a copy of them.
58 .PP
59 .B pcap_next()
60 reads the next packet (by calling
61 .B pcap_dispatch()
62 with a
63 .I cnt
64 of 1) and returns a
65 .I u_char
66 pointer to the data in that packet.  The
67 packet data is not to be freed by the caller, and is not
68 guaranteed to be valid after the next call to
69 .BR pcap_next_ex() ,
70 .BR pcap_next() ,
71 .BR pcap_loop() ,
72 or
73 .BR pcap_dispatch() ;
74 if the code needs it to remain valid, it must make a copy of it.
75 The
76 .I pcap_pkthdr
77 structure pointed to by
78 .I h
79 is filled in with the appropriate values for the packet.
80 .SH RETURN VALUE
81 .B pcap_next_ex()
82 returns 1 if the packet was read without problems, 0
83 if packets are being read from a live capture, and the timeout expired,
84 \-1 if an error occurred while reading the packet, and \-2 if
85 packets are being read from a ``savefile'', and there are no more
86 packets to read from the savefile.
87 If \-1 is returned,
88 .B pcap_geterr()
89 or
90 .B pcap_perror()
91 may be called with
92 .I p
93 as an argument to fetch or display the error text.
94 .PP
95 .B pcap_next()
96 returns a pointer to the packet data on success, and returns
97 .B NULL
98 if an error occurred, or if no packets were read from a live
99 capture (if, for example, they were discarded because they didn't pass
100 the packet filter, or if, on platforms that support a read timeout that
101 starts before any packets arrive, the timeout expires before any packets
102 arrive, or if the file descriptor for the capture device is in
103 non-blocking mode and no packets were available to be read), or if no
104 more packets are available in a ``savefile.''  Unfortunately, there is
105 no way to determine whether an error occurred or not.
106 .SH SEE ALSO
107 pcap(3PCAP), pcap_geterr(3PCAP), pcap_dispatch(3PCAP)