xref: /openbsd/lib/libpcap/pcap-int.h (revision 346f594f)
1 /*	$OpenBSD: pcap-int.h,v 1.14 2018/04/05 03:47:27 lteo 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 
36 #ifndef pcap_int_h
37 #define pcap_int_h
38 
39 #include <pcap.h>
40 
41 /*
42  * Stuff to do when we close.
43  */
44 #define MUST_CLEAR_RFMON	0x00000002	/* clear rfmon (monitor) mode */
45 
46 struct pcap_opt {
47 	int	buffer_size;
48 	char	*source;
49 	int	promisc;
50 	int	rfmon;
51 	int	immediate;	/* immediate mode - deliver packets as soon as they arrive */
52 };
53 
54 /*
55  * Savefile
56  */
57 struct pcap_sf {
58 	FILE *rfile;
59 	int swapped;
60 	int version_major;
61 	int version_minor;
62 	u_char *base;
63 };
64 
65 struct pcap_md {
66 	struct pcap_stat stat;
67 	/*XXX*/
68 	int use_bpf;
69 	u_long	TotPkts;	/* can't oflow for 79 hrs on ether */
70 	u_long	TotAccepted;	/* count accepted by filter */
71 	u_long	TotDrops;	/* count of dropped packets */
72 	long	TotMissed;	/* missed by i/f during this run */
73 	long	OrigMissed;	/* missed by i/f before this run */
74 	int	timeout;	/* timeout for buffering */
75 	int	must_do_on_close; /* stuff we must do when we close */
76 	struct pcap *next;	/* list of open pcaps that need stuff cleared on close */
77 };
78 
79 struct pcap {
80 	int fd;
81 	int snapshot;
82 	int linktype;
83 	int tzoff;		/* timezone offset */
84 	int offset;		/* offset for proper alignment */
85 	int activated;		/* true if the capture is really started */
86 	int oldstyle;		/* if we're opening with pcap_open_live() */
87 	int break_loop;		/* force break from packet-reading loop */
88 
89 	struct pcap_sf sf;
90 	struct pcap_md md;
91 	struct pcap_opt opt;
92 
93 	/*
94 	 * Read buffer.
95 	 */
96 	int bufsize;
97 	u_char *buffer;
98 	u_char *bp;
99 	int cc;
100 
101 	/*
102 	 * Place holder for pcap_next().
103 	 */
104 	u_char *pkt;
105 
106 
107 	/*
108 	 * Placeholder for filter code if bpf not in kernel.
109 	 */
110 	struct bpf_program fcode;
111 
112 	/*
113 	 * Datalink types supported on underlying fd
114 	 */
115 	int dlt_count;
116 	u_int *dlt_list;
117 
118 	char errbuf[PCAP_ERRBUF_SIZE];
119 
120 	struct pcap_pkthdr pcap_header;	/* This is needed for the pcap_next_ex() to work */
121 };
122 
123 /*
124  * How a `pcap_pkthdr' is actually stored in the dumpfile.
125  */
126 
127 struct pcap_sf_pkthdr {
128     struct bpf_timeval ts;	/* time stamp */
129     bpf_u_int32 caplen;		/* length of portion present */
130     bpf_u_int32 len;		/* length this packet (off wire) */
131 };
132 
133 int	yylex(void);
134 
135 #ifndef min
136 #define min(a, b) ((a) > (b) ? (b) : (a))
137 #endif
138 
139 /* Not all systems have IFF_LOOPBACK */
140 #ifdef IFF_LOOPBACK
141 #define ISLOOPBACK(name, flags) ((flags) & IFF_LOOPBACK)
142 #else
143 #define ISLOOPBACK(name, flags) ((name)[0] == 'l' && (name)[1] == 'o' && \
144     (isdigit((unsigned char)((name)[2])) || (name)[2] == '\0'))
145 #endif
146 
147 /* XXX should these be in pcap.h? */
148 int	pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
149 int	pcap_read(pcap_t *, int cnt, pcap_handler, u_char *);
150 
151 int	pcap_do_addexit(pcap_t *);
152 void	pcap_add_to_pcaps_to_close(pcap_t *);
153 void	pcap_remove_from_pcaps_to_close(pcap_t *);
154 int	pcap_check_activated(pcap_t *);
155 
156 /* Ultrix pads to make everything line up on a nice boundary */
157 #if defined(ultrix) || defined(__alpha)
158 #define       PCAP_FDDIPAD 3
159 #endif
160 
161 /* XXX */
162 extern int pcap_fddipad;
163 #endif
164