00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef lib_pcap_h
00038 #define lib_pcap_h
00039
00040 #if defined(WIN32)
00041 #include <pcap-stdinc.h>
00042 #elif defined(MSDOS)
00043 #include <sys/types.h>
00044 #include <sys/socket.h>
00045 #else
00046 #include <sys/types.h>
00047 #include <sys/time.h>
00048 #endif
00049
00050 #ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
00051 #include <pcap-bpf.h>
00052 #endif
00053
00054 #include <stdio.h>
00055
00056 #ifdef HAVE_REMOTE
00057
00058
00059
00060 #ifndef SOCKET
00061 #ifdef WIN32
00062 #define SOCKET unsigned int
00063 #else
00064 #define SOCKET int
00065 #endif
00066 #endif
00067 #endif
00068
00069 #ifdef __cplusplus
00070 extern "C" {
00071 #endif
00072
00073 #define PCAP_VERSION_MAJOR 2
00074 #define PCAP_VERSION_MINOR 4
00075
00076 #define PCAP_ERRBUF_SIZE 256
00077
00078
00079
00080
00081
00082 #if BPF_RELEASE - 0 < 199406
00083 typedef int bpf_int32;
00084 typedef u_int bpf_u_int32;
00085 #endif
00086
00087 typedef struct pcap pcap_t;
00088 typedef struct pcap_dumper pcap_dumper_t;
00089 typedef struct pcap_if pcap_if_t;
00090 typedef struct pcap_addr pcap_addr_t;
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 struct pcap_file_header {
00127 bpf_u_int32 magic;
00128 u_short version_major;
00129 u_short version_minor;
00130 bpf_int32 thiszone;
00131 bpf_u_int32 sigfigs;
00132 bpf_u_int32 snaplen;
00133 bpf_u_int32 linktype;
00134 };
00135
00136 typedef enum {
00137 PCAP_D_INOUT = 0,
00138 PCAP_D_IN,
00139 PCAP_D_OUT
00140 } pcap_direction_t;
00141
00142
00143
00144
00145
00146
00147 struct pcap_pkthdr {
00148 struct timeval ts;
00149 bpf_u_int32 caplen;
00150 bpf_u_int32 len;
00151 };
00152
00153
00154
00155
00156 struct pcap_stat {
00157 u_int ps_recv;
00158 u_int ps_drop;
00159 u_int ps_ifdrop;
00160 #ifdef HAVE_REMOTE
00161 u_int ps_capt;
00162 u_int ps_sent;
00163 u_int ps_netdrop;
00164 #endif
00165 };
00166
00167 #ifdef MSDOS
00168
00169
00170
00171 struct pcap_stat_ex {
00172 u_long rx_packets;
00173 u_long tx_packets;
00174 u_long rx_bytes;
00175 u_long tx_bytes;
00176 u_long rx_errors;
00177 u_long tx_errors;
00178 u_long rx_dropped;
00179 u_long tx_dropped;
00180 u_long multicast;
00181 u_long collisions;
00182
00183
00184 u_long rx_length_errors;
00185 u_long rx_over_errors;
00186 u_long rx_crc_errors;
00187 u_long rx_frame_errors;
00188 u_long rx_fifo_errors;
00189 u_long rx_missed_errors;
00190
00191
00192 u_long tx_aborted_errors;
00193 u_long tx_carrier_errors;
00194 u_long tx_fifo_errors;
00195 u_long tx_heartbeat_errors;
00196 u_long tx_window_errors;
00197 };
00198 #endif
00199
00200
00201
00202
00203 struct pcap_if {
00204 struct pcap_if *next;
00205 char *name;
00206 char *description;
00207 struct pcap_addr *addresses;
00208 bpf_u_int32 flags;
00209 };
00210
00211 #define PCAP_IF_LOOPBACK 0x00000001
00212
00213
00214
00215
00216 struct pcap_addr {
00217 struct pcap_addr *next;
00218 struct sockaddr *addr;
00219 struct sockaddr *netmask;
00220 struct sockaddr *broadaddr;
00221 struct sockaddr *dstaddr;
00222 };
00223
00224 typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
00225 const u_char *);
00226
00227 char *pcap_lookupdev(char *);
00228 int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
00229 pcap_t *pcap_open_live(const char *, int, int, int, char *);
00230 pcap_t *pcap_open_dead(int, int);
00231 pcap_t *pcap_open_offline(const char *, char *);
00232 pcap_t *pcap_fopen_offline(FILE *, char *);
00233 void pcap_close(pcap_t *);
00234 int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
00235 int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
00236 const u_char*
00237 pcap_next(pcap_t *, struct pcap_pkthdr *);
00238 int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
00239 void pcap_breakloop(pcap_t *);
00240 int pcap_stats(pcap_t *, struct pcap_stat *);
00241 int pcap_setfilter(pcap_t *, struct bpf_program *);
00242 int pcap_setdirection(pcap_t *, pcap_direction_t);
00243 int pcap_getnonblock(pcap_t *, char *);
00244 int pcap_setnonblock(pcap_t *, int, char *);
00245 void pcap_perror(pcap_t *, char *);
00246 int pcap_inject(pcap_t *, const void *, size_t);
00247 int pcap_sendpacket(pcap_t *, const u_char *, int);
00248 char *pcap_strerror(int);
00249 char *pcap_geterr(pcap_t *);
00250 int pcap_compile(pcap_t *, struct bpf_program *, char *, int,
00251 bpf_u_int32);
00252 int pcap_compile_nopcap(int, int, struct bpf_program *,
00253 char *, int, bpf_u_int32);
00254 void pcap_freecode(struct bpf_program *);
00255 int pcap_datalink(pcap_t *);
00256 int pcap_list_datalinks(pcap_t *, int **);
00257 int pcap_set_datalink(pcap_t *, int);
00258 int pcap_datalink_name_to_val(const char *);
00259 const char *pcap_datalink_val_to_name(int);
00260 const char *pcap_datalink_val_to_description(int);
00261 int pcap_snapshot(pcap_t *);
00262 int pcap_is_swapped(pcap_t *);
00263 int pcap_major_version(pcap_t *);
00264 int pcap_minor_version(pcap_t *);
00265
00266
00267 FILE *pcap_file(pcap_t *);
00268 int pcap_fileno(pcap_t *);
00269
00270 pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
00271 pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
00272 FILE *pcap_dump_file(pcap_dumper_t *);
00273 long pcap_dump_ftell(pcap_dumper_t *);
00274 int pcap_dump_flush(pcap_dumper_t *);
00275 void pcap_dump_close(pcap_dumper_t *);
00276 void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
00277
00278 int pcap_findalldevs(pcap_if_t **, char *);
00279 void pcap_freealldevs(pcap_if_t *);
00280
00281 const char *pcap_lib_version(void);
00282
00283
00284 u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
00285 int bpf_validate(struct bpf_insn *f, int len);
00286 char *bpf_image(struct bpf_insn *, int);
00287 void bpf_dump(struct bpf_program *, int);
00288
00289 #if defined(WIN32)
00290
00291
00292
00293
00294
00295 int pcap_setbuff(pcap_t *p, int dim);
00296 int pcap_setmode(pcap_t *p, int mode);
00297 int pcap_setmintocopy(pcap_t *p, int size);
00298
00299 #ifdef WPCAP
00300
00301 #include <Win32-Extensions.h>
00302 #endif
00303
00304 #define MODE_CAPT 0
00305 #define MODE_STAT 1
00306 #define MODE_MON 2
00307
00308 #elif defined(MSDOS)
00309
00310
00311
00312
00313
00314 int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
00315 void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
00316 u_long pcap_mac_packets (void);
00317
00318 #else
00319
00320
00321
00322
00323
00324 int pcap_get_selectable_fd(pcap_t *);
00325
00326 #endif
00327
00328 #ifdef HAVE_REMOTE
00329
00330 #include "remote-ext.h"
00331 #endif
00332
00333 #ifdef __cplusplus
00334 }
00335 #endif
00336
00337 #endif