2021-01-18 01:26:35 -08:00
|
|
|
/* $OpenBSD: pcap.h,v 1.22 2021/01/18 09:26:35 sthen Exp $ */
|
1995-10-18 01:37:01 -07:00
|
|
|
|
|
|
|
/*
|
1999-07-19 21:49:54 -07:00
|
|
|
* Copyright (c) 1993, 1994, 1995, 1996, 1997
|
1995-10-18 01:37:01 -07:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the Computer Systems
|
|
|
|
* Engineering Group at Lawrence Berkeley Laboratory.
|
|
|
|
* 4. Neither the name of the University nor of the Laboratory may be used
|
|
|
|
* to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lib_pcap_h
|
|
|
|
#define lib_pcap_h
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define PCAP_VERSION_MAJOR 2
|
|
|
|
#define PCAP_VERSION_MINOR 4
|
|
|
|
|
|
|
|
#define PCAP_ERRBUF_SIZE 256
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compatibility for systems that have a bpf.h that
|
|
|
|
* predates the bpf typedefs for 64-bit support.
|
|
|
|
*/
|
|
|
|
#if BPF_RELEASE - 0 < 199406
|
1996-07-12 06:19:06 -07:00
|
|
|
typedef int bpf_int32;
|
|
|
|
typedef u_int bpf_u_int32;
|
1995-10-18 01:37:01 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct pcap pcap_t;
|
2005-11-18 03:05:38 -08:00
|
|
|
typedef struct pcap_if pcap_if_t;
|
|
|
|
typedef struct pcap_addr pcap_addr_t;
|
1995-10-18 01:37:01 -07:00
|
|
|
typedef struct pcap_dumper pcap_dumper_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first record in the file contains saved values for some
|
|
|
|
* of the flags used in the printout phases of tcpdump.
|
1996-07-12 06:19:06 -07:00
|
|
|
* Many fields here are 32 bit ints so compilers won't insert unwanted
|
1995-10-18 01:37:01 -07:00
|
|
|
* padding; these files need to be interchangeable across architectures.
|
|
|
|
*/
|
|
|
|
struct pcap_file_header {
|
|
|
|
bpf_u_int32 magic;
|
|
|
|
u_short version_major;
|
|
|
|
u_short version_minor;
|
|
|
|
bpf_int32 thiszone; /* gmt to local correction */
|
|
|
|
bpf_u_int32 sigfigs; /* accuracy of timestamps */
|
|
|
|
bpf_u_int32 snaplen; /* max length saved portion of each pkt */
|
|
|
|
bpf_u_int32 linktype; /* data link type (DLT_*) */
|
|
|
|
};
|
|
|
|
|
2006-03-26 12:58:50 -08:00
|
|
|
typedef enum {
|
|
|
|
PCAP_D_INOUT = 0,
|
|
|
|
PCAP_D_IN,
|
|
|
|
PCAP_D_OUT
|
|
|
|
} pcap_direction_t;
|
|
|
|
|
1995-10-18 01:37:01 -07:00
|
|
|
/*
|
|
|
|
* Each packet in the dump file is prepended with this generic header.
|
|
|
|
* This gets around the problem of different headers for different
|
|
|
|
* packet interfaces.
|
|
|
|
*/
|
|
|
|
struct pcap_pkthdr {
|
2001-10-02 11:04:35 -07:00
|
|
|
struct bpf_timeval ts; /* time stamp */
|
1995-10-18 01:37:01 -07:00
|
|
|
bpf_u_int32 caplen; /* length of portion present */
|
2019-11-27 19:08:21 -08:00
|
|
|
bpf_u_int32 len; /* length of this packet (off wire) */
|
1995-10-18 01:37:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As returned by the pcap_stats()
|
|
|
|
*/
|
|
|
|
struct pcap_stat {
|
|
|
|
u_int ps_recv; /* number of packets received */
|
|
|
|
u_int ps_drop; /* number of packets dropped */
|
|
|
|
u_int ps_ifdrop; /* drops by interface XXX not yet supported */
|
|
|
|
};
|
|
|
|
|
2005-11-18 03:05:38 -08:00
|
|
|
/*
|
|
|
|
* Item in a list of interfaces.
|
|
|
|
*/
|
|
|
|
struct pcap_if {
|
|
|
|
struct pcap_if *next;
|
|
|
|
char *name; /* name to hand to "pcap_open_live()" */
|
|
|
|
char *description; /* textual description of interface, or NULL */
|
|
|
|
struct pcap_addr *addresses;
|
|
|
|
bpf_u_int32 flags; /* PCAP_IF_ interface flags */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Representation of an interface address.
|
|
|
|
*/
|
|
|
|
struct pcap_addr {
|
|
|
|
struct pcap_addr *next;
|
|
|
|
struct sockaddr *addr; /* address */
|
|
|
|
struct sockaddr *netmask; /* netmask for that address */
|
|
|
|
struct sockaddr *broadaddr; /* broadcast address for that address */
|
|
|
|
struct sockaddr *dstaddr; /* P2P destination address for that address */
|
|
|
|
};
|
|
|
|
|
Import a number of core functions from libpcap-1.2.0 while preserving
local changes: strncpy() -> strlcpy(), malloc(x * y) -> calloc(x, y),
exclude cross-platform cruft, etc.
The new functions are pcap_create(), pcap_set_snaplen(),
pcap_set_promisc(), pcap_can_set_rfmon(), pcap_set_rfmon(),
pcap_set_timeout(), pcap_set_buffer_size(), pcap_activate(), and
pcap_statustostr().
This diff was tested on amd64, i386, macppc, and sparc64, where
regression tests were done on various pcap-based ports (especially amd64
and i386 where regression tests were run on all pcap-based ports).
Testers also tried running pcap-based ports that they are familiar with
to ensure that there is no behavioral change. tcpdump and pflogd in
base were also tested by different testers. The new pcap_* functions
were tested with a proof-of-concept Snort 2.9 port for many months.
Thank you to everyone who helped test this diff and provided feedback:
haesbaert@, sthen@, matthew@, gonzalo@, brett@, Rodolfo Gouveia,
Aaron Bieber, Markus Lude, and Ray Percival.
ok haesbaert sthen henning
2012-05-24 18:58:08 -07:00
|
|
|
/*
|
|
|
|
* Error codes for the pcap API.
|
|
|
|
* These will all be negative, so you can check for the success or
|
|
|
|
* failure of a call that returns these codes by checking for a
|
|
|
|
* negative value.
|
|
|
|
*/
|
|
|
|
#define PCAP_ERROR -1 /* generic error code */
|
|
|
|
#define PCAP_ERROR_BREAK -2 /* loop terminated by pcap_breakloop */
|
|
|
|
#define PCAP_ERROR_NOT_ACTIVATED -3 /* the capture needs to be activated */
|
|
|
|
#define PCAP_ERROR_ACTIVATED -4 /* the operation can't be performed on already activated captures */
|
|
|
|
#define PCAP_ERROR_NO_SUCH_DEVICE -5 /* no such device exists */
|
|
|
|
#define PCAP_ERROR_RFMON_NOTSUP -6 /* this device doesn't support rfmon (monitor) mode */
|
|
|
|
#define PCAP_ERROR_NOT_RFMON -7 /* operation supported only in monitor mode */
|
|
|
|
#define PCAP_ERROR_PERM_DENIED -8 /* no permission to open the device */
|
|
|
|
#define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */
|
|
|
|
#define PCAP_ERROR_CANTSET_TSTAMP_TYPE -10 /* this device doesn't support setting the time stamp type */
|
|
|
|
#define PCAP_ERROR_PROMISC_PERM_DENIED -11 /* you don't have permission to capture in promiscuous mode */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Warning codes for the pcap API.
|
|
|
|
* These will all be positive and non-zero, so they won't look like
|
|
|
|
* errors.
|
|
|
|
*/
|
|
|
|
#define PCAP_WARNING 1 /* generic warning code */
|
|
|
|
#define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */
|
|
|
|
#define PCAP_WARNING_TSTAMP_TYPE_NOTSUP 3 /* the requested time stamp type is not supported */
|
|
|
|
|
2021-01-18 01:26:35 -08:00
|
|
|
/*
|
|
|
|
* Value to pass to pcap_compile() as the netmask if you don't know what
|
|
|
|
* the netmask is.
|
|
|
|
*/
|
|
|
|
#define PCAP_NETMASK_UNKNOWN 0xffffffff
|
|
|
|
|
1995-10-18 01:37:01 -07:00
|
|
|
typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
|
|
|
|
const u_char *);
|
|
|
|
|
2004-06-24 11:29:38 -07:00
|
|
|
__BEGIN_DECLS
|
1995-10-18 01:37:01 -07:00
|
|
|
char *pcap_lookupdev(char *);
|
2006-03-26 12:58:50 -08:00
|
|
|
int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
|
Import a number of core functions from libpcap-1.2.0 while preserving
local changes: strncpy() -> strlcpy(), malloc(x * y) -> calloc(x, y),
exclude cross-platform cruft, etc.
The new functions are pcap_create(), pcap_set_snaplen(),
pcap_set_promisc(), pcap_can_set_rfmon(), pcap_set_rfmon(),
pcap_set_timeout(), pcap_set_buffer_size(), pcap_activate(), and
pcap_statustostr().
This diff was tested on amd64, i386, macppc, and sparc64, where
regression tests were done on various pcap-based ports (especially amd64
and i386 where regression tests were run on all pcap-based ports).
Testers also tried running pcap-based ports that they are familiar with
to ensure that there is no behavioral change. tcpdump and pflogd in
base were also tested by different testers. The new pcap_* functions
were tested with a proof-of-concept Snort 2.9 port for many months.
Thank you to everyone who helped test this diff and provided feedback:
haesbaert@, sthen@, matthew@, gonzalo@, brett@, Rodolfo Gouveia,
Aaron Bieber, Markus Lude, and Ray Percival.
ok haesbaert sthen henning
2012-05-24 18:58:08 -07:00
|
|
|
|
|
|
|
pcap_t *pcap_create(const char *, char *);
|
|
|
|
int pcap_set_snaplen(pcap_t *, int);
|
|
|
|
int pcap_set_promisc(pcap_t *, int);
|
|
|
|
int pcap_can_set_rfmon(pcap_t *);
|
|
|
|
int pcap_set_rfmon(pcap_t *, int);
|
|
|
|
int pcap_set_timeout(pcap_t *, int);
|
2018-04-04 20:47:27 -07:00
|
|
|
int pcap_set_immediate_mode(pcap_t *, int);
|
Import a number of core functions from libpcap-1.2.0 while preserving
local changes: strncpy() -> strlcpy(), malloc(x * y) -> calloc(x, y),
exclude cross-platform cruft, etc.
The new functions are pcap_create(), pcap_set_snaplen(),
pcap_set_promisc(), pcap_can_set_rfmon(), pcap_set_rfmon(),
pcap_set_timeout(), pcap_set_buffer_size(), pcap_activate(), and
pcap_statustostr().
This diff was tested on amd64, i386, macppc, and sparc64, where
regression tests were done on various pcap-based ports (especially amd64
and i386 where regression tests were run on all pcap-based ports).
Testers also tried running pcap-based ports that they are familiar with
to ensure that there is no behavioral change. tcpdump and pflogd in
base were also tested by different testers. The new pcap_* functions
were tested with a proof-of-concept Snort 2.9 port for many months.
Thank you to everyone who helped test this diff and provided feedback:
haesbaert@, sthen@, matthew@, gonzalo@, brett@, Rodolfo Gouveia,
Aaron Bieber, Markus Lude, and Ray Percival.
ok haesbaert sthen henning
2012-05-24 18:58:08 -07:00
|
|
|
int pcap_set_buffer_size(pcap_t *, int);
|
|
|
|
int pcap_activate(pcap_t *);
|
|
|
|
|
2005-11-18 03:05:38 -08:00
|
|
|
pcap_t *pcap_open_live(const char *, int, int, int, char *);
|
|
|
|
pcap_t *pcap_open_dead(int, int);
|
2006-03-26 12:58:50 -08:00
|
|
|
pcap_t *pcap_open_offline(const char *, char *);
|
|
|
|
pcap_t *pcap_fopen_offline(FILE *, char *);
|
1995-10-18 01:37:01 -07:00
|
|
|
void pcap_close(pcap_t *);
|
|
|
|
int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
|
|
|
|
int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
|
|
|
|
const u_char*
|
|
|
|
pcap_next(pcap_t *, struct pcap_pkthdr *);
|
2006-03-26 12:58:50 -08:00
|
|
|
int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
|
|
|
|
void pcap_breakloop(pcap_t *);
|
1995-10-18 01:37:01 -07:00
|
|
|
int pcap_stats(pcap_t *, struct pcap_stat *);
|
|
|
|
int pcap_setfilter(pcap_t *, struct bpf_program *);
|
2006-03-26 12:58:50 -08:00
|
|
|
int pcap_setdirection(pcap_t *, pcap_direction_t);
|
2005-11-18 03:05:38 -08:00
|
|
|
int pcap_getnonblock(pcap_t *, char *);
|
|
|
|
int pcap_setnonblock(pcap_t *, int, char *);
|
2018-06-03 03:29:28 -07:00
|
|
|
void pcap_perror(pcap_t *, const char *);
|
2006-03-26 12:58:50 -08:00
|
|
|
int pcap_inject(pcap_t *, const void *, size_t);
|
|
|
|
int pcap_sendpacket(pcap_t *, const u_char *, int);
|
Import a number of core functions from libpcap-1.2.0 while preserving
local changes: strncpy() -> strlcpy(), malloc(x * y) -> calloc(x, y),
exclude cross-platform cruft, etc.
The new functions are pcap_create(), pcap_set_snaplen(),
pcap_set_promisc(), pcap_can_set_rfmon(), pcap_set_rfmon(),
pcap_set_timeout(), pcap_set_buffer_size(), pcap_activate(), and
pcap_statustostr().
This diff was tested on amd64, i386, macppc, and sparc64, where
regression tests were done on various pcap-based ports (especially amd64
and i386 where regression tests were run on all pcap-based ports).
Testers also tried running pcap-based ports that they are familiar with
to ensure that there is no behavioral change. tcpdump and pflogd in
base were also tested by different testers. The new pcap_* functions
were tested with a proof-of-concept Snort 2.9 port for many months.
Thank you to everyone who helped test this diff and provided feedback:
haesbaert@, sthen@, matthew@, gonzalo@, brett@, Rodolfo Gouveia,
Aaron Bieber, Markus Lude, and Ray Percival.
ok haesbaert sthen henning
2012-05-24 18:58:08 -07:00
|
|
|
const char *pcap_statustostr(int);
|
2018-06-03 03:29:28 -07:00
|
|
|
const char *pcap_strerror(int);
|
1995-10-18 01:37:01 -07:00
|
|
|
char *pcap_geterr(pcap_t *);
|
2018-06-03 03:29:28 -07:00
|
|
|
int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
|
1996-07-12 06:19:06 -07:00
|
|
|
bpf_u_int32);
|
2000-04-26 14:25:52 -07:00
|
|
|
int pcap_compile_nopcap(int, int, struct bpf_program *,
|
2018-06-03 03:29:28 -07:00
|
|
|
const char *, int, bpf_u_int32);
|
2001-12-17 14:29:47 -08:00
|
|
|
void pcap_freecode(struct bpf_program *);
|
2016-04-06 01:02:56 -07:00
|
|
|
int pcap_offline_filter(const struct bpf_program *,
|
|
|
|
const struct pcap_pkthdr *, const u_char *);
|
1995-10-18 01:37:01 -07:00
|
|
|
int pcap_datalink(pcap_t *);
|
2005-11-18 03:05:38 -08:00
|
|
|
int pcap_list_datalinks(pcap_t *, int **);
|
|
|
|
int pcap_set_datalink(pcap_t *, int);
|
2016-04-06 01:02:56 -07:00
|
|
|
void pcap_free_datalinks(int *);
|
2005-11-18 03:05:38 -08:00
|
|
|
int pcap_datalink_name_to_val(const char *);
|
|
|
|
const char *pcap_datalink_val_to_name(int);
|
|
|
|
const char *pcap_datalink_val_to_description(int);
|
1995-10-18 01:37:01 -07:00
|
|
|
int pcap_snapshot(pcap_t *);
|
|
|
|
int pcap_is_swapped(pcap_t *);
|
|
|
|
int pcap_major_version(pcap_t *);
|
|
|
|
int pcap_minor_version(pcap_t *);
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
FILE *pcap_file(pcap_t *);
|
|
|
|
int pcap_fileno(pcap_t *);
|
|
|
|
|
1999-07-19 21:49:54 -07:00
|
|
|
pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
|
2006-03-26 12:58:50 -08:00
|
|
|
pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
|
|
|
|
FILE *pcap_dump_file(pcap_dumper_t *);
|
|
|
|
long pcap_dump_ftell(pcap_dumper_t *);
|
|
|
|
int pcap_dump_flush(pcap_dumper_t *);
|
1995-10-18 01:37:01 -07:00
|
|
|
void pcap_dump_close(pcap_dumper_t *);
|
|
|
|
void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
|
|
|
|
|
2005-11-18 03:05:38 -08:00
|
|
|
int pcap_findalldevs(pcap_if_t **, char *);
|
|
|
|
void pcap_freealldevs(pcap_if_t *);
|
|
|
|
|
2006-03-26 12:58:50 -08:00
|
|
|
const char *pcap_lib_version(void);
|
|
|
|
|
2018-06-03 03:29:28 -07:00
|
|
|
char *bpf_image(const struct bpf_insn *, int);
|
2006-03-26 12:58:50 -08:00
|
|
|
|
|
|
|
int pcap_get_selectable_fd(pcap_t *);
|
|
|
|
|
2004-06-24 11:29:38 -07:00
|
|
|
__END_DECLS
|
1995-10-18 01:37:01 -07:00
|
|
|
#endif
|