]>
Commit | Line | Data |
---|---|---|
b7080c8e A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights | |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.0 (the 'License'). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
13 | * | |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License." | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* $OpenBSD: pcap.h,v 1.6 1996/07/12 13:19:12 mickey Exp $ */ | |
25 | ||
26 | /* | |
27 | * Copyright (c) 1993, 1994, 1995, 1996 | |
28 | * The Regents of the University of California. All rights reserved. | |
29 | * | |
30 | * Redistribution and use in source and binary forms, with or without | |
31 | * modification, are permitted provided that the following conditions | |
32 | * are met: | |
33 | * 1. Redistributions of source code must retain the above copyright | |
34 | * notice, this list of conditions and the following disclaimer. | |
35 | * 2. Redistributions in binary form must reproduce the above copyright | |
36 | * notice, this list of conditions and the following disclaimer in the | |
37 | * documentation and/or other materials provided with the distribution. | |
38 | * 3. All advertising materials mentioning features or use of this software | |
39 | * must display the following acknowledgement: | |
40 | * This product includes software developed by the Computer Systems | |
41 | * Engineering Group at Lawrence Berkeley Laboratory. | |
42 | * 4. Neither the name of the University nor of the Laboratory may be used | |
43 | * to endorse or promote products derived from this software without | |
44 | * specific prior written permission. | |
45 | * | |
46 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
47 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
49 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
52 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
54 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
55 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
56 | * SUCH DAMAGE. | |
57 | * | |
58 | * @(#) Header: pcap.h,v 1.19 96/06/16 22:36:28 leres Exp (LBL) | |
59 | */ | |
60 | ||
61 | #ifndef lib_pcap_h | |
62 | #define lib_pcap_h | |
63 | ||
64 | #include <sys/types.h> | |
65 | #include <sys/time.h> | |
66 | ||
67 | #include <net/bpf.h> | |
68 | ||
69 | #include <stdio.h> | |
70 | ||
71 | #define PCAP_VERSION_MAJOR 2 | |
72 | #define PCAP_VERSION_MINOR 4 | |
73 | ||
74 | #define PCAP_ERRBUF_SIZE 256 | |
75 | ||
76 | /* | |
77 | * Compatibility for systems that have a bpf.h that | |
78 | * predates the bpf typedefs for 64-bit support. | |
79 | */ | |
80 | #if BPF_RELEASE - 0 < 199406 | |
81 | typedef int bpf_int32; | |
82 | typedef u_int bpf_u_int32; | |
83 | #endif | |
84 | ||
85 | typedef struct pcap pcap_t; | |
86 | typedef struct pcap_dumper pcap_dumper_t; | |
87 | ||
88 | /* | |
89 | * The first record in the file contains saved values for some | |
90 | * of the flags used in the printout phases of tcpdump. | |
91 | * Many fields here are 32 bit ints so compilers won't insert unwanted | |
92 | * padding; these files need to be interchangeable across architectures. | |
93 | */ | |
94 | struct pcap_file_header { | |
95 | bpf_u_int32 magic; | |
96 | u_short version_major; | |
97 | u_short version_minor; | |
98 | bpf_int32 thiszone; /* gmt to local correction */ | |
99 | bpf_u_int32 sigfigs; /* accuracy of timestamps */ | |
100 | bpf_u_int32 snaplen; /* max length saved portion of each pkt */ | |
101 | bpf_u_int32 linktype; /* data link type (DLT_*) */ | |
102 | }; | |
103 | ||
104 | /* | |
105 | * Each packet in the dump file is prepended with this generic header. | |
106 | * This gets around the problem of different headers for different | |
107 | * packet interfaces. | |
108 | */ | |
109 | struct pcap_pkthdr { | |
110 | struct timeval ts; /* time stamp */ | |
111 | bpf_u_int32 caplen; /* length of portion present */ | |
112 | bpf_u_int32 len; /* length this packet (off wire) */ | |
113 | }; | |
114 | ||
115 | /* | |
116 | * As returned by the pcap_stats() | |
117 | */ | |
118 | struct pcap_stat { | |
119 | u_int ps_recv; /* number of packets received */ | |
120 | u_int ps_drop; /* number of packets dropped */ | |
121 | u_int ps_ifdrop; /* drops by interface XXX not yet supported */ | |
122 | }; | |
123 | ||
124 | typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, | |
125 | const u_char *); | |
126 | ||
127 | char *pcap_lookupdev(char *); | |
128 | int pcap_lookupnet(char *, bpf_u_int32 *, bpf_u_int32 *, char *); | |
129 | pcap_t *pcap_open_live(char *, int, int, int, char *); | |
130 | pcap_t *pcap_open_offline(char *, char *); | |
131 | void pcap_close(pcap_t *); | |
132 | int pcap_loop(pcap_t *, int, pcap_handler, u_char *); | |
133 | int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); | |
134 | const u_char* | |
135 | pcap_next(pcap_t *, struct pcap_pkthdr *); | |
136 | int pcap_stats(pcap_t *, struct pcap_stat *); | |
137 | int pcap_setfilter(pcap_t *, struct bpf_program *); | |
138 | void pcap_perror(pcap_t *, char *); | |
139 | char *pcap_strerror(int); | |
140 | char *pcap_geterr(pcap_t *); | |
141 | int pcap_compile(pcap_t *, struct bpf_program *, char *, int, | |
142 | bpf_u_int32); | |
143 | /* XXX */ | |
144 | int pcap_freecode(pcap_t *, struct bpf_program *); | |
145 | int pcap_datalink(pcap_t *); | |
146 | int pcap_snapshot(pcap_t *); | |
147 | int pcap_is_swapped(pcap_t *); | |
148 | int pcap_major_version(pcap_t *); | |
149 | int pcap_minor_version(pcap_t *); | |
150 | ||
151 | /* XXX */ | |
152 | FILE *pcap_file(pcap_t *); | |
153 | int pcap_fileno(pcap_t *); | |
154 | ||
155 | pcap_dumper_t *pcap_dump_open(pcap_t *, char *); | |
156 | void pcap_dump_close(pcap_dumper_t *); | |
157 | void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); | |
158 | ||
159 | /* XXX this guy lives in the bpf tree */ | |
160 | u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); | |
161 | char *bpf_image(struct bpf_insn *, int); | |
162 | ||
163 | /* XXX */ | |
164 | extern int pcap_fddipad; | |
165 | ||
166 | #endif |