diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2006-03-26 20:58:52 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2006-03-26 20:58:52 +0000 |
commit | 9abeba6a9640964dca82b6116b6410eb404ef725 (patch) | |
tree | 3175d7fa482f202499efa111b6f4df7df9c0baf4 /lib/libpcap/pcap-bpf.c | |
parent | de2969b748faebff4bd8661c93932a2522f4363b (diff) |
add remaining tcpdump.org libpcap 0.9 APIs, most notably
pcap_setdirection() (which depends on the kernel-side bpf changes
committed yesterday); ok canacar@
Diffstat (limited to 'lib/libpcap/pcap-bpf.c')
-rw-r--r-- | lib/libpcap/pcap-bpf.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c index 60b5cc7b140..bc988b1325f 100644 --- a/lib/libpcap/pcap-bpf.c +++ b/lib/libpcap/pcap-bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap-bpf.c,v 1.19 2006/01/16 22:45:57 reyk Exp $ */ +/* $OpenBSD: pcap-bpf.c,v 1.20 2006/03/26 20:58:51 djm Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1998 @@ -170,6 +170,13 @@ pcap_inject(pcap_t *p, const void *buf, size_t len) return (write(p->fd, buf, len)); } +int +pcap_sendpacket(pcap_t *p, const u_char *buf, int size) +{ + return (pcap_inject(p, buf, size) == -1 ? -1 : 0); +} + +/* ARGSUSED */ static __inline int bpf_open(pcap_t *p, char *errbuf) { @@ -340,7 +347,7 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, int pcap_setfilter(pcap_t *p, struct bpf_program *fp) { - int buflen; + size_t buflen; /* * It looks that BPF code generated by gen_protochain() is not * compatible with some of kernel BPF code (for example BSD/OS 3.1). @@ -367,6 +374,33 @@ pcap_setfilter(pcap_t *p, struct bpf_program *fp) } int +pcap_setdirection(pcap_t *p, pcap_direction_t d) +{ + u_int dirfilt; + + switch (d) { + case PCAP_D_INOUT: + dirfilt = 0; + break; + case PCAP_D_IN: + dirfilt = BPF_DIRECTION_OUT; + break; + case PCAP_D_OUT: + dirfilt = BPF_DIRECTION_IN; + break; + default: + snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Invalid direction"); + return (-1); + } + if (ioctl(p->fd, BIOCSDIRFILT, &dirfilt) < 0) { + snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSDIRFILT: %s", + pcap_strerror(errno)); + return (-1); + } + return (0); +} + +int pcap_set_datalink(pcap_t *p, int dlt) { int i; |