pcap.h revision 17683
117683Spst/*
217683Spst * Copyright (c) 1993, 1994, 1995, 1996
317683Spst *	The Regents of the University of California.  All rights reserved.
417683Spst *
517683Spst * Redistribution and use in source and binary forms, with or without
617683Spst * modification, are permitted provided that the following conditions
717683Spst * are met:
817683Spst * 1. Redistributions of source code must retain the above copyright
917683Spst *    notice, this list of conditions and the following disclaimer.
1017683Spst * 2. Redistributions in binary form must reproduce the above copyright
1117683Spst *    notice, this list of conditions and the following disclaimer in the
1217683Spst *    documentation and/or other materials provided with the distribution.
1317683Spst * 3. All advertising materials mentioning features or use of this software
1417683Spst *    must display the following acknowledgement:
1517683Spst *	This product includes software developed by the Computer Systems
1617683Spst *	Engineering Group at Lawrence Berkeley Laboratory.
1717683Spst * 4. Neither the name of the University nor of the Laboratory may be used
1817683Spst *    to endorse or promote products derived from this software without
1917683Spst *    specific prior written permission.
2017683Spst *
2117683Spst * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2217683Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2317683Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2417683Spst * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2517683Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2617683Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2717683Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2817683Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2917683Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3017683Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3117683Spst * SUCH DAMAGE.
3217683Spst *
3317683Spst * @(#) $Header: pcap.h,v 1.20 96/07/12 19:24:15 leres Exp $ (LBL)
3417683Spst */
3517683Spst
3617683Spst#ifndef lib_pcap_h
3717683Spst#define lib_pcap_h
3817683Spst
3917683Spst#include <sys/types.h>
4017683Spst#include <sys/time.h>
4117683Spst
4217683Spst#include <net/bpf.h>
4317683Spst
4417683Spst#include <stdio.h>
4517683Spst
4617683Spst#define PCAP_VERSION_MAJOR 2
4717683Spst#define PCAP_VERSION_MINOR 4
4817683Spst
4917683Spst#define PCAP_ERRBUF_SIZE 256
5017683Spst
5117683Spst/*
5217683Spst * Compatibility for systems that have a bpf.h that
5317683Spst * predates the bpf typedefs for 64-bit support.
5417683Spst */
5517683Spst#if BPF_RELEASE - 0 < 199406
5617683Spsttypedef	int bpf_int32;
5717683Spsttypedef	u_int bpf_u_int32;
5817683Spst#endif
5917683Spst
6017683Spsttypedef struct pcap pcap_t;
6117683Spsttypedef struct pcap_dumper pcap_dumper_t;
6217683Spst
6317683Spst/*
6417683Spst * The first record in the file contains saved values for some
6517683Spst * of the flags used in the printout phases of tcpdump.
6617683Spst * Many fields here are 32 bit ints so compilers won't insert unwanted
6717683Spst * padding; these files need to be interchangeable across architectures.
6817683Spst */
6917683Spststruct pcap_file_header {
7017683Spst	bpf_u_int32 magic;
7117683Spst	u_short version_major;
7217683Spst	u_short version_minor;
7317683Spst	bpf_int32 thiszone;	/* gmt to local correction */
7417683Spst	bpf_u_int32 sigfigs;	/* accuracy of timestamps */
7517683Spst	bpf_u_int32 snaplen;	/* max length saved portion of each pkt */
7617683Spst	bpf_u_int32 linktype;	/* data link type (DLT_*) */
7717683Spst};
7817683Spst
7917683Spst/*
8017683Spst * Each packet in the dump file is prepended with this generic header.
8117683Spst * This gets around the problem of different headers for different
8217683Spst * packet interfaces.
8317683Spst */
8417683Spststruct pcap_pkthdr {
8517683Spst	struct timeval ts;	/* time stamp */
8617683Spst	bpf_u_int32 caplen;	/* length of portion present */
8717683Spst	bpf_u_int32 len;	/* length this packet (off wire) */
8817683Spst};
8917683Spst
9017683Spst/*
9117683Spst * As returned by the pcap_stats()
9217683Spst */
9317683Spststruct pcap_stat {
9417683Spst	u_int ps_recv;		/* number of packets received */
9517683Spst	u_int ps_drop;		/* number of packets dropped */
9617683Spst	u_int ps_ifdrop;	/* drops by interface XXX not yet supported */
9717683Spst};
9817683Spst
9917683Spsttypedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
10017683Spst			     const u_char *);
10117683Spst
10217683Spstchar	*pcap_lookupdev(char *);
10317683Spstint	pcap_lookupnet(char *, bpf_u_int32 *, bpf_u_int32 *, char *);
10417683Spstpcap_t	*pcap_open_live(char *, int, int, int, char *);
10517683Spstpcap_t	*pcap_open_offline(char *, char *);
10617683Spstvoid	pcap_close(pcap_t *);
10717683Spstint	pcap_loop(pcap_t *, int, pcap_handler, u_char *);
10817683Spstint	pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
10917683Spstconst u_char*
11017683Spst	pcap_next(pcap_t *, struct pcap_pkthdr *);
11117683Spstint	pcap_stats(pcap_t *, struct pcap_stat *);
11217683Spstint	pcap_setfilter(pcap_t *, struct bpf_program *);
11317683Spstvoid	pcap_perror(pcap_t *, char *);
11417683Spstchar	*pcap_strerror(int);
11517683Spstchar	*pcap_geterr(pcap_t *);
11617683Spstint	pcap_compile(pcap_t *, struct bpf_program *, char *, int,
11717683Spst	    bpf_u_int32);
11817683Spst/* XXX */
11917683Spstint	pcap_freecode(pcap_t *, struct bpf_program *);
12017683Spstint	pcap_datalink(pcap_t *);
12117683Spstint	pcap_snapshot(pcap_t *);
12217683Spstint	pcap_is_swapped(pcap_t *);
12317683Spstint	pcap_major_version(pcap_t *);
12417683Spstint	pcap_minor_version(pcap_t *);
12517683Spst
12617683Spst/* XXX */
12717683SpstFILE	*pcap_file(pcap_t *);
12817683Spstint	pcap_fileno(pcap_t *);
12917683Spst
13017683Spstpcap_dumper_t *pcap_dump_open(pcap_t *, char *);
13117683Spstvoid	pcap_dump_close(pcap_dumper_t *);
13217683Spstvoid	pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
13317683Spst
13417683Spst/* XXX this guy lives in the bpf tree */
13517683Spstu_int	bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
13617683Spstchar	*bpf_image(struct bpf_insn *, int);
13717683Spst#endif
138