xref: /openbsd/lib/libpcap/pcap-int.h (revision d485f761)
1 /*	$OpenBSD: pcap-int.h,v 1.9 2001/10/02 18:04:35 deraadt Exp $	*/
2 
3 /*
4  * Copyright (c) 1994, 1995, 1996
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the Computer Systems
18  *	Engineering Group at Lawrence Berkeley Laboratory.
19  * 4. Neither the name of the University nor of the Laboratory may be used
20  *    to endorse or promote products derived from this software without
21  *    specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * @(#) $Header: /home/cvs/src/lib/libpcap/pcap-int.h,v 1.9 2001/10/02 18:04:35 deraadt Exp $ (LBL)
36  */
37 
38 #ifndef pcap_int_h
39 #define pcap_int_h
40 
41 #include <pcap.h>
42 
43 /*
44  * Savefile
45  */
46 struct pcap_sf {
47 	FILE *rfile;
48 	int swapped;
49 	int version_major;
50 	int version_minor;
51 	u_char *base;
52 };
53 
54 struct pcap_md {
55 	struct pcap_stat stat;
56 	/*XXX*/
57 	int use_bpf;
58 	u_long	TotPkts;	/* can't oflow for 79 hrs on ether */
59 	u_long	TotAccepted;	/* count accepted by filter */
60 	u_long	TotDrops;	/* count of dropped packets */
61 	long	TotMissed;	/* missed by i/f during this run */
62 	long	OrigMissed;	/* missed by i/f before this run */
63 #ifdef linux
64 	int pad;
65 	int skip;
66 	char *device;
67 #endif
68 };
69 
70 struct pcap {
71 	int fd;
72 	int snapshot;
73 	int linktype;
74 	int tzoff;		/* timezone offset */
75 	int offset;		/* offset for proper alignment */
76 
77 	struct pcap_sf sf;
78 	struct pcap_md md;
79 
80 	/*
81 	 * Read buffer.
82 	 */
83 	int bufsize;
84 	u_char *buffer;
85 	u_char *bp;
86 	int cc;
87 
88 	/*
89 	 * Place holder for pcap_next().
90 	 */
91 	u_char *pkt;
92 
93 
94 	/*
95 	 * Placeholder for filter code if bpf not in kernel.
96 	 */
97 	struct bpf_program fcode;
98 
99 	char errbuf[PCAP_ERRBUF_SIZE];
100 };
101 
102 /*
103  * How a `pcap_pkthdr' is actually stored in the dumpfile.
104  */
105 
106 struct pcap_sf_pkthdr {
107     struct bpf_timeval ts;	/* time stamp */
108     bpf_u_int32 caplen;		/* length of portion present */
109     bpf_u_int32 len;		/* length this packet (off wire) */
110 };
111 
112 int	yylex(void);
113 
114 #ifndef min
115 #define min(a, b) ((a) > (b) ? (b) : (a))
116 #endif
117 
118 /* XXX should these be in pcap.h? */
119 int	pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
120 int	pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
121 
122 /* Ultrix pads to make everything line up on a nice boundary */
123 #if defined(ultrix) || defined(__alpha)
124 #define       PCAP_FDDIPAD 3
125 #endif
126 
127 /* XXX */
128 extern int pcap_fddipad;
129 #endif
130