1*78871eb8Sdugsong /* $OpenBSD: pcap.h,v 1.10 2001/12/17 22:29:47 dugsong Exp $ */ 2df930be7Sderaadt 3df930be7Sderaadt /* 401efc7efSderaadt * Copyright (c) 1993, 1994, 1995, 1996, 1997 5df930be7Sderaadt * The Regents of the University of California. All rights reserved. 6df930be7Sderaadt * 7df930be7Sderaadt * Redistribution and use in source and binary forms, with or without 8df930be7Sderaadt * modification, are permitted provided that the following conditions 9df930be7Sderaadt * are met: 10df930be7Sderaadt * 1. Redistributions of source code must retain the above copyright 11df930be7Sderaadt * notice, this list of conditions and the following disclaimer. 12df930be7Sderaadt * 2. Redistributions in binary form must reproduce the above copyright 13df930be7Sderaadt * notice, this list of conditions and the following disclaimer in the 14df930be7Sderaadt * documentation and/or other materials provided with the distribution. 15df930be7Sderaadt * 3. All advertising materials mentioning features or use of this software 16df930be7Sderaadt * must display the following acknowledgement: 17df930be7Sderaadt * This product includes software developed by the Computer Systems 18df930be7Sderaadt * Engineering Group at Lawrence Berkeley Laboratory. 19df930be7Sderaadt * 4. Neither the name of the University nor of the Laboratory may be used 20df930be7Sderaadt * to endorse or promote products derived from this software without 21df930be7Sderaadt * specific prior written permission. 22df930be7Sderaadt * 23df930be7Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24df930be7Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25df930be7Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26df930be7Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27df930be7Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28df930be7Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29df930be7Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30df930be7Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31df930be7Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32df930be7Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33df930be7Sderaadt * SUCH DAMAGE. 34df930be7Sderaadt * 35*78871eb8Sdugsong * @(#) $Header: /home/cvs/src/lib/libpcap/pcap.h,v 1.10 2001/12/17 22:29:47 dugsong Exp $ (LBL) 36df930be7Sderaadt */ 37df930be7Sderaadt 38df930be7Sderaadt #ifndef lib_pcap_h 39df930be7Sderaadt #define lib_pcap_h 40df930be7Sderaadt 41df930be7Sderaadt #include <sys/types.h> 42df930be7Sderaadt #include <sys/time.h> 43df930be7Sderaadt 44df930be7Sderaadt #include <net/bpf.h> 45df930be7Sderaadt 46df930be7Sderaadt #include <stdio.h> 47df930be7Sderaadt 48df930be7Sderaadt #define PCAP_VERSION_MAJOR 2 49df930be7Sderaadt #define PCAP_VERSION_MINOR 4 50df930be7Sderaadt 51df930be7Sderaadt #define PCAP_ERRBUF_SIZE 256 52df930be7Sderaadt 53df930be7Sderaadt /* 54df930be7Sderaadt * Compatibility for systems that have a bpf.h that 55df930be7Sderaadt * predates the bpf typedefs for 64-bit support. 56df930be7Sderaadt */ 57df930be7Sderaadt #if BPF_RELEASE - 0 < 199406 589b113833Smickey typedef int bpf_int32; 599b113833Smickey typedef u_int bpf_u_int32; 60df930be7Sderaadt #endif 61df930be7Sderaadt 62df930be7Sderaadt typedef struct pcap pcap_t; 63df930be7Sderaadt typedef struct pcap_dumper pcap_dumper_t; 64df930be7Sderaadt 65df930be7Sderaadt /* 66df930be7Sderaadt * The first record in the file contains saved values for some 67df930be7Sderaadt * of the flags used in the printout phases of tcpdump. 689b113833Smickey * Many fields here are 32 bit ints so compilers won't insert unwanted 69df930be7Sderaadt * padding; these files need to be interchangeable across architectures. 70df930be7Sderaadt */ 71df930be7Sderaadt struct pcap_file_header { 72df930be7Sderaadt bpf_u_int32 magic; 73df930be7Sderaadt u_short version_major; 74df930be7Sderaadt u_short version_minor; 75df930be7Sderaadt bpf_int32 thiszone; /* gmt to local correction */ 76df930be7Sderaadt bpf_u_int32 sigfigs; /* accuracy of timestamps */ 77df930be7Sderaadt bpf_u_int32 snaplen; /* max length saved portion of each pkt */ 78df930be7Sderaadt bpf_u_int32 linktype; /* data link type (DLT_*) */ 79df930be7Sderaadt }; 80df930be7Sderaadt 81df930be7Sderaadt /* 82df930be7Sderaadt * Each packet in the dump file is prepended with this generic header. 83df930be7Sderaadt * This gets around the problem of different headers for different 84df930be7Sderaadt * packet interfaces. 85df930be7Sderaadt */ 86df930be7Sderaadt struct pcap_pkthdr { 87eb867ec1Sderaadt struct bpf_timeval ts; /* time stamp */ 88df930be7Sderaadt bpf_u_int32 caplen; /* length of portion present */ 89df930be7Sderaadt bpf_u_int32 len; /* length this packet (off wire) */ 90df930be7Sderaadt }; 91df930be7Sderaadt 92df930be7Sderaadt /* 93df930be7Sderaadt * As returned by the pcap_stats() 94df930be7Sderaadt */ 95df930be7Sderaadt struct pcap_stat { 96df930be7Sderaadt u_int ps_recv; /* number of packets received */ 97df930be7Sderaadt u_int ps_drop; /* number of packets dropped */ 98df930be7Sderaadt u_int ps_ifdrop; /* drops by interface XXX not yet supported */ 99df930be7Sderaadt }; 100df930be7Sderaadt 101df930be7Sderaadt typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, 102df930be7Sderaadt const u_char *); 103df930be7Sderaadt 104df930be7Sderaadt char *pcap_lookupdev(char *); 1059b113833Smickey int pcap_lookupnet(char *, bpf_u_int32 *, bpf_u_int32 *, char *); 106df930be7Sderaadt pcap_t *pcap_open_live(char *, int, int, int, char *); 10701efc7efSderaadt pcap_t *pcap_open_offline(const char *, char *); 108df930be7Sderaadt void pcap_close(pcap_t *); 109df930be7Sderaadt int pcap_loop(pcap_t *, int, pcap_handler, u_char *); 110df930be7Sderaadt int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); 111df930be7Sderaadt const u_char* 112df930be7Sderaadt pcap_next(pcap_t *, struct pcap_pkthdr *); 113df930be7Sderaadt int pcap_stats(pcap_t *, struct pcap_stat *); 114df930be7Sderaadt int pcap_setfilter(pcap_t *, struct bpf_program *); 115df930be7Sderaadt void pcap_perror(pcap_t *, char *); 116df930be7Sderaadt char *pcap_strerror(int); 117df930be7Sderaadt char *pcap_geterr(pcap_t *); 1189b113833Smickey int pcap_compile(pcap_t *, struct bpf_program *, char *, int, 1199b113833Smickey bpf_u_int32); 120a9b0695fSjakob int pcap_compile_nopcap(int, int, struct bpf_program *, 121a9b0695fSjakob char *, int, bpf_u_int32); 122*78871eb8Sdugsong void pcap_freecode(struct bpf_program *); 123df930be7Sderaadt int pcap_datalink(pcap_t *); 124df930be7Sderaadt int pcap_snapshot(pcap_t *); 125df930be7Sderaadt int pcap_is_swapped(pcap_t *); 126df930be7Sderaadt int pcap_major_version(pcap_t *); 127df930be7Sderaadt int pcap_minor_version(pcap_t *); 128df930be7Sderaadt 129df930be7Sderaadt /* XXX */ 130df930be7Sderaadt FILE *pcap_file(pcap_t *); 131df930be7Sderaadt int pcap_fileno(pcap_t *); 132df930be7Sderaadt 13301efc7efSderaadt pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); 134df930be7Sderaadt void pcap_dump_close(pcap_dumper_t *); 135df930be7Sderaadt void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); 136df930be7Sderaadt 137df930be7Sderaadt /* XXX this guy lives in the bpf tree */ 138df930be7Sderaadt u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); 139df930be7Sderaadt char *bpf_image(struct bpf_insn *, int); 140df930be7Sderaadt #endif 141