merge conflicts

This commit is contained in:
christos 2015-03-31 21:39:42 +00:00
parent f907ecca40
commit bd64c25012
61 changed files with 3060 additions and 1750 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bpf_filter.c,v 1.5 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: bpf_filter.c,v 1.6 2015/03/31 21:39:42 christos Exp $ */
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -188,10 +188,25 @@ m_xhalf(const struct mbuf *m, uint32_t k, int *err)
}
#endif
#ifdef __linux__
#include <linux/types.h>
#include <linux/if_packet.h>
#include <linux/filter.h>
#endif
enum {
BPF_S_ANC_NONE,
BPF_S_ANC_VLAN_TAG,
BPF_S_ANC_VLAN_TAG_PRESENT,
};
/*
* Execute the filter program starting at pc on the packet p
* wirelen is the length of the original packet
* buflen is the amount of data present
* aux_data is auxiliary data, currently used only when interpreting
* filters intended for the Linux kernel in cases where the kernel
* rejects the filter; it contains VLAN tag information
* For the kernel, p is assumed to be a pointer to an mbuf if buflen is 0,
* in all other cases, p is a pointer to a buffer and buflen is its size.
*/
@ -199,8 +214,9 @@ u_int
bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
u_int buflen)
{
u_int32 A, X, k;
int32 mem[BPF_MEMWORDS];
register u_int32 A, X;
register bpf_u_int32 k;
u_int32 mem[BPF_MEMWORDS];
#if defined(KERNEL) || defined(_KERNEL)
struct mbuf *m, *n;
int merr, len;
@ -240,7 +256,7 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
case BPF_LD|BPF_W|BPF_ABS:
k = pc->k;
if (k + sizeof(int32) > buflen) {
if (k > buflen || sizeof(int32_t) > buflen - k) {
#if defined(KERNEL) || defined(_KERNEL)
if (m == NULL)
return 0;
@ -257,7 +273,7 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
case BPF_LD|BPF_H|BPF_ABS:
k = pc->k;
if (k + sizeof(short) > buflen) {
if (k > buflen || sizeof(int16_t) > buflen - k) {
#if defined(KERNEL) || defined(_KERNEL)
if (m == NULL)
return 0;
@ -273,22 +289,50 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
continue;
case BPF_LD|BPF_B|BPF_ABS:
k = pc->k;
if (k >= (int)buflen) {
#if defined(KERNEL) || defined(_KERNEL)
if (m == NULL)
return 0;
n = m;
MINDEX(len, n, k);
A = mtod(n, u_char *)[k];
continue;
#else
return 0;
#endif
}
A = p[k];
continue;
{
#if defined(SKF_AD_VLAN_TAG) && defined(SKF_AD_VLAN_TAG_PRESENT)
int code = BPF_S_ANC_NONE;
#define ANCILLARY(CODE) case SKF_AD_OFF + SKF_AD_##CODE: \
code = BPF_S_ANC_##CODE; \
if (!aux_data) \
return 0; \
break;
switch (pc->k) {
ANCILLARY(VLAN_TAG);
ANCILLARY(VLAN_TAG_PRESENT);
default :
#endif
k = pc->k;
if (k >= (int)buflen) {
#if defined(KERNEL) || defined(_KERNEL)
if (m == NULL)
return 0;
n = m;
MINDEX(len, n, k);
A = mtod(n, u_char *)[k];
continue;
#else
return 0;
#endif
}
A = p[k];
#if defined(SKF_AD_VLAN_TAG) && defined(SKF_AD_VLAN_TAG_PRESENT)
}
switch (code) {
case BPF_S_ANC_VLAN_TAG:
if (aux_data)
A = aux_data->vlan_tag;
break;
case BPF_S_ANC_VLAN_TAG_PRESENT:
if (aux_data)
A = aux_data->vlan_tag_present;
break;
}
#endif
continue;
}
case BPF_LD|BPF_W|BPF_LEN:
A = wirelen;
continue;
@ -299,7 +343,8 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
case BPF_LD|BPF_W|BPF_IND:
k = X + pc->k;
if (k + sizeof(int32) > buflen) {
if (pc->k > buflen || X > buflen - pc->k ||
sizeof(int32_t) > buflen - k) {
#if defined(KERNEL) || defined(_KERNEL)
if (m == NULL)
return 0;
@ -316,7 +361,8 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
case BPF_LD|BPF_H|BPF_IND:
k = X + pc->k;
if (k + sizeof(short) > buflen) {
if (X > buflen || pc->k > buflen - X ||
sizeof(int16_t) > buflen - k) {
#if defined(KERNEL) || defined(_KERNEL)
if (m == NULL)
return 0;
@ -333,7 +379,7 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
case BPF_LD|BPF_B|BPF_IND:
k = X + pc->k;
if (k >= (int)buflen) {
if (pc->k >= (int)buflen || X >= buflen - pc->k) {
#if defined(KERNEL) || defined(_KERNEL)
if (m == NULL)
return 0;
@ -535,6 +581,17 @@ bpf_filter(const struct bpf_insn *pc, const u_char *p, u_int wirelen,
}
}
u_int
bpf_filter(pc, p, wirelen, buflen)
register const struct bpf_insn *pc;
register const u_char *p;
u_int wirelen;
register u_int buflen;
{
return bpf_filter_with_aux_data(pc, p, wirelen, buflen, NULL);
}
/*
* Return true if the 'fcode' is a valid filter program.
* The constraints are that each jump be forward and to a valid

View File

@ -1,4 +1,4 @@
/* $NetBSD: fad-gifc.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: fad-gifc.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
/*
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: fad-gifc.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: fad-gifc.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -222,12 +222,12 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
/*
* XXX - The 32-bit compatibility layer for Linux on IA-64
* is slightly broken. It correctly converts the structures
* to and from kernel land from 64 bit to 32 bit but
* doesn't update ifc.ifc_len, leaving it larger than the
* amount really used. This means we read off the end
* of the buffer and encounter an interface with an
* "empty" name. Since this is highly unlikely to ever
* occur in a valid case we can just finish looking for
* to and from kernel land from 64 bit to 32 bit but
* doesn't update ifc.ifc_len, leaving it larger than the
* amount really used. This means we read off the end
* of the buffer and encounter an interface with an
* "empty" name. Since this is highly unlikely to ever
* occur in a valid case we can just finish looking for
* interfaces if we see an empty name.
*/
if (!(*ifrp->ifr_name))

View File

@ -1,4 +1,4 @@
/* $NetBSD: fad-win32.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: fad-win32.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
@ -14,9 +14,9 @@
* 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. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: fad-win32.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: fad-win32.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -132,7 +132,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
char *AdaptersName;
ULONG NameLength;
char *name;
/*
* Find out how big a buffer we need.
*
@ -175,7 +175,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Cannot allocate enough memory to list the adapters.");
return (-1);
}
}
if (!PacketGetAdapterNames(AdaptersName, &NameLength)) {
snprintf(errbuf, PCAP_ERRBUF_SIZE,
@ -184,7 +184,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
free(AdaptersName);
return (-1);
}
/*
* "PacketGetAdapterNames()" returned a list of
* null-terminated ASCII interface name strings,
@ -200,7 +200,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
desc = &AdaptersName[0];
while (*desc != '\0' || *(desc + 1) != '\0')
desc++;
/*
* Found it - "desc" points to the first of the two
* nulls at the end of the list of names, so the
@ -208,7 +208,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
* after it.
*/
desc += 2;
/*
* Loop over the elements in the first list.
*/
@ -236,7 +236,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
if (pcap_platform_finddevs(&devlist, errbuf) < 0)
ret = -1;
}
if (ret == -1) {
/*
* We had an error; free the list we've been constructing.
@ -246,7 +246,7 @@ pcap_findalldevs_interfaces(pcap_if_t **alldevsp, char *errbuf)
devlist = NULL;
}
}
*alldevsp = devlist;
free(AdaptersName);
return (ret);

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: gencode.h,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: gencode.h,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@ -163,7 +163,7 @@
#define A_CONNECTACK 44 /* Connect Ack message */
#define A_RELEASE 45 /* Release message */
#define A_RELEASE_DONE 46 /* Release message */
/* ATM field types */
#define A_VPI 51
#define A_VCI 52
@ -296,9 +296,9 @@ void gen_not(struct block *);
struct block *gen_scode(const char *, struct qual);
struct block *gen_ecode(const u_char *, struct qual);
struct block *gen_acode(const u_char *, struct qual);
struct block *gen_mcode(const char *, const char *, int, struct qual);
struct block *gen_mcode(const char *, const char *, unsigned int, struct qual);
#ifdef INET6
struct block *gen_mcode6(const char *, const char *, int, struct qual);
struct block *gen_mcode6(const char *, const char *, unsigned int, struct qual);
#endif
struct block *gen_ncode(const char *, bpf_u_int32, struct qual);
struct block *gen_proto_abbrev(int);
@ -323,6 +323,8 @@ struct block *gen_mpls(int);
struct block *gen_pppoed(void);
struct block *gen_pppoes(int);
struct block *gen_geneve(int);
struct block *gen_atmfield_code(int atmfield, bpf_int32 jvalue, bpf_u_int32 jtype, int reverse);
struct block *gen_atmtype_abbrev(int type);
struct block *gen_atmmulti_abbrev(int type);

View File

@ -1,4 +1,4 @@
/* $NetBSD: grammar.y,v 1.5 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: grammar.y,v 1.6 2015/03/31 21:39:42 christos Exp $ */
%{
/*
@ -23,7 +23,7 @@
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: grammar.y,v 1.5 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: grammar.y,v 1.6 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -303,8 +303,8 @@ pfaction_to_num(const char *action)
%token LEN
%token IPV6 ICMPV6 AH ESP
%token VLAN MPLS
%token PPPOED PPPOES
%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
%token PPPOED PPPOES GENEVE
%token ISO ESIS CLNP ISIS L1 L2 IIH LSP SNP CSNP PSNP
%token STP
%token IPX
%token NETBEUI
@ -314,7 +314,7 @@ pfaction_to_num(const char *action)
%token RADIO
%token FISU LSSU MSU HFISU HLSSU HMSU
%token SIO OPC DPC SLS HSIO HOPC HDPC HSLS
%type <s> ID
%type <e> EID
@ -390,7 +390,7 @@ nid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
"in this configuration");
#endif /*INET6*/
}
| EID {
| EID {
$$.b = gen_ecode($1, $$.q = $<blk>0.q);
/*
* $1 was allocated by "pcap_ether_aton()",
@ -527,6 +527,8 @@ other: pqual TK_BROADCAST { $$ = gen_broadcast($1); }
| PPPOED { $$ = gen_pppoed(); }
| PPPOES pnum { $$ = gen_pppoes($2); }
| PPPOES { $$ = gen_pppoes(-1); }
| GENEVE pnum { $$ = gen_geneve($2); }
| GENEVE { $$ = gen_geneve(-1); }
| pfvar { $$ = $1; }
| pqual p80211 { $$ = $2; }
| pllc { $$ = $1; }

View File

@ -1,4 +1,4 @@
/* $NetBSD: inet.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: inet.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
/*
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: inet.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: inet.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -577,7 +577,8 @@ get_if_description(const char *name)
* Try to get a description for a given device, and then look for that
* device in the specified list of devices.
*
* If we find it, add the specified address to it and return 0.
* If we find it, then, if the specified address isn't null, add it to
* the list of addresses for the device and return 0.
*
* If we don't find it, check whether we can open it:
*
@ -588,9 +589,17 @@ get_if_description(const char *name)
*
* Otherwise, attempt to add an entry for it, with the specified
* ifnet flags and description, and, if that succeeds, add the
* specified address to it, set *curdev_ret to point to the new
* entry, and return 0, otherwise return PCAP_ERROR and set errbuf
* to an error message.
* specified address to its list of addresses if that address is
* non-null, set *curdev_ret to point to the new entry, and
* return 0, otherwise return PCAP_ERROR and set errbuf to an
* error message.
*
* (We can get called with a null address because we might get a list
* of interface name/address combinations from the underlying OS, with
* the address being absent in some cases, rather than a list of
* interfaces with each interface having a list of addresses, so this
* call may be the only call made to add to the list, and we want to
* add interfaces even if they have no addresses.)
*/
int
add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
@ -621,14 +630,24 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
return (0);
}
if (addr == NULL) {
/*
* There's no address to add; this entry just meant
* "here's a new interface".
*/
return (0);
}
/*
* "curdev" is an entry for this interface; add an entry for this
* address to its list of addresses.
* "curdev" is an entry for this interface, and we have an
* address for it; add an entry for that address to the
* interface's list of addresses.
*
* Allocate the new entry and fill it in.
*/
return (add_addr_to_dev(curdev, addr, addr_size, netmask, netmask_size,
broadaddr, broadaddr_size, dstaddr, dstaddr_size, errbuf));
return (add_addr_to_dev(curdev, addr, addr_size, netmask,
netmask_size, broadaddr, broadaddr_size, dstaddr,
dstaddr_size, errbuf));
}
/*
@ -910,7 +929,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
/* XXX Work around Linux kernel bug */
ifr.ifr_addr.sa_family = AF_INET;
#endif
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
(void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
if (errno == EADDRNOTAVAIL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
@ -930,7 +949,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
/* XXX Work around Linux kernel bug */
ifr.ifr_addr.sa_family = AF_INET;
#endif
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
(void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"SIOCGIFNETMASK: %s: %s", device, pcap_strerror(errno));

View File

@ -1,4 +1,4 @@
/* $NetBSD: os-osf4.h,v 1.2 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: os-osf4.h,v 1.3 2015/03/31 21:39:43 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@ -25,4 +25,4 @@
int snprintf(char *, size_t, const char *, ...);
int vsnprintf(char *, size_t, const char *, va_list);
int pfopen(char *, int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: os-osf5.h,v 1.2 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: os-osf5.h,v 1.3 2015/03/31 21:39:43 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@ -29,4 +29,4 @@
int snprintf(char *, size_t, const char *, ...);
int vsnprintf(char *, size_t, const char *, va_list);
int pfopen(char *, int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: optimize.c,v 1.7 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: optimize.c,v 1.8 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
@ -24,7 +24,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: optimize.c,v 1.7 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: optimize.c,v 1.8 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -2249,7 +2249,92 @@ install_bpf_program(pcap_t *p, struct bpf_program *fp)
#ifdef BDEBUG
static void
opt_dump(struct block *root)
dot_dump_node(struct block *block, struct bpf_program *prog, FILE *out)
{
int icount, noffset;
int i;
if (block == NULL || isMarked(block))
return;
Mark(block);
icount = slength(block->stmts) + 1 + block->longjt + block->longjf;
noffset = min(block->offset + icount, (int)prog->bf_len);
fprintf(out, "\tblock%d [shape=ellipse, id=\"block-%d\" label=\"BLOCK%d\\n", block->id, block->id, block->id);
for (i = block->offset; i < noffset; i++) {
fprintf(out, "\\n%s", bpf_image(prog->bf_insns + i, i));
}
fprintf(out, "\" tooltip=\"");
for (i = 0; i < BPF_MEMWORDS; i++)
if (block->val[i] != 0)
fprintf(out, "val[%d]=%d ", i, block->val[i]);
fprintf(out, "val[A]=%d ", block->val[A_ATOM]);
fprintf(out, "val[X]=%d", block->val[X_ATOM]);
fprintf(out, "\"");
if (JT(block) == NULL)
fprintf(out, ", peripheries=2");
fprintf(out, "];\n");
dot_dump_node(JT(block), prog, out);
dot_dump_node(JF(block), prog, out);
}
static void
dot_dump_edge(struct block *block, FILE *out)
{
if (block == NULL || isMarked(block))
return;
Mark(block);
if (JT(block)) {
fprintf(out, "\t\"block%d\":se -> \"block%d\":n [label=\"T\"]; \n",
block->id, JT(block)->id);
fprintf(out, "\t\"block%d\":sw -> \"block%d\":n [label=\"F\"]; \n",
block->id, JF(block)->id);
}
dot_dump_edge(JT(block), out);
dot_dump_edge(JF(block), out);
}
/* Output the block CFG using graphviz/DOT language
* In the CFG, block's code, value index for each registers at EXIT,
* and the jump relationship is show.
*
* example DOT for BPF `ip src host 1.1.1.1' is:
digraph BPF {
block0 [shape=ellipse, id="block-0" label="BLOCK0\n\n(000) ldh [12]\n(001) jeq #0x800 jt 2 jf 5" tooltip="val[A]=0 val[X]=0"];
block1 [shape=ellipse, id="block-1" label="BLOCK1\n\n(002) ld [26]\n(003) jeq #0x1010101 jt 4 jf 5" tooltip="val[A]=0 val[X]=0"];
block2 [shape=ellipse, id="block-2" label="BLOCK2\n\n(004) ret #68" tooltip="val[A]=0 val[X]=0", peripheries=2];
block3 [shape=ellipse, id="block-3" label="BLOCK3\n\n(005) ret #0" tooltip="val[A]=0 val[X]=0", peripheries=2];
"block0":se -> "block1":n [label="T"];
"block0":sw -> "block3":n [label="F"];
"block1":se -> "block2":n [label="T"];
"block1":sw -> "block3":n [label="F"];
}
*
* After install graphviz on http://www.graphviz.org/, save it as bpf.dot
* and run `dot -Tpng -O bpf.dot' to draw the graph.
*/
static void
dot_dump(struct block *root)
{
struct bpf_program f;
FILE *out = stdout;
memset(bids, 0, sizeof bids);
f.bf_insns = icode_to_fcode(root, &f.bf_len);
fprintf(out, "digraph BPF {\n");
unMarkAll();
dot_dump_node(root, &f, out);
unMarkAll();
dot_dump_edge(root, out);
fprintf(out, "}\n");
free((char *)f.bf_insns);
}
static void
plain_dump(struct block *root)
{
struct bpf_program f;
@ -2259,4 +2344,17 @@ opt_dump(struct block *root)
putchar('\n');
free((char *)f.bf_insns);
}
static void
opt_dump(struct block *root)
{
/* if optimizer debugging is enabled, output DOT graph
* `dflag=4' is equivalent to -dddd to follow -d/-dd/-ddd
* convention in tcpdump command line
*/
if (dflag > 3)
dot_dump(root);
else
plain_dump(root);
}
#endif

View File

@ -1,77 +0,0 @@
%define prefix /usr
%define version @VERSION@
Summary: A system-independent interface for user-level packet capture
Name: libpcap
Version: %version
Release: 1
Group: Development/Libraries
License: BSD with advertising
Source: @NAME@.tar.gz
BuildRoot: /tmp/%{name}-buildroot
URL: http://www.tcpdump.org
Source: http://www.tcpdump.org/release/%{name}-%{version}.tar.gz
%description
Libpcap provides a portable framework for low-level network
monitoring. Libpcap can provide network statistics collection,
security monitoring and network debugging. Since almost every system
vendor provides a different interface for packet capture, the libpcap
authors created this system-independent API to ease in porting and to
alleviate the need for several system-dependent packet capture modules
in each application.
Install libpcap if you need to do low-level network traffic monitoring
on your network.
%package devel
Summary: Libraries and header files for the libpcap library
Group: Development/Libraries
%description devel
Libpcap provides a portable framework for low-level network
monitoring. Libpcap can provide network statistics collection,
security monitoring and network debugging. Since almost every system
vendor provides a different interface for packet capture, the libpcap
authors created this system-independent API to ease in porting and to
alleviate the need for several system-dependent packet capture modules
in each application.
This package provides the libraries, include files, and other
resources needed for developing libpcap applications.
%prep
%setup -q
%build
export CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing"
%configure
make %{?_smp_mflags}
%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc LICENSE README CHANGES INSTALL.txt README.linux TODO VERSION CREDITS packaging/pcap.spec
%{_libdir}/libpcap.so.*
%{_mandir}/man7/pcap*.7*
%files devel
%defattr(-,root,root)
%{_bindir}/pcap-config
%{_includedir}/pcap/*.h
%{_includedir}/pcap.h
%{_includedir}/pcap-bpf.h
%{_includedir}/pcap-namedb.h
%{_libdir}/libpcap.so
%{_libdir}/libpcap.a
%{_mandir}/man1/pcap-config.1*
%{_mandir}/man3/pcap*.3*
%{_mandir}/man5/pcap*.5*

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-bpf.c,v 1.5 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-bpf.c,v 1.6 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1998
@ -22,7 +22,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-bpf.c,v 1.5 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-bpf.c,v 1.6 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -243,7 +243,7 @@ static int pcap_set_datalink_bpf(pcap_t *p, int dlt);
*/
static int
pcap_getnonblock_bpf(pcap_t *p, char *errbuf)
{
{
#ifdef HAVE_ZEROCOPY_BPF
struct pcap_bpf *pb = p->priv;
@ -255,7 +255,7 @@ pcap_getnonblock_bpf(pcap_t *p, char *errbuf)
static int
pcap_setnonblock_bpf(pcap_t *p, int nonblock, char *errbuf)
{
{
#ifdef HAVE_ZEROCOPY_BPF
struct pcap_bpf *pb = p->priv;
@ -1546,22 +1546,43 @@ pcap_activate_bpf(pcap_t *p)
#if defined(LIFNAMSIZ) && defined(ZONENAME_MAX) && defined(lifr_zoneid)
/*
* Check if the given source network device has a '/' separated
* zonename prefix string. The zonename prefixed source device
* can be used by libpcap consumers to capture network traffic
* in non-global zones from the global zone on Solaris 11 and
* above. If the zonename prefix is present then we strip the
* prefix and pass the zone ID as part of lifr_zoneid.
* Retrieve the zoneid of the zone we are currently executing in.
*/
if ((ifr.lifr_zoneid = getzoneid()) == -1) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "getzoneid(): %s",
pcap_strerror(errno));
status = PCAP_ERROR;
goto bad;
}
/*
* Check if the given source datalink name has a '/' separated
* zonename prefix string. The zonename prefixed source datalink can
* be used by pcap consumers in the Solaris global zone to capture
* traffic on datalinks in non-global zones. Non-global zones
* do not have access to datalinks outside of their own namespace.
*/
if ((zonesep = strchr(p->opt.source, '/')) != NULL) {
char zonename[ZONENAME_MAX];
char path_zname[ZONENAME_MAX];
int znamelen;
char *lnamep;
if (ifr.lifr_zoneid != GLOBAL_ZONEID) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"zonename/linkname only valid in global zone.");
status = PCAP_ERROR;
goto bad;
}
znamelen = zonesep - p->opt.source;
(void) strlcpy(zonename, p->opt.source, znamelen + 1);
(void) strlcpy(path_zname, p->opt.source, znamelen + 1);
ifr.lifr_zoneid = getzoneidbyname(path_zname);
if (ifr.lifr_zoneid == -1) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"getzoneidbyname(%s): %s", path_zname,
pcap_strerror(errno));
status = PCAP_ERROR;
goto bad;
}
lnamep = strdup(zonesep + 1);
ifr.lifr_zoneid = getzoneidbyname(zonename);
free(p->opt.source);
p->opt.source = lnamep;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-bpf.h,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-bpf.h,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -6,7 +6,7 @@
*
* This code is derived from the Stanford/CMU enet packet filter,
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* Redistribution and use in source and binary forms, with or without

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-bt-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-bt-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -33,9 +33,8 @@
* By Paolo Abeni <paolo.abeni@email.it>
*
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-bt-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-bt-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -78,7 +77,7 @@ struct pcap_bt {
int dev_id; /* device ID of device we're bound to */
};
int
int
bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
struct hci_dev_list_req *dev_list;
@ -89,7 +88,7 @@ bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (sock < 0)
{
/* if bluetooth is not supported this this is not fatal*/
/* if bluetooth is not supported this this is not fatal*/
if (errno == EAFNOSUPPORT)
return 0;
snprintf(err_str, PCAP_ERRBUF_SIZE,
@ -98,7 +97,7 @@ bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
}
dev_list = malloc(HCI_MAX_DEV * sizeof(*dev_req) + sizeof(*dev_list));
if (!dev_list)
if (!dev_list)
{
snprintf(err_str, PCAP_ERRBUF_SIZE, "Can't allocate %zu bytes for Bluetooth device list",
HCI_MAX_DEV * sizeof(*dev_req) + sizeof(*dev_list));
@ -108,7 +107,7 @@ bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
dev_list->dev_num = HCI_MAX_DEV;
if (ioctl(sock, HCIGETDEVLIST, (void *) dev_list) < 0)
if (ioctl(sock, HCIGETDEVLIST, (void *) dev_list) < 0)
{
snprintf(err_str, PCAP_ERRBUF_SIZE,
"Can't get Bluetooth device list via ioctl: %s",
@ -120,11 +119,11 @@ bt_findalldevs(pcap_if_t **alldevsp, char *err_str)
dev_req = dev_list->dev_req;
for (i = 0; i < dev_list->dev_num; i++, dev_req++) {
char dev_name[20], dev_descr[30];
snprintf(dev_name, 20, BT_IFACE"%d", dev_req->dev_id);
snprintf(dev_descr, 30, "Bluetooth adapter number %d", i);
if (pcap_add_if(alldevsp, dev_name, 0,
if (pcap_add_if(alldevsp, dev_name, 0,
dev_descr, err_str) < 0)
{
ret = -1;
@ -198,7 +197,7 @@ bt_activate(pcap_t* handle)
if (sscanf(handle->opt.source, BT_IFACE"%d", &dev_id) != 1)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't get Bluetooth device index from %s",
"Can't get Bluetooth device index from %s",
handle->opt.source);
return PCAP_ERROR;
}
@ -217,7 +216,7 @@ bt_activate(pcap_t* handle)
handle->setnonblock_op = pcap_setnonblock_fd;
handle->stats_op = bt_stats_linux;
handlep->dev_id = dev_id;
/* Create HCI socket */
handle->fd = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (handle->fd < 0) {
@ -247,10 +246,10 @@ bt_activate(pcap_t* handle)
goto close_fail;
}
/* Setup filter, do not call hci function to avoid dependence on
/* Setup filter, do not call hci function to avoid dependence on
* external libs */
memset(&flt, 0, sizeof(flt));
memset((void *) &flt.type_mask, 0xff, sizeof(flt.type_mask));
memset((void *) &flt.type_mask, 0xff, sizeof(flt.type_mask));
memset((void *) &flt.event_mask, 0xff, sizeof(flt.event_mask));
if (setsockopt(handle->fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
@ -314,7 +313,7 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
bthdr = (pcap_bluetooth_h4_header*) &handle->buffer[handle->offset];
iv.iov_base = &handle->buffer[handle->offset+sizeof(pcap_bluetooth_h4_header)];
iv.iov_len = handle->snapshot;
memset(&msg, 0, sizeof(msg));
msg.msg_iov = &iv;
msg.msg_iovlen = 1;
@ -339,7 +338,7 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
pkth.caplen = ret;
/* get direction and timestamp*/
/* get direction and timestamp*/
cmsg = CMSG_FIRSTHDR(&msg);
int in=0;
while (cmsg) {
@ -354,7 +353,7 @@ bt_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *us
}
cmsg = CMSG_NXTHDR(&msg, cmsg);
}
if ((in && (handle->direction == PCAP_D_OUT)) ||
if ((in && (handle->direction == PCAP_D_OUT)) ||
((!in) && (handle->direction == PCAP_D_IN)))
return 0;
@ -376,10 +375,10 @@ bt_inject_linux(pcap_t *handle, const void *buf, size_t size)
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on "
"bluetooth devices");
return (-1);
}
}
static int
static int
bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
{
struct pcap_bt *handlep = handle->priv;
@ -387,28 +386,28 @@ bt_stats_linux(pcap_t *handle, struct pcap_stat *stats)
struct hci_dev_info dev_info;
struct hci_dev_stats * s = &dev_info.stat;
dev_info.dev_id = handlep->dev_id;
/* ignore eintr */
do {
ret = ioctl(handle->fd, HCIGETDEVINFO, (void *)&dev_info);
} while ((ret == -1) && (errno == EINTR));
if (ret < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't get stats via ioctl: %s", strerror(errno));
return (-1);
}
/* we receive both rx and tx frames, so comulate all stats */
stats->ps_recv = s->evt_rx + s->acl_rx + s->sco_rx + s->cmd_tx +
/* we receive both rx and tx frames, so comulate all stats */
stats->ps_recv = s->evt_rx + s->acl_rx + s->sco_rx + s->cmd_tx +
s->acl_tx +s->sco_tx;
stats->ps_drop = s->err_rx + s->err_tx;
stats->ps_ifdrop = 0;
return 0;
}
static int
static int
bt_setdirection_linux(pcap_t *p, pcap_direction_t d)
{
p->direction = d;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-bt-linux.h,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-bt-linux.h,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-bt-monitor-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-bt-monitor-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2014 Michal Labedzki for Tieto Corporation
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-bt-monitor-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-bt-monitor-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -49,6 +49,8 @@ __RCSID("$NetBSD: pcap-bt-monitor-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp
#include "pcap/bluetooth.h"
#include "pcap-int.h"
#include "pcap-bt-monitor-linux.h"
#define BT_CONTROL_SIZE 32
#define INTERFACE_NAME "bluetooth-monitor"
@ -76,7 +78,6 @@ bt_monitor_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_ch
struct pcap_pkthdr pkth;
pcap_bluetooth_linux_monitor_header *bthdr;
struct mgmt_hdr hdr;
int in = 0;
bthdr = (pcap_bluetooth_linux_monitor_header*) &handle->buffer[handle->offset];

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-can-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-can-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2009 Felix Obenhuber
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-can-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-can-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -176,7 +176,7 @@ can_activate(pcap_t* handle)
/* get interface index */
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, handle->opt.source, sizeof(ifr.ifr_name));
strlcpy(ifr.ifr_name, handle->opt.source, sizeof(ifr.ifr_name));
if (ioctl(handle->fd, SIOCGIFINDEX, &ifr) < 0)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-canusb-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-canusb-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2009 Felix Obenhuber
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-canusb-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-canusb-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -46,6 +46,7 @@ __RCSID("$NetBSD: pcap-canusb-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $")
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>
@ -97,7 +98,7 @@ int canusb_findalldevs(pcap_if_t **alldevsp, char *err_str)
libusb_device** devs;
unsigned char sernum[65];
int cnt, i;
if (libusb_init(&fdctx) != 0) {
/*
* XXX - if this doesn't just mean "no USB file system mounted",
@ -105,7 +106,7 @@ int canusb_findalldevs(pcap_if_t **alldevsp, char *err_str)
* saying "no CANUSB devices".
*/
return 0;
}
}
cnt = libusb_get_device_list(fdctx,&devs);
@ -116,24 +117,24 @@ int canusb_findalldevs(pcap_if_t **alldevsp, char *err_str)
struct libusb_device_descriptor desc;
libusb_get_device_descriptor(devs[i],&desc);
if ((desc.idVendor != CANUSB_VID) || (desc.idProduct != CANUSB_PID))
if ((desc.idVendor != CANUSB_VID) || (desc.idProduct != CANUSB_PID))
continue; //It is not, check next device
//It is!
libusb_device_handle *dh = NULL;
if ((ret = libusb_open(devs[i],&dh)) == 0)
{
char dev_name[30];
char dev_descr[50];
char dev_descr[50];
int n = libusb_get_string_descriptor_ascii(dh,desc.iSerialNumber,sernum,64);
sernum[n] = 0;
snprintf(dev_name, 30, CANUSB_IFACE"%s", sernum);
snprintf(dev_descr, 50, "CanUSB [%s]", sernum);
libusb_close(dh);
if (pcap_add_if(alldevsp, dev_name, 0, dev_descr, err_str) < 0)
{
libusb_free_device_list(devs,1);
@ -153,18 +154,18 @@ static libusb_device_handle* canusb_opendevice(struct libusb_context *ctx, char*
libusb_device** devs;
unsigned char serial[65];
int cnt,i,n;
cnt = libusb_get_device_list(ctx,&devs);
for(i=0;i<cnt;i++)
{
{
// Check if this device is interesting.
struct libusb_device_descriptor desc;
libusb_get_device_descriptor(devs[i],&desc);
if ((desc.idVendor != CANUSB_VID) || (desc.idProduct != CANUSB_PID))
continue;
//Found one!
libusb_device_handle *dh = NULL;
@ -196,9 +197,9 @@ static libusb_device_handle* canusb_opendevice(struct libusb_context *ctx, char*
libusb_close(dh);
continue;
}
//Fount it!
libusb_free_device_list(devs,1);
libusb_free_device_list(devs,1);
return dh;
}
@ -209,7 +210,7 @@ static libusb_device_handle* canusb_opendevice(struct libusb_context *ctx, char*
pcap_t *
canusb_create(const char *device, char *ebuf, int *is_ours)
{
{
const char *cp;
char *cpend;
long devnum;
@ -263,30 +264,31 @@ static void* canusb_capture_thread(void *arg)
{
struct pcap_canusb *canusb = arg;
int i;
struct
struct
{
uint8_t rxsz, txsz;
} status;
fcntl(canusb->wrpipe, F_SETFL, O_NONBLOCK);
fcntl(canusb->wrpipe, F_SETFL, O_NONBLOCK);
while(canusb->loop)
{
int sz;
struct CAN_Msg msg;
libusb_interrupt_transfer(canusb->dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);
//HACK!!!!! -> drop buffered data, read new one by reading twice.
libusb_interrupt_transfer(canusb->dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);
//HACK!!!!! -> drop buffered data, read new one by reading twice.
libusb_interrupt_transfer(canusb->dev, 0x81, (unsigned char*)&status, sizeof(status), &sz, 100);
for(i = 0; i<status.rxsz; i++)
{
libusb_bulk_transfer(canusb->dev, 0x85, (unsigned char*)&msg, sizeof(msg), &sz, 100);
write(canusb->wrpipe, &msg, sizeof(msg));
libusb_bulk_transfer(canusb->dev, 0x85, (unsigned char*)&msg, sizeof(msg), &sz, 100);
if(write(canusb->wrpipe, &msg, sizeof(msg)) < 0)
fprintf(stderr,"write() error: %s\n", strerror(errno));
}
}
return NULL;
}
@ -300,7 +302,7 @@ static int canusb_startcapture(struct pcap_canusb* this)
this->rdpipe = pipefd[0];
this->wrpipe = pipefd[1];
this->loop = 1;
this->loop = 1;
pthread_create(&this->worker, NULL, canusb_capture_thread, this);
return this->rdpipe;
@ -315,7 +317,7 @@ static void canusb_clearbufs(struct pcap_canusb* this)
cmd[1] = 1; //Empty outgoing buffer
cmd[3] = 0; //Not a write to serial number
memset(&cmd[4],0,16-4);
libusb_interrupt_transfer(this->dev, 0x1,cmd,16,&al,100);
}
@ -331,7 +333,7 @@ static void canusb_close(pcap_t* handle)
{
libusb_close(canusb->dev);
canusb->dev = NULL;
}
}
if (canusb->ctx)
{
libusb_exit(canusb->ctx);
@ -350,9 +352,9 @@ static int canusb_activate(pcap_t* handle)
/*
* XXX - what causes this to fail?
*/
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "libusb_init() failed");
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "libusb_init() failed");
return PCAP_ERROR;
}
}
handle->read_op = canusb_read_linux;
@ -376,7 +378,7 @@ static int canusb_activate(pcap_t* handle)
if (!canusb->dev)
{
libusb_exit(canusb->ctx);
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't open USB Device");
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't open USB Device");
return PCAP_ERROR;
}
@ -398,7 +400,7 @@ canusb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char
int i = 0;
struct CAN_Msg msg;
struct pcap_pkthdr pkth;
while(i < max_packets)
{
int n;
@ -409,10 +411,10 @@ canusb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char
pkth.caplen = pkth.len = n;
pkth.caplen -= 4;
pkth.caplen -= 8 - msg.length;
if ((firstpacket.tv_sec == -1) && (firstpacket.tv_usec == -1))
gettimeofday(&firstpacket, NULL);
pkth.ts.tv_usec = firstpacket.tv_usec + (msg.timestamp % 100) * 10000;
pkth.ts.tv_sec = firstpacket.tv_usec + (msg.timestamp / 100);
if (pkth.ts.tv_usec > 1000000)
@ -424,7 +426,7 @@ canusb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char
callback(user, &pkth, (void*)&msg.id);
i++;
}
return i;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-common.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@ -24,7 +24,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-common.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -391,7 +391,7 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
* The Link Types are used for prepending meta-information
* like interface index, interface name
* before standard Ethernet, PPP, Frelay & C-HDLC Frames
@ -408,7 +408,7 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for internal communication with a
* voice Adapter Card (PIC)
*/
@ -483,7 +483,7 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for internal communication with a
* integrated service module (ISM).
*/
@ -524,7 +524,7 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for capturing data on a secure tunnel interface.
*/
#define LINKTYPE_JUNIPER_ST 200
@ -616,11 +616,11 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
*/
#define LINKTYPE_IEEE802_15_4_NONASK_PHY 215
/*
/*
* David Gibson <david@gibson.dropbear.id.au> requested this for
* captures from the Linux kernel /dev/input/eventN devices. This
* is used to communicate keystrokes and mouse movements from the
* Linux kernel to display systems, such as Xorg.
* Linux kernel to display systems, such as Xorg.
*/
#define LINKTYPE_LINUX_EVDEV 216
@ -782,7 +782,7 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
*/
#define LINKTYPE_JUNIPER_VS 232
#define LINKTYPE_JUNIPER_SRX_E2E 233
@ -814,12 +814,12 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
*/
#define LINKTYPE_JUNIPER_ATM_CEMIC 238
/*
* NetFilter LOG messages
* NetFilter LOG messages
* (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets)
*
* Requested by Jakub Zawadzki <darkjames-ws@darkjames.pl>
@ -927,7 +927,7 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
/*
* Link-layer header type for upper-protocol layer PDU saves from wireshark.
*
*
* the actual contents are determined by two TAGs stored with each
* packet:
* EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the
@ -999,7 +999,13 @@ __RCSID("$NetBSD: pcap-common.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
*/
#define LINKTYPE_IPMI_HPM_2 260
#define LINKTYPE_MATCHING_MAX 260 /* highest value in the "matching" range */
/*
* per Joshua Wright <jwright@hasborg.com>, formats for Zwave captures.
*/
#define LINKTYPE_ZWAVE_R1_R2 261
#define LINKTYPE_ZWAVE_R3 262
#define LINKTYPE_MATCHING_MAX 262 /* highest value in the "matching" range */
static struct linktype_map {
int dlt;
@ -1161,8 +1167,6 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
{
pcap_usb_header_mmapped *uhdr = (pcap_usb_header_mmapped *)buf;
bpf_u_int32 offset = 0;
usb_isodesc *pisodesc;
int32_t numdesc, i;
/*
* "offset" is the offset *past* the field we're swapping;
@ -1171,7 +1175,7 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
*/
/*
* The URB id is a totally opaque value; do we really need to
* The URB id is a totally opaque value; do we really need to
* convert it to the reading host's byte order???
*/
offset += 8; /* skip past id */
@ -1226,6 +1230,17 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
} else
offset += 8; /* skip USB setup header */
/*
* With the old header, there are no isochronous descriptors
* after the header.
*
* With the new header, the actual number of descriptors in
* the header is not s.iso.numdesc, it's ndesc - only the
* first N descriptors, for some value of N, are put into
* the header, and ndesc is set to the actual number copied.
* In addition, if s.iso.numdesc is negative, no descriptors
* are captured, and ndesc is set to 0.
*/
if (header_len_64_bytes) {
/*
* This is either the "version 1" header, with
@ -1254,31 +1269,33 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
if (hdr->caplen < offset)
return;
uhdr->ndesc = SWAPLONG(uhdr->ndesc);
}
if (uhdr->transfer_type == URB_ISOCHRONOUS) {
/* swap the values in struct linux_usb_isodesc */
pisodesc = (usb_isodesc *)(void *)(buf+offset);
numdesc = uhdr->s.iso.numdesc;
for (i = 0; i < numdesc; i++) {
offset += 4; /* skip past status */
if (hdr->caplen < offset)
return;
pisodesc->status = SWAPLONG(pisodesc->status);
if (uhdr->transfer_type == URB_ISOCHRONOUS) {
/* swap the values in struct linux_usb_isodesc */
usb_isodesc *pisodesc;
u_int32_t i;
offset += 4; /* skip past offset */
if (hdr->caplen < offset)
return;
pisodesc->offset = SWAPLONG(pisodesc->offset);
pisodesc = (usb_isodesc *)(void *)(buf+offset);
for (i = 0; i < uhdr->ndesc; i++) {
offset += 4; /* skip past status */
if (hdr->caplen < offset)
return;
pisodesc->status = SWAPLONG(pisodesc->status);
offset += 4; /* skip past len */
if (hdr->caplen < offset)
return;
pisodesc->len = SWAPLONG(pisodesc->len);
offset += 4; /* skip past offset */
if (hdr->caplen < offset)
return;
pisodesc->offset = SWAPLONG(pisodesc->offset);
offset += 4; /* skip past padding */
offset += 4; /* skip past len */
if (hdr->caplen < offset)
return;
pisodesc->len = SWAPLONG(pisodesc->len);
pisodesc++;
offset += 4; /* skip past padding */
pisodesc++;
}
}
}
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: pcap-dag.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-dag.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* pcap-dag.c: Packet capture interface for Endace DAG card.
* pcap-dag.c: Packet capture interface for Emulex EndaceDAG cards.
*
* The functionality of this code attempts to mimic that of pcap-linux as much
* as possible. This code is compiled in several different ways depending on
@ -12,13 +12,13 @@
* called as required from their pcap-linux/bpf equivalents.
*
* Authors: Richard Littin, Sean Irvine ({richard,sean}@reeltwo.com)
* Modifications: Jesper Peterson <support@endace.com>
* Koryn Grant <support@endace.com>
* Stephen Donnelly <support@endace.com>
* Modifications: Jesper Peterson
* Koryn Grant
* Stephen Donnelly <stephen.donnelly@emulex.com>
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-dag.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-dag.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -45,6 +45,7 @@ struct rtentry; /* declarations in <net/if.h> */
#include "dagnew.h"
#include "dagapi.h"
#include "dagpci.h"
#include "pcap-dag.h"
@ -155,7 +156,7 @@ dag_platform_cleanup(pcap_t *p)
#ifdef HAVE_DAG_STREAMS_API
if(dag_stop_stream(p->fd, pd->dag_stream) < 0)
fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
if(dag_detach_stream(p->fd, pd->dag_stream) < 0)
fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
#else
@ -226,7 +227,7 @@ dag_erf_ext_header_count(uint8_t * erf, size_t len)
/* loop over the extension headers */
do {
/* sanity check we have enough bytes */
if ( len < (24 + (hdr_num * 8)) )
return hdr_num;
@ -253,10 +254,11 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
int flags = pd->dag_offset_flags;
unsigned int nonblocking = flags & DAGF_NONBLOCK;
unsigned int num_ext_hdr = 0;
unsigned int ticks_per_second;
/* Get the next bufferful of packets (if necessary). */
while (pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size) {
/*
* Has "pcap_breakloop()" been called?
*/
@ -295,7 +297,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/* Pcap is configured to process only available packets, and there aren't any, return immediately. */
return 0;
}
if(!nonblocking &&
pd->dag_timeout &&
(pd->dag_mem_top - pd->dag_mem_bottom < dag_record_size))
@ -305,14 +307,14 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
}
}
/* Process the packets. */
while (pd->dag_mem_top - pd->dag_mem_bottom >= dag_record_size) {
unsigned short packet_len = 0;
int caplen = 0;
struct pcap_pkthdr pcap_header;
#ifdef HAVE_DAG_STREAMS_API
dag_record_t *header = (dag_record_t *)(pd->dag_mem_bottom);
#else
@ -321,7 +323,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
u_char *dp = ((u_char *)header); /* + dag_record_size; */
unsigned short rlen;
/*
* Has "pcap_breakloop()" been called?
*/
@ -334,7 +336,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
p->break_loop = 0;
return -2;
}
rlen = ntohs(header->rlen);
if (rlen < dag_record_size)
{
@ -364,7 +366,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
}
}
}
if ((header->type & 0x7f) == TYPE_PAD) {
continue;
}
@ -372,13 +374,13 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
num_ext_hdr = dag_erf_ext_header_count(dp, rlen);
/* ERF encapsulation */
/* The Extensible Record Format is not dropped for this kind of encapsulation,
/* The Extensible Record Format is not dropped for this kind of encapsulation,
* and will be handled as a pseudo header by the decoding application.
* The information carried in the ERF header and in the optional subheader (if present)
* could be merged with the libpcap information, to offer a better decoding.
* The packet length is
* o the length of the packet on the link (header->wlen),
* o plus the length of the ERF header (dag_record_size), as the length of the
* o plus the length of the ERF header (dag_record_size), as the length of the
* pseudo header will be adjusted during the decoding,
* o plus the length of the optional subheader (if present).
*
@ -420,7 +422,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
dp += dag_record_size;
/* Skip over extension headers */
dp += 8 * num_ext_hdr;
switch((header->type & 0x7f)) {
case TYPE_ATM:
case TYPE_AAL5:
@ -439,19 +441,22 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
caplen = rlen - dag_record_size - 4;
dp+=4;
}
/* Skip over extension headers */
caplen -= (8 * num_ext_hdr);
if (header->type == TYPE_ATM) {
caplen = packet_len = ATM_CELL_SIZE;
}
if (p->linktype == DLT_SUNATM) {
struct sunatm_hdr *sunatm = (struct sunatm_hdr *)dp;
unsigned long rawatm;
rawatm = ntohl(*((unsigned long *)dp));
sunatm->vci = htons((rawatm >> 4) & 0xffff);
sunatm->vpi = (rawatm >> 20) & 0x00ff;
sunatm->flags = ((header->flags.iface & 1) ? 0x80 : 0x00) |
sunatm->flags = ((header->flags.iface & 1) ? 0x80 : 0x00) |
((sunatm->vpi == 0 && sunatm->vci == htons(5)) ? 6 :
((sunatm->vpi == 0 && sunatm->vci == htons(16)) ? 5 :
((sunatm->vpi == 0 && sunatm->vci == htons(16)) ? 5 :
((dp[ATM_HDR_SIZE] == 0xaa &&
dp[ATM_HDR_SIZE+1] == 0xaa &&
dp[ATM_HDR_SIZE+2] == 0x03) ? 2 : 1)));
@ -470,6 +475,8 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
packet_len = ntohs(header->wlen);
packet_len -= (pd->dag_fcs_bits >> 3);
caplen = rlen - dag_record_size - 2;
/* Skip over extension headers */
caplen -= (8 * num_ext_hdr);
if (caplen > packet_len) {
caplen = packet_len;
}
@ -483,6 +490,8 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
packet_len = ntohs(header->wlen);
packet_len -= (pd->dag_fcs_bits >> 3);
caplen = rlen - dag_record_size;
/* Skip over extension headers */
caplen -= (8 * num_ext_hdr);
if (caplen > packet_len) {
caplen = packet_len;
}
@ -493,6 +502,8 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
packet_len = ntohs(header->wlen);
packet_len -= (pd->dag_fcs_bits >> 3);
caplen = rlen - dag_record_size - 4;
/* Skip over extension headers */
caplen -= (8 * num_ext_hdr);
if (caplen > packet_len) {
caplen = packet_len;
}
@ -503,7 +514,7 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/* Add the MTP2 Pseudo Header */
caplen += MTP2_HDR_LEN;
packet_len += MTP2_HDR_LEN;
TempPkt[MTP2_SENT_OFFSET] = 0;
TempPkt[MTP2_ANNEX_A_USED_OFFSET] = MTP2_ANNEX_A_USED_UNKNOWN;
*(TempPkt+MTP2_LINK_NUMBER_OFFSET) = ((header->rec.mc_hdlc.mc_header>>16)&0x01);
@ -518,6 +529,8 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
case TYPE_IPV6:
packet_len = ntohs(header->wlen);
caplen = rlen - dag_record_size;
/* Skip over extension headers */
caplen -= (8 * num_ext_hdr);
if (caplen > packet_len) {
caplen = packet_len;
}
@ -538,45 +551,52 @@ dag_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
continue;
} /* switch type */
/* Skip over extension headers */
caplen -= (8 * num_ext_hdr);
} /* ERF encapsulation */
if (caplen > p->snapshot)
caplen = p->snapshot;
/* Run the packet filter if there is one. */
if ((p->fcode.bf_insns == NULL) || bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen)) {
/* convert between timestamp formats */
register unsigned long long ts;
if (IS_BIGENDIAN()) {
ts = SWAPLL(header->ts);
} else {
ts = header->ts;
}
switch (p->opt.tstamp_precision) {
case PCAP_TSTAMP_PRECISION_NANO:
ticks_per_second = 1000000000;
break;
case PCAP_TSTAMP_PRECISION_MICRO:
default:
ticks_per_second = 1000000;
break;
}
pcap_header.ts.tv_sec = ts >> 32;
ts = (ts & 0xffffffffULL) * 1000000;
ts = (ts & 0xffffffffULL) * ticks_per_second;
ts += 0x80000000; /* rounding */
pcap_header.ts.tv_usec = ts >> 32;
if (pcap_header.ts.tv_usec >= 1000000) {
pcap_header.ts.tv_usec -= 1000000;
pcap_header.ts.tv_usec = ts >> 32;
if (pcap_header.ts.tv_usec >= ticks_per_second) {
pcap_header.ts.tv_usec -= ticks_per_second;
pcap_header.ts.tv_sec++;
}
/* Fill in our own header data */
pcap_header.caplen = caplen;
pcap_header.len = packet_len;
/* Count the packet. */
pd->stat.ps_recv++;
/* Call the user supplied callback function */
callback(user, &pcap_header, dp);
/* Only count packets that pass the filter, for consistency with standard Linux behaviour. */
processed++;
if (processed == cnt && !PACKET_COUNT_IS_UNLIMITED(cnt))
@ -603,7 +623,7 @@ dag_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
* device will result in a failure. The promisc flag is ignored because DAG
* cards are always promiscuous. The to_ms parameter is used in setting the
* API polling parameters.
*
*
* snaplen is now also ignored, until we get per-stream slen support. Set
* slen with approprite DAG tool BEFORE pcap_activate().
*
@ -639,7 +659,7 @@ static int dag_activate(pcap_t* handle)
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't allocate string for device name: %s\n", pcap_strerror(errno));
goto fail;
}
/* Parse input name to get dag device and stream number if provided */
if (dag_parse_name(device, newDev, strlen(device) + 16, &handlep->dag_stream) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_parse_name: %s\n", pcap_strerror(errno));
@ -685,7 +705,7 @@ static int dag_activate(pcap_t* handle)
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s\n", pcap_strerror(errno));
goto faildetach;
}
if (handle->opt.immediate) {
/* Call callback immediately.
* XXX - is this the right way to handle this?
@ -710,7 +730,7 @@ static int dag_activate(pcap_t* handle)
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s\n", pcap_strerror(errno));
goto faildetach;
}
#else
if((handlep->dag_mem_base = dag_mmap(handle->fd)) == MAP_FAILED) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,"dag_mmap %s: %s\n", device, pcap_strerror(errno));
@ -733,14 +753,14 @@ static int dag_activate(pcap_t* handle)
handle->snapshot = MIN_DAG_SNAPLEN;
}
/* snap len has to be a multiple of 4 */
snprintf(conf, 30, "varlen slen=%d", (snaplen + 3) & ~3);
snprintf(conf, 30, "varlen slen=%d", (snaplen + 3) & ~3);
if(dag_configure(handle->fd, conf) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,"dag_configure %s: %s\n", device, pcap_strerror(errno));
goto faildetach;
}
#endif
#endif
#ifdef HAVE_DAG_STREAMS_API
if(dag_start_stream(handle->fd, handlep->dag_stream) < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "dag_start_stream %s: %s\n", device, pcap_strerror(errno));
@ -807,7 +827,7 @@ static int dag_activate(pcap_t* handle)
handle->linktype = -1;
if (dag_get_datalink(handle) < 0)
goto failstop;
handle->bufsize = 0;
if (new_pcap_dag(handle) < 0) {
@ -838,12 +858,12 @@ static int dag_activate(pcap_t* handle)
handlep->stat.ps_ifdrop = 0;
return 0;
#ifdef HAVE_DAG_STREAMS_API
#ifdef HAVE_DAG_STREAMS_API
failstop:
if (dag_stop_stream(handle->fd, handlep->dag_stream) < 0) {
fprintf(stderr,"dag_stop_stream: %s\n", strerror(errno));
}
faildetach:
if (dag_detach_stream(handle->fd, handlep->dag_stream) < 0)
fprintf(stderr,"dag_detach_stream: %s\n", strerror(errno));
@ -852,7 +872,7 @@ failstop:
if (dag_stop(handle->fd) < 0)
fprintf(stderr,"dag_stop: %s\n", strerror(errno));
#endif /* HAVE_DAG_STREAMS_API */
failclose:
if (dag_close(handle->fd) < 0)
fprintf(stderr,"dag_close: %s\n", strerror(errno));
@ -922,6 +942,26 @@ pcap_t *dag_create(const char *device, char *ebuf, int *is_ours)
return NULL;
p->activate_op = dag_activate;
/*
* We claim that we support microsecond and nanosecond time
* stamps.
*
* XXX Our native precision is 2^-32s, but libpcap doesn't support
* power of two precisions yet. We can convert to either MICRO or NANO.
*/
p->tstamp_precision_count = 2;
p->tstamp_precision_list = malloc(2 * sizeof(u_int));
if (p->tstamp_precision_list == NULL) {
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
pcap_strerror(errno));
if (p->tstamp_type_list != NULL)
free(p->tstamp_type_list);
free(p);
return NULL;
}
p->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
p->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO;
return p;
}
@ -934,9 +974,9 @@ dag_stats(pcap_t *p, struct pcap_stat *ps) {
*/
/*pd->stat.ps_recv = 0;*/
/*pd->stat.ps_drop = 0;*/
*ps = pd->stat;
return 0;
}
@ -958,6 +998,8 @@ dag_findalldevs(pcap_if_t **devlistp, char *errbuf)
char dagname[DAGNAME_BUFSIZE];
int dagstream;
int dagfd;
dag_card_inf_t *inf;
char *description;
/* Try all the DAGs 0-DAG_MAX_BOARDS */
for (c = 0; c < DAG_MAX_BOARDS; c++) {
@ -966,8 +1008,11 @@ dag_findalldevs(pcap_if_t **devlistp, char *errbuf)
{
return -1;
}
description = NULL;
if ( (dagfd = dag_open(dagname)) >= 0 ) {
if (pcap_add_if(devlistp, name, 0, NULL, errbuf) == -1) {
if ((inf = dag_pciinfo(dagfd)))
description = dag_device_name(inf->device_code, 1);
if (pcap_add_if(devlistp, name, 0, description, errbuf) == -1) {
/*
* Failure.
*/
@ -982,19 +1027,19 @@ dag_findalldevs(pcap_if_t **devlistp, char *errbuf)
dag_detach_stream(dagfd, stream);
snprintf(name, 10, "dag%d:%d", c, stream);
if (pcap_add_if(devlistp, name, 0, NULL, errbuf) == -1) {
if (pcap_add_if(devlistp, name, 0, description, errbuf) == -1) {
/*
* Failure.
*/
ret = -1;
}
rxstreams--;
if(rxstreams <= 0) {
break;
}
}
}
}
}
#endif /* HAVE_DAG_STREAMS_API */
dag_close(dagfd);
@ -1054,13 +1099,13 @@ dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
uint32_t mindata;
struct timeval maxwait;
struct timeval poll;
if (dag_get_stream_poll(p->fd, pd->dag_stream,
&mindata, &maxwait, &poll) < 0) {
snprintf(errbuf, PCAP_ERRBUF_SIZE, "dag_get_stream_poll: %s\n", pcap_strerror(errno));
return -1;
}
/* Amount of data to collect in Bytes before calling callbacks.
* Important for efficiency, but can introduce latency
* at low packet rates if to_ms not set!
@ -1069,7 +1114,7 @@ dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
mindata = 0;
else
mindata = 65536;
if (dag_set_stream_poll(p->fd, pd->dag_stream,
mindata, &maxwait, &poll) < 0) {
snprintf(errbuf, PCAP_ERRBUF_SIZE, "dag_set_stream_poll: %s\n", pcap_strerror(errno));
@ -1084,7 +1129,7 @@ dag_setnonblock(pcap_t *p, int nonblock, char *errbuf)
}
return (0);
}
static int
dag_get_datalink(pcap_t *p)
{
@ -1105,18 +1150,18 @@ dag_get_datalink(pcap_t *p)
/* Get list of possible ERF types for this card */
if (dag_get_stream_erf_types(p->fd, pd->dag_stream, types, 255) < 0) {
snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_stream_erf_types: %s", pcap_strerror(errno));
return (-1);
return (-1);
}
while (types[index]) {
#elif defined HAVE_DAG_GET_ERF_TYPES
/* Get list of possible ERF types for this card */
if (dag_get_erf_types(p->fd, types, 255) < 0) {
snprintf(p->errbuf, sizeof(p->errbuf), "dag_get_erf_types: %s", pcap_strerror(errno));
return (-1);
return (-1);
}
while (types[index]) {
#else
/* Check the type through a dagapi call. */
@ -1162,7 +1207,7 @@ dag_get_datalink(pcap_t *p)
p->linktype = DLT_EN10MB;
break;
case TYPE_ATM:
case TYPE_ATM:
case TYPE_AAL5:
case TYPE_MC_ATM:
case TYPE_MC_AAL5:

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-dbus.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-dbus.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2012 Jakub Zawadzki
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-dbus.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-dbus.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -127,7 +127,7 @@ dbus_write(pcap_t *handle, const void *buf, size_t size)
dbus_message_unref(msg);
return 0;
}
}
static int
dbus_stats(pcap_t *handle, struct pcap_stat *stats)
@ -255,8 +255,8 @@ dbus_create(const char *device, char *ebuf, int *is_ours)
{
pcap_t *p;
if (strcmp(device, "dbus-system") &&
strcmp(device, "dbus-session") &&
if (strcmp(device, "dbus-system") &&
strcmp(device, "dbus-session") &&
strncmp(device, "dbus://", 7))
{
*is_ours = 0;
@ -272,7 +272,7 @@ dbus_create(const char *device, char *ebuf, int *is_ours)
return (p);
}
int
int
dbus_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
if (pcap_add_if(alldevsp, "dbus-system", 0, "D-Bus system bus", err_str) < 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-dlpi.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-dlpi.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-dlpi.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-dlpi.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -303,7 +303,7 @@ pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size)
ret = -1;
#endif /* raw mode */
return (ret);
}
}
#ifndef DL_IPATM
#define DL_IPATM 0x12 /* ATM Classical IP interface */

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-dos.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-dos.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* This file is part of DOS-libpcap
@ -168,7 +168,7 @@ pcap_t *pcap_create_interface (const char *device, char *ebuf)
* network packets.
*/
static int pcap_activate_dos (pcap_t *pcap)
{
{
struct pcap_dos *pcapd = pcap->priv;
if (pcap->opt.rfmon) {
@ -199,7 +199,7 @@ static int pcap_activate_dos (pcap_t *pcap)
!first_init(pcap->opt.source, pcap->errbuf, pcap->opt.promisc))
{
return (PCAP_ERROR);
}
}
atexit (close_driver);
}
else if (stricmp(active_dev->name,pcap->opt.source))
@ -403,7 +403,7 @@ int pcap_stats_ex (pcap_t *p, struct pcap_stat_ex *se)
strlcpy (p->errbuf, "pktdrvr doesn't have detailed statistics",
PCAP_ERRBUF_SIZE);
return (-1);
}
}
memcpy (se, (*dev->get_stats)(dev), sizeof(*se));
return (0);
}
@ -522,7 +522,7 @@ int pcap_lookupnet (const char *device, bpf_u_int32 *localnet,
}
ARGSUSED (device);
return (0);
}
}
/*
* Get a list of all interfaces that are present and that we probe okay.
@ -962,7 +962,7 @@ static int init_watt32 (struct pcap *pcap, const char *dev_name, char *err_buf)
* have default values. Should be taken from another
* ini-file/environment in any case (ref. tcpdump.ini)
*/
_watt_is_init = 1;
_watt_is_init = 1;
if (!using_pktdrv || !has_ip_addr) /* for now .... */
{
@ -1094,7 +1094,7 @@ static int pkt_open (struct device *dev)
if (!PktInitDriver(mode))
return (0);
PktResetStatistics (pktInfo.handle);
PktQueueBusy (FALSE);
return (1);
@ -1292,7 +1292,7 @@ struct device rtl8139_dev LOCKED_VAR = {
0,0,0,0,0,0,
&cs89_dev,
rtl8139_probe /* dev->probe routine */
};
};
/*
* Dequeue routine is called by polling.

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-dos.h,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-dos.h,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Internal details for libpcap on DOS.
@ -216,7 +216,7 @@ extern void _w32_os_yield (void); /* Watt-32's misc.c */
#define PCAP_ASSERT(x) ((void)0)
#else
void pcap_assert (const char *what, const char *file, unsigned line);
void pcap_assert (const char *what, const char *file, unsigned line);
#define PCAP_ASSERT(x) do { \
if (!(x)) \

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-int.h,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-int.h,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1994, 1995, 1996
@ -204,6 +204,11 @@ struct pcap {
/* We're accepting only packets in this direction/these directions. */
pcap_direction_t direction;
/*
* Flags to affect BPF code generation.
*/
int bpf_codegen_flags;
/*
* Placeholder for filter code if bpf not in kernel.
*/
@ -250,6 +255,11 @@ struct pcap {
cleanup_op_t cleanup_op;
};
/*
* BPF code generation flags.
*/
#define BPF_SPECIAL_VLAN_HANDLING 0x00000001 /* special VLAN handling for Linux */
/*
* This is a timeval as stored in a savefile.
* It has to use the same types everywhere, independent of the actual

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-netfilter-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-netfilter-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2011 Jakub Zawadzki
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-netfilter-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-netfilter-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -62,14 +62,14 @@ __RCSID("$NetBSD: pcap-netfilter-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp
#include <linux/netfilter/nfnetlink_queue.h>
/* NOTE: if your program drops privilages after pcap_activate() it WON'T work with nfqueue.
* It took me quite some time to debug ;/
* It took me quite some time to debug ;/
*
* Sending any data to nfnetlink socket requires CAP_NET_ADMIN privilages,
* and in nfqueue we need to send verdict reply after recving packet.
*
* In tcpdump you can disable dropping privilages with -Z root
*/
#include "pcap-netfilter-linux.h"
#define HDR_LENGTH (NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct nfgenmsg))))
@ -121,10 +121,10 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
return -1;
}
if (NFNL_SUBSYS_ID(nlh->nlmsg_type) == NFNL_SUBSYS_ULOG &&
NFNL_MSG_TYPE(nlh->nlmsg_type) == NFULNL_MSG_PACKET)
if (NFNL_SUBSYS_ID(nlh->nlmsg_type) == NFNL_SUBSYS_ULOG &&
NFNL_MSG_TYPE(nlh->nlmsg_type) == NFULNL_MSG_PACKET)
type = NFLOG;
else if (NFNL_SUBSYS_ID(nlh->nlmsg_type) == NFNL_SUBSYS_QUEUE &&
else if (NFNL_SUBSYS_ID(nlh->nlmsg_type) == NFNL_SUBSYS_QUEUE &&
NFNL_MSG_TYPE(nlh->nlmsg_type) == NFQNL_MSG_PACKET)
type = NFQUEUE;
@ -132,7 +132,7 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
const unsigned char *payload = NULL;
struct pcap_pkthdr pkth;
const struct nfgenmsg *nfg;
const struct nfgenmsg *nfg = NULL;
int id = 0;
if (handle->linktype != DLT_NFLOG) {
@ -189,7 +189,7 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
gettimeofday(&pkth.ts, NULL);
if (handle->fcode.bf_insns == NULL ||
bpf_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
bpf_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
{
handlep->packets_read++;
callback(user, &pkth, payload);
@ -199,7 +199,10 @@ netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_c
if (type == NFQUEUE) {
/* XXX, possible responses: NF_DROP, NF_ACCEPT, NF_STOLEN, NF_QUEUE, NF_REPEAT, NF_STOP */
nfqueue_send_verdict(handle, ntohs(nfg->res_id), id, NF_ACCEPT);
/* if type == NFQUEUE, handle->linktype is always != DLT_NFLOG,
so nfg is always initialized to NLMSG_DATA(nlh). */
if (nfg != NULL)
nfqueue_send_verdict(handle, ntohs(nfg->res_id), id, NF_ACCEPT);
}
}
@ -236,7 +239,7 @@ netfilter_inject_linux(pcap_t *handle, const void *buf, size_t size)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on netfilter devices");
return (-1);
}
}
struct my_nfattr {
u_int16_t nfa_len;
@ -254,7 +257,7 @@ netfilter_send_config_msg(const pcap_t *handle, u_int16_t msg_type, int ack, u_i
struct sockaddr_nl snl;
static unsigned int seq_id;
if (!seq_id)
seq_id = time(NULL);
++seq_id;
@ -346,7 +349,7 @@ nflog_send_config_cmd(const pcap_t *handle, u_int16_t group_id, u_int8_t cmd, u_
return nflog_send_config_msg(handle, family, group_id, &nfa);
}
static int
static int
nflog_send_config_mode(const pcap_t *handle, u_int16_t group_id, u_int8_t copy_mode, u_int32_t copy_range)
{
struct nfulnl_msg_config_mode msg;
@ -400,7 +403,7 @@ nfqueue_send_config_cmd(const pcap_t *handle, u_int16_t group_id, u_int8_t cmd,
return nfqueue_send_config_msg(handle, AF_UNSPEC, group_id, &nfa);
}
static int
static int
nfqueue_send_config_mode(const pcap_t *handle, u_int16_t group_id, u_int8_t copy_mode, u_int32_t copy_range)
{
struct nfqnl_msg_config_params msg;
@ -433,7 +436,7 @@ netfilter_activate(pcap_t* handle)
dev += strlen(NFQUEUE_IFACE);
type = NFQUEUE;
}
if (type != OTHER && *dev == ':') {
dev++;
while (*dev) {
@ -442,7 +445,7 @@ netfilter_activate(pcap_t* handle)
if (group_count == 32) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Maximum 32 netfilter groups! dev: %s",
"Maximum 32 netfilter groups! dev: %s",
handle->opt.source);
return PCAP_ERROR;
}
@ -467,7 +470,7 @@ netfilter_activate(pcap_t* handle)
if (type == OTHER || *dev) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't get netfilter group(s) index from %s",
"Can't get netfilter group(s) index from %s",
handle->opt.source);
return PCAP_ERROR;
}
@ -604,7 +607,7 @@ netfilter_create(const char *device, char *ebuf, int *is_ours)
/* Does it begin with NFLOG_IFACE or NFQUEUE_IFACE? */
if (strncmp(cp, NFLOG_IFACE, sizeof NFLOG_IFACE - 1) == 0)
cp += sizeof NFLOG_IFACE - 1;
else if (strncmp(cp, NFQUEUE_IFACE, sizeof NFQUEUE_IFACE - 1) == 0)
else if (strncmp(cp, NFQUEUE_IFACE, sizeof NFQUEUE_IFACE - 1) == 0)
cp += sizeof NFQUEUE_IFACE - 1;
else {
/* Nope, doesn't begin with NFLOG_IFACE nor NFQUEUE_IFACE */
@ -633,11 +636,11 @@ netfilter_create(const char *device, char *ebuf, int *is_ours)
return (p);
}
int
int
netfilter_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
int sock;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER);
if (sock < 0) {
/* if netlink is not supported this is not fatal */

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-netfilter-linux.h,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-netfilter-linux.h,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2011 Jakub Zawadzki
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-nit.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-nit.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@ -22,7 +22,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-nit.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-nit.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -216,7 +216,7 @@ pcap_inject_nit(pcap_t *p, const void *buf, size_t size)
return (-1);
}
return (ret);
}
}
static int
nit_setflags(pcap_t *p)

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-pf.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-pf.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-pf.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-pf.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -242,7 +242,7 @@ pcap_inject_pf(pcap_t *p, const void *buf, size_t size)
return (-1);
}
return (ret);
}
}
static int
pcap_stats_pf(pcap_t *p, struct pcap_stat *ps)

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-septel.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-septel.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* pcap-septel.c: Packet capture interface for Intel/Septel card.
@ -17,7 +17,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-septel.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-septel.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -199,9 +199,9 @@ septel_inject(pcap_t *handle, const void *buf _U_, size_t size _U_)
* See also pcap(3).
*/
static pcap_t *septel_activate(pcap_t* handle) {
/* Initialize some components of the pcap structure. */
/* Initialize some components of the pcap structure. */
handle->linktype = DLT_MTP2;
handle->bufsize = 0;
/*
@ -249,9 +249,9 @@ static int septel_stats(pcap_t *p, struct pcap_stat *ps) {
struct pcap_septel *handlep = p->priv;
/*handlep->stat.ps_recv = 0;*/
/*handlep->stat.ps_drop = 0;*/
*ps = handlep->stat;
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-sita.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-sita.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* pcap-sita.c: Packet capture interface additions for SITA ACN devices
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-sita.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-sita.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -188,7 +188,7 @@ static int read_client_nbytes(int fd, int count, unsigned char *buf) {
find_unit_by_fd(fd, &chassis, &geoslot, &u);
while (count) {
if ((len = recv(fd, buf, count, 0)) <= 0) return -1; /* read in whatever data was sent to us */
count -= len;
count -= len;
buf += len;
} /* till we have everything we are looking for */
return 0;
@ -216,7 +216,7 @@ static void empty_unit(int chassis, int geoslot) {
u->imsg = (char *)realloc(u->imsg, 1); /* and re-allocate the old large buffer into a new small one */
if (u->imsg == NULL) { /* oops, realloc call failed */
fprintf(stderr, "Warning...call to realloc() failed, value of errno is %d\n", errno);
}
}
@ -558,10 +558,10 @@ static void sort_if_table(void) {
}
if (has_swapped == 0)
return;
}
}
return;
}
static int process_client_data (char *errbuf) { /* returns: -1 = error, 0 = OK */
int chassis, geoslot;
unit_t *u;

View File

@ -1,7 +1,7 @@
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-snf.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-snf.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
/* $NetBSD: pcap-snf.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-snf.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -21,6 +21,9 @@ __RCSID("$NetBSD: pcap-snf.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
#include <unistd.h>
#include <snf.h>
#if SNF_VERSION_API >= 0x0003
#define SNF_HAVE_INJECT_API
#endif
#include "pcap-int.h"
#include "pcap-snf.h"
@ -31,6 +34,9 @@ __RCSID("$NetBSD: pcap-snf.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
struct pcap_snf {
snf_handle_t snf_handle; /* opaque device handle */
snf_ring_t snf_ring; /* opaque device ring handle */
#ifdef SNF_HAVE_INJECT_API
snf_inject_t snf_inj; /* inject handle, if inject is used */
#endif
int snf_timeout;
int snf_boardnum;
};
@ -46,9 +52,10 @@ static int
snf_pcap_stats(pcap_t *p, struct pcap_stat *ps)
{
struct snf_ring_stats stats;
struct pcap_snf *snfps = p->priv;
int rc;
if ((rc = snf_ring_getstats(ps->snf_ring, &stats))) {
if ((rc = snf_ring_getstats(snfps->snf_ring, &stats))) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "snf_get_stats: %s",
pcap_strerror(rc));
return -1;
@ -67,6 +74,10 @@ snf_platform_cleanup(pcap_t *p)
if (p == NULL)
return;
#ifdef SNF_HAVE_INJECT_API
if (ps->snf_inj)
snf_inject_close(ps->snf_inj);
#endif
snf_ring_close(ps->snf_ring);
snf_close(ps->snf_handle);
pcap_cleanup_live_common(p);
@ -100,14 +111,23 @@ snf_setnonblock(pcap_t *p, int nonblock, char *errbuf)
static inline
struct timeval
snf_timestamp_to_timeval(const int64_t ts_nanosec)
snf_timestamp_to_timeval(const int64_t ts_nanosec, const int tstamp_precision)
{
struct timeval tv;
int32_t rem;
long tv_nsec;
if (ts_nanosec == 0)
return (struct timeval) { 0, 0 };
tv.tv_sec = ts_nanosec / _NSEC_PER_SEC;
tv.tv_usec = (ts_nanosec % _NSEC_PER_SEC) / 1000;
tv_nsec = (ts_nanosec % _NSEC_PER_SEC);
/* libpcap expects tv_usec to be nanos if using nanosecond precision. */
if (tstamp_precision == PCAP_TSTAMP_PRECISION_NANO)
tv.tv_usec = tv_nsec;
else
tv.tv_usec = tv_nsec / 1000;
return tv;
}
@ -118,11 +138,13 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
struct pcap_pkthdr hdr;
int i, flags, err, caplen, n;
struct snf_recv_req req;
int nonblock, timeout;
if (!p || cnt == 0)
if (!p)
return -1;
n = 0;
timeout = ps->snf_timeout;
while (n < cnt || PACKET_COUNT_IS_UNLIMITED(cnt)) {
/*
* Has "pcap_breakloop()" been called?
@ -136,14 +158,17 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
}
}
err = snf_ring_recv(ps->snf_ring, ps->snf_timeout, &req);
err = snf_ring_recv(ps->snf_ring, timeout, &req);
if (err) {
if (err == EBUSY || err == EAGAIN)
return (0);
if (err == EINTR)
if (err == EBUSY || err == EAGAIN) {
return (n);
}
else if (err == EINTR) {
timeout = 0;
continue;
if (err != 0) {
}
else {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "snf_read: %s",
pcap_strerror(err));
return -1;
@ -156,12 +181,17 @@ snf_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
if ((p->fcode.bf_insns == NULL) ||
bpf_filter(p->fcode.bf_insns, req.pkt_addr, req.length, caplen)) {
hdr.ts = snf_timestamp_to_timeval(req.timestamp);
hdr.ts = snf_timestamp_to_timeval(req.timestamp, p->opt.tstamp_precision);
hdr.caplen = caplen;
hdr.len = req.length;
callback(user, &hdr, req.pkt_addr);
}
n++;
/* After one successful packet is received, we won't block
* again for that timeout. */
if (timeout != 0)
timeout = 0;
}
return (n);
}
@ -188,9 +218,32 @@ snf_setfilter(pcap_t *p, struct bpf_program *fp)
static int
snf_inject(pcap_t *p, const void *buf _U_, size_t size _U_)
{
strlcpy(p->errbuf, "Sending packets isn't supported with snf",
#ifdef SNF_HAVE_INJECT_API
struct pcap_snf *ps = p->priv;
int rc;
if (ps->snf_inj == NULL) {
rc = snf_inject_open(ps->snf_boardnum, 0, &ps->snf_inj);
if (rc) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"snf_inject_open: %s", pcap_strerror(rc));
return (-1);
}
}
rc = snf_inject_send(ps->snf_inj, -1, 0, buf, size);
if (!rc) {
return (size);
}
else {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "snf_inject_send: %s",
pcap_strerror(rc));
return (-1);
}
#else
strlcpy(p->errbuf, "Sending packets isn't supported with this snf version",
PCAP_ERRBUF_SIZE);
return (-1);
#endif
}
static int
@ -200,7 +253,7 @@ snf_activate(pcap_t* p)
char *device = p->opt.source;
const char *nr = NULL;
int err;
int flags = 0;
int flags = -1, ring_id = -1;
if (device == NULL) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
@ -210,8 +263,10 @@ snf_activate(pcap_t* p)
/* In Libpcap, we set pshared by default if NUM_RINGS is set to > 1.
* Since libpcap isn't thread-safe */
if ((nr = getenv("SNF_NUM_RINGS")) && *nr && atoi(nr) > 1)
flags |= SNF_F_PSHARED;
if ((nr = getenv("SNF_FLAGS")) && *nr)
flags = strtol(nr, NULL, 0);
else if ((nr = getenv("SNF_NUM_RINGS")) && *nr && atoi(nr) > 1)
flags = SNF_F_PSHARED;
else
nr = NULL;
@ -227,10 +282,14 @@ snf_activate(pcap_t* p)
return -1;
}
err = snf_ring_open(ps->snf_handle, &ps->snf_ring);
if ((nr = getenv("SNF_PCAP_RING_ID")) && *nr) {
ring_id = (int) strtol(nr, NULL, 0);
}
err = snf_ring_open_id(ps->snf_handle, ring_id, &ps->snf_ring);
if (err != 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"snf_ring_open failed: %s", pcap_strerror(err));
"snf_ring_open_id(ring=%d) failed: %s",
ring_id, pcap_strerror(err));
return -1;
}
@ -260,12 +319,104 @@ snf_activate(pcap_t* p)
p->setnonblock_op = snf_setnonblock;
p->stats_op = snf_pcap_stats;
p->cleanup_op = snf_platform_cleanup;
#ifdef SNF_HAVE_INJECT_API
ps->snf_inj = NULL;
#endif
return 0;
}
#define MAX_DESC_LENGTH 128
int
snf_findalldevs(pcap_if_t **devlistp, char *errbuf)
{
pcap_if_t *devlist = NULL,*curdev,*prevdev;
pcap_addr_t *curaddr;
struct snf_ifaddrs *ifaddrs, *ifa;
char desc[MAX_DESC_LENGTH];
int ret;
if (snf_init(SNF_VERSION_API))
return (-1);
if (snf_getifaddrs(&ifaddrs) || ifaddrs == NULL)
{
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"snf_getifaddrs: %s", pcap_strerror(errno));
return (-1);
}
ifa = ifaddrs;
while (ifa)
{
/*
* Allocate a new entry
*/
curdev = (pcap_if_t *)malloc(sizeof(pcap_if_t));
if (curdev == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"snf_findalldevs malloc: %s", pcap_strerror(errno));
return (-1);
}
if (devlist == NULL) /* save first entry */
devlist = curdev;
else
prevdev->next = curdev;
/*
* Fill in the entry.
*/
curdev->next = NULL;
curdev->name = strdup(ifa->snf_ifa_name);
if (curdev->name == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"snf_findalldevs strdup: %s", pcap_strerror(errno));
free(curdev);
return (-1);
}
(void)snprintf(desc,MAX_DESC_LENGTH,"Myricom snf%d",
ifa->snf_ifa_portnum);
curdev->description = strdup(desc);
if (curdev->description == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"snf_findalldevs strdup1: %s", pcap_strerror(errno));
free(curdev->name);
free(curdev);
return (-1);
}
curdev->addresses = NULL;
curdev->flags = 0;
curaddr = (pcap_addr_t *)malloc(sizeof(pcap_addr_t));
if (curaddr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"snf_findalldevs malloc1: %s", pcap_strerror(errno));
free(curdev->description);
free(curdev->name);
free(curdev);
return (-1);
}
curdev->addresses = curaddr;
curaddr->next = NULL;
curaddr->addr = (struct sockaddr*)malloc(sizeof(struct sockaddr_storage));
if (curaddr->addr == NULL) {
(void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
"malloc2: %s", pcap_strerror(errno));
free(curdev->description);
free(curdev->name);
free(curaddr);
free(curdev);
return (-1);
}
curaddr->addr->sa_family = AF_INET;
curaddr->netmask = NULL;
curaddr->broadaddr = NULL;
curaddr->dstaddr = NULL;
curaddr->next = NULL;
prevdev = curdev;
ifa = ifa->snf_ifa_next;
}
snf_freeifaddrs(ifaddrs);
*devlistp = devlist;
/*
* There are no platform-specific devices since each device
* exists as a regular Ethernet device.
@ -329,6 +480,22 @@ snf_create(const char *device, char *ebuf, int *is_ours)
return NULL;
ps = p->priv;
/*
* We support microsecond and nanosecond time stamps.
*/
p->tstamp_precision_count = 2;
p->tstamp_precision_list = malloc(2 * sizeof(u_int));
if (p->tstamp_precision_list == NULL) {
snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
pcap_strerror(errno));
if (p->tstamp_type_list != NULL)
free(p->tstamp_type_list);
free(p);
return NULL;
}
p->tstamp_precision_list[0] = PCAP_TSTAMP_PRECISION_MICRO;
p->tstamp_precision_list[1] = PCAP_TSTAMP_PRECISION_NANO;
p->activate_op = snf_activate;
ps->snf_boardnum = boardnum;
return p;

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-snit.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-snit.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-snit.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-snit.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -216,7 +216,7 @@ static int
pcap_inject_snit(pcap_t *p, const void *buf, size_t size)
{
struct strbuf ctl, data;
/*
* XXX - can we just do
*

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-snoop.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-snoop.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@ -22,7 +22,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-snoop.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-snoop.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -119,7 +119,7 @@ again:
caplen = (datalen < p->snapshot) ? datalen : p->snapshot;
cp = (u_char *)(sh + 1) + p->offset; /* XXX */
/*
/*
* XXX unfortunately snoop loopback isn't exactly like
* BSD's. The address family is encoded in the first 2
* bytes rather than the first 4 bytes! Luckily the last
@ -160,7 +160,7 @@ pcap_inject_snoop(pcap_t *p, const void *buf, size_t size)
return (-1);
}
return (ret);
}
}
static int
pcap_stats_snoop(pcap_t *p, struct pcap_stat *ps)

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-usb-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-usb-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap-usb-linux.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap-usb-linux.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -144,21 +144,21 @@ static int usb_setdirection_linux(pcap_t *, pcap_direction_t);
static void usb_cleanup_linux_mmap(pcap_t *);
/* facility to add an USB device to the device list*/
static int
static int
usb_dev_add(pcap_if_t** alldevsp, int n, char *err_str)
{
char dev_name[10];
char dev_descr[30];
char dev_descr[30];
snprintf(dev_name, 10, USB_IFACE"%d", n);
snprintf(dev_descr, 30, "USB bus number %d", n);
if (pcap_add_if(alldevsp, dev_name, 0,
if (pcap_add_if(alldevsp, dev_name, 0,
dev_descr, err_str) < 0)
return -1;
return 0;
return 0;
}
int
int
usb_findalldevs(pcap_if_t **alldevsp, char *err_str)
{
struct dirent* data;
@ -177,7 +177,7 @@ usb_findalldevs(pcap_if_t **alldevsp, char *err_str)
if (strncmp(name, "usb", 3) != 0)
continue;
if (sscanf(&name[3], "%d", &n) == 0)
if (sscanf(&name[3], "%d", &n) == 0)
continue;
ret = usb_dev_add(alldevsp, n, err_str);
@ -198,7 +198,7 @@ usb_findalldevs(pcap_if_t **alldevsp, char *err_str)
if ((len < 1) || !isdigit(name[--len]))
continue;
while (isdigit(name[--len]));
if (sscanf(&name[len+1], "%d", &n) != 1)
if (sscanf(&name[len+1], "%d", &n) != 1)
continue;
ret = usb_dev_add(alldevsp, n, err_str);
@ -212,12 +212,12 @@ usb_findalldevs(pcap_if_t **alldevsp, char *err_str)
return 0;
}
static
static
int usb_mmap(pcap_t* handle)
{
struct pcap_usb_linux *handlep = handle->priv;
int len = ioctl(handle->fd, MON_IOCQ_RING_SIZE);
if (len < 0)
if (len < 0)
return 0;
handlep->mmapbuflen = len;
@ -265,7 +265,7 @@ probe_devices(int bus)
continue;
snprintf(buf, sizeof(buf), "/dev/bus/usb/%03d/%s", bus, data->d_name);
fd = open(buf, O_RDWR);
if (fd == -1)
continue;
@ -368,7 +368,7 @@ usb_activate(pcap_t* handle)
}
/*now select the read method: try to open binary interface */
snprintf(full_path, USB_LINE_LEN, LINUX_USB_MON_DEV"%d", handlep->bus_index);
snprintf(full_path, USB_LINE_LEN, LINUX_USB_MON_DEV"%d", handlep->bus_index);
handle->fd = open(full_path, O_RDONLY, 0);
if (handle->fd >= 0)
{
@ -407,7 +407,7 @@ usb_activate(pcap_t* handle)
}
else {
/*Binary interface not available, try open text interface */
snprintf(full_path, USB_LINE_LEN, USB_TEXT_DIR"/%dt", handlep->bus_index);
snprintf(full_path, USB_LINE_LEN, USB_TEXT_DIR"/%dt", handlep->bus_index);
handle->fd = open(full_path, O_RDONLY, 0);
if (handle->fd < 0)
{
@ -417,7 +417,7 @@ usb_activate(pcap_t* handle)
* Not found at the new location; try
* the old location.
*/
snprintf(full_path, USB_LINE_LEN, USB_TEXT_DIR_OLD"/%dt", handlep->bus_index);
snprintf(full_path, USB_LINE_LEN, USB_TEXT_DIR_OLD"/%dt", handlep->bus_index);
handle->fd = open(full_path, O_RDONLY, 0);
}
if (handle->fd < 0) {
@ -458,22 +458,22 @@ usb_activate(pcap_t* handle)
return 0;
}
static inline int
static inline int
ascii_to_int(char c)
{
return c < 'A' ? c- '0': ((c<'a') ? c - 'A' + 10: c-'a'+10);
}
/*
* see <linux-kernel-source>/Documentation/usb/usbmon.txt and
* <linux-kernel-source>/drivers/usb/mon/mon_text.c for urb string
* see <linux-kernel-source>/Documentation/usb/usbmon.txt and
* <linux-kernel-source>/drivers/usb/mon/mon_text.c for urb string
* format description
*/
static int
usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
{
/* see:
* /usr/src/linux/Documentation/usb/usbmon.txt
* /usr/src/linux/Documentation/usb/usbmon.txt
* for message format
*/
struct pcap_usb_linux *handlep = handle->priv;
@ -506,11 +506,11 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
return -1;
}
/* read urb header; %n argument may increment return value, but it's
/* read urb header; %n argument may increment return value, but it's
* not mandatory, so does not count on it*/
string[ret] = 0;
ret = sscanf(string, "%x %d %c %c%c:%d:%d %s%n", &tag, &timestamp, &etype,
&pipeid1, &pipeid2, &dev_addr, &ep_num, status,
ret = sscanf(string, "%x %d %c %c%c:%d:%d %s%n", &tag, &timestamp, &etype,
&pipeid1, &pipeid2, &dev_addr, &ep_num, status,
&cnt);
if (ret < 8)
{
@ -526,10 +526,10 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
string += cnt;
/* don't use usbmon provided timestamp, since it have low precision*/
if (gettimeofday(&pkth.ts, NULL) < 0)
if (gettimeofday(&pkth.ts, NULL) < 0)
{
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't get timestamp for message '%s' %d:%s",
"Can't get timestamp for message '%s' %d:%s",
string, errno, strerror(errno));
return -1;
}
@ -572,11 +572,11 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
if (ret != 1)
{
/* this a setup packet, setup data can be filled with underscore if
* usbmon has not been able to read them, so we must parse this fields as
* usbmon has not been able to read them, so we must parse this fields as
* strings */
pcap_usb_setup* shdr;
char str1[3], str2[3], str3[5], str4[5], str5[5];
ret = sscanf(string, "%s %s %s %s %s%n", str1, str2, str3, str4,
ret = sscanf(string, "%s %s %s %s %s%n", str1, str2, str3, str4,
str5, &cnt);
if (ret < 5)
{
@ -597,7 +597,7 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
uhdr->setup_flag = 0;
}
else
else
uhdr->setup_flag = 1;
/* read urb data */
@ -610,7 +610,7 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
}
string += cnt;
/* urb tag is not present if urb length is 0, so we can stop here
/* urb tag is not present if urb length is 0, so we can stop here
* text parsing */
pkth.len = urb_len+pkth.caplen;
uhdr->urb_len = urb_len;
@ -627,7 +627,7 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
return -1;
}
if (urb_tag != '=')
if (urb_tag != '=')
goto got;
/* skip urb tag and following space */
@ -636,7 +636,7 @@ usb_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *u
/* if we reach this point we got some urb data*/
uhdr->data_flag = 0;
/* read all urb data; if urb length is greater then the usbmon internal
/* read all urb data; if urb length is greater then the usbmon internal
* buffer length used by the kernel to spool the URB, we get only
* a partial information.
* At least until linux 2.6.17 there is no way to set usbmon intenal buffer
@ -675,7 +675,7 @@ usb_inject_linux(pcap_t *handle, const void *buf, size_t size)
return (-1);
}
static int
static int
usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
{
struct pcap_usb_linux *handlep = handle->priv;
@ -700,7 +700,7 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
}
if (fd < 0) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't open USB stats file %s: %s",
"Can't open USB stats file %s: %s",
string, strerror(errno));
return -1;
}
@ -722,11 +722,11 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
/* extract info on dropped urbs */
for (consumed=0; consumed < ret; ) {
/* from the sscanf man page:
* The C standard says: "Execution of a %n directive does
/* from the sscanf man page:
* The C standard says: "Execution of a %n directive does
* not increment the assignment count returned at the completion
* of execution" but the Corrigendum seems to contradict this.
* Do not make any assumptions on the effect of %n conversions
* Do not make any assumptions on the effect of %n conversions
* on the return value and explicitly check for cnt assignmet*/
int ntok;
@ -738,7 +738,7 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
ptr += cnt;
if (strcmp(token, "nreaders") == 0)
ret = sscanf(ptr, "%d", &stats->ps_drop);
else
else
ret = sscanf(ptr, "%d", &dummy);
if (ntok != 1)
break;
@ -751,7 +751,7 @@ usb_stats_linux(pcap_t *handle, struct pcap_stat *stats)
return 0;
}
static int
static int
usb_setdirection_linux(pcap_t *p, pcap_direction_t d)
{
p->direction = d;
@ -759,7 +759,7 @@ usb_setdirection_linux(pcap_t *p, pcap_direction_t d)
}
static int
static int
usb_stats_linux_bin(pcap_t *handle, struct pcap_stat *stats)
{
struct pcap_usb_linux *handlep = handle->priv;
@ -780,7 +780,7 @@ usb_stats_linux_bin(pcap_t *handle, struct pcap_stat *stats)
}
/*
* see <linux-kernel-source>/Documentation/usb/usbmon.txt and
* see <linux-kernel-source>/Documentation/usb/usbmon.txt and
* <linux-kernel-source>/drivers/usb/mon/mon_bin.c binary ABI
*/
static int
@ -838,7 +838,7 @@ usb_read_linux_bin(pcap_t *handle, int max_packets, pcap_handler callback, u_cha
}
/*
* see <linux-kernel-source>/Documentation/usb/usbmon.txt and
* see <linux-kernel-source>/Documentation/usb/usbmon.txt and
* <linux-kernel-source>/drivers/usb/mon/mon_bin.c binary ABI
*/
#define VEC_SIZE 32
@ -892,7 +892,7 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
for (i=0; i<fetch.nfetch; ++i) {
/* discard filler */
hdr = (pcap_usb_header*) &handlep->mmapbuf[vec[i]];
if (hdr->event_type == '@')
if (hdr->event_type == '@')
continue;
/* we can get less that than really captured from kernel, depending on
@ -922,7 +922,11 @@ usb_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback, u_ch
}
/* flush pending events*/
ioctl(handle->fd, MON_IOCH_MFLUSH, nflush);
if (ioctl(handle->fd, MON_IOCH_MFLUSH, nflush) == -1) {
snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
"Can't mflush fd %d: %s", handle->fd, strerror(errno));
return -1;
}
return packets;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-usb-linux.h,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-usb-linux.h,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap-win32.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap-win32.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
@ -14,9 +14,9 @@
* 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. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* 3. Neither the name of the Politecnico di Torino, CACE Technologies
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -110,7 +110,7 @@ BOOL WINAPI DllMain(
}
/* Start winsock */
int
int
wsockinit()
{
WORD wVersionRequested;
@ -120,13 +120,13 @@ wsockinit()
if (done)
return err;
wVersionRequested = MAKEWORD( 1, 1);
wVersionRequested = MAKEWORD( 1, 1);
err = WSAStartup( wVersionRequested, &wsaData );
atexit ((void(*)(void))WSACleanup);
InitializeCriticalSection(&g_PcapCompileCriticalSection);
done = 1;
if ( err != 0 )
err = -1;
return err;
@ -222,11 +222,11 @@ pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed");
return (PCAP_ERROR);
}
cc = p->Packet->ulBytesReceived;
bp = p->Packet->Buffer;
}
}
else
bp = p->bp;
@ -330,14 +330,14 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/* The timeout has expired but we no packets arrived */
return 0;
header = (dag_record_t*)p->adapter->DagBuffer;
}
}
else
header = (dag_record_t*)p->bp;
endofbuf = (char*)header + cc;
/*
* Cycle through the packets
/*
* Cycle through the packets
*/
do
{
@ -347,12 +347,12 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/* Increase the number of captured packets */
pw->stat.ps_recv++;
/* Find the beginning of the packet */
dp = ((u_char *)header) + dag_record_size;
/* Determine actual packet len */
switch(header->type)
switch(header->type)
{
case TYPE_ATM:
packet_len = ATM_SNAPLEN;
@ -370,9 +370,9 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
caplen = packet_len;
}
dp += 2;
break;
case TYPE_HDLC_POS:
swt = SWAPS(header->wlen);
packet_len = swt - (pw->dag_fcs_bits);
@ -381,10 +381,10 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
caplen = packet_len;
}
break;
}
if(caplen > p->snapshot)
caplen = p->snapshot;
@ -397,14 +397,14 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
* out of the loop without having read any packets, and
* return the number of packets we've processed so far.
*/
if (p->break_loop)
if (p->break_loop)
{
if (n == 0)
if (n == 0)
{
p->break_loop = 0;
return (-2);
}
else
}
else
{
p->bp = (char*)header;
p->cc = endofbuf - (char*)header;
@ -425,30 +425,30 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
pcap_header.ts.tv_sec++;
}
}
/* No underlaying filtering system. We need to filter on our own */
if (p->fcode.bf_insns)
if (p->fcode.bf_insns)
{
if (bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
if (bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
{
/* Move to next packet */
header = (dag_record_t*)((char*)header + erf_record_len);
continue;
}
}
/* Fill the header for the user suppplied callback function */
pcap_header.caplen = caplen;
pcap_header.len = packet_len;
/* Call the callback function */
(*callback)(user, &pcap_header, dp);
/* Move to next packet */
header = (dag_record_t*)((char*)header + erf_record_len);
/* Stop if the number of packets requested by user has been reached*/
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt))
if (++n >= cnt && !PACKET_COUNT_IS_UNLIMITED(cnt))
{
p->bp = (char*)header;
p->cc = endofbuf - (char*)header;
@ -456,24 +456,24 @@ pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
}
}
while((u_char*)header < endofbuf);
return 1;
}
#endif /* HAVE_DAG_API */
/* Send a packet to the network */
static int
static int
pcap_inject_win32(pcap_t *p, const void *buf, size_t size){
LPPACKET PacketToSend;
PacketToSend=PacketAllocatePacket();
if (PacketToSend == NULL)
{
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send error: PacketAllocatePacket failed");
return -1;
}
PacketInitPacket(PacketToSend,(PVOID)buf,size);
if(PacketSendPacket(p->adapter,PacketToSend,TRUE) == FALSE){
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send error: PacketSendPacket failed");
@ -524,28 +524,28 @@ pcap_activate_win32(pcap_t *p)
wsockinit();
p->adapter = PacketOpenAdapter(p->opt.source);
if (p->adapter == NULL)
{
/* Adapter detected but we are not able to open it. Return failure. */
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Error opening adapter: %s", pcap_win32strerror());
return PCAP_ERROR;
}
/*get network type*/
if(PacketGetNetType (p->adapter,&type) == FALSE)
{
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Cannot determine the network type: %s", pcap_win32strerror());
goto bad;
}
/*Set the linktype*/
switch (type.LinkType)
switch (type.LinkType)
{
case NdisMediumWan:
p->linktype = DLT_EN10MB;
break;
case NdisMedium802_3:
p->linktype = DLT_EN10MB;
/*
@ -568,27 +568,27 @@ pcap_activate_win32(pcap_t *p)
p->dlt_count = 2;
}
break;
case NdisMediumFddi:
p->linktype = DLT_FDDI;
break;
case NdisMedium802_5:
p->linktype = DLT_IEEE802;
case NdisMedium802_5:
p->linktype = DLT_IEEE802;
break;
case NdisMediumArcnetRaw:
p->linktype = DLT_ARCNET;
break;
case NdisMediumArcnet878_2:
p->linktype = DLT_ARCNET;
break;
case NdisMediumAtm:
p->linktype = DLT_ATM_RFC1483;
break;
case NdisMediumCHDLC:
p->linktype = DLT_CHDLC;
break;
@ -619,7 +619,7 @@ pcap_activate_win32(pcap_t *p)
}
/* Set promiscuous mode */
if (p->opt.promisc)
if (p->opt.promisc)
{
if (PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_PROMISCUOUS) == FALSE)
@ -628,7 +628,7 @@ pcap_activate_win32(pcap_t *p)
goto bad;
}
}
else
else
{
if (PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_ALL_LOCAL) == FALSE)
{
@ -649,8 +649,8 @@ pcap_activate_win32(pcap_t *p)
if(!(p->adapter->Flags & INFO_FLAG_DAG_CARD))
{
/*
* Traditional Adapter
/*
* Traditional Adapter
*/
/*
* If the buffer size wasn't explicitly set, default to
@ -664,16 +664,16 @@ pcap_activate_win32(pcap_t *p)
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: not enough memory to allocate the kernel buffer");
goto bad;
}
p->buffer = (u_char *)malloc(p->bufsize);
if (p->buffer == NULL)
if (p->buffer == NULL)
{
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno));
goto bad;
}
PacketInitPacket(p->Packet,(BYTE*)p->buffer,p->bufsize);
if (p->opt.immediate)
{
/* tell the driver to copy the buffer as soon as data arrives */
@ -696,8 +696,8 @@ pcap_activate_win32(pcap_t *p)
else
#ifdef HAVE_DAG_API
{
/*
* Dag Card
/*
* Dag Card
*/
LONG status;
HKEY dagkey;
@ -705,8 +705,8 @@ pcap_activate_win32(pcap_t *p)
DWORD lpcbdata;
int postype = 0;
char keyname[512];
snprintf(keyname, sizeof(keyname), "%s\\CardParams\\%s",
snprintf(keyname, sizeof(keyname), "%s\\CardParams\\%s",
"SYSTEM\\CurrentControlSet\\Services\\DAG",
strstr(_strlwr(p->opt.source), "dag"));
do
@ -714,36 +714,36 @@ pcap_activate_win32(pcap_t *p)
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyname, 0, KEY_READ, &dagkey);
if(status != ERROR_SUCCESS)
break;
status = RegQueryValueEx(dagkey,
"PosType",
NULL,
&lptype,
(char*)&postype,
&lpcbdata);
if(status != ERROR_SUCCESS)
{
postype = 0;
}
RegCloseKey(dagkey);
}
while(FALSE);
p->snapshot = PacketSetSnapLen(p->adapter, snaplen);
/* Set the length of the FCS associated to any packet. This value
/* Set the length of the FCS associated to any packet. This value
* will be subtracted to the packet length */
pw->dag_fcs_bits = p->adapter->DagFcsLen;
}
#else
goto bad;
#endif /* HAVE_DAG_API */
PacketSetReadTimeout(p->adapter, p->opt.timeout);
#ifdef HAVE_DAG_API
if(p->adapter->Flags & INFO_FLAG_DAG_CARD)
{
@ -884,23 +884,23 @@ pcap_setfilter_win32_npf(pcap_t *p, struct bpf_program *fp)
/*
* We filter at user level, since the kernel driver does't process the packets
*/
static int
static int
pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) {
if(!fp)
if(!fp)
{
strncpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
return -1;
}
/* Install a user level filter */
if (install_bpf_program(p, fp) < 0)
if (install_bpf_program(p, fp) < 0)
{
snprintf(p->errbuf, sizeof(p->errbuf),
"setfilter, unable to install the filter: %s", pcap_strerror(errno));
return -1;
}
return (0);
}

View File

@ -354,12 +354,25 @@ open a
.B pcap_t
for a ``savefile'', given a pathname
.TP
.BR pcap_open_offline_with_tstamp_precision (3PCAP)
open a
.B pcap_t
for a ``savefile'', given a pathname, and specify the precision to
provide for packet time stamps
.TP
.BR pcap_fopen_offline (3PCAP)
open a
.B pcap_t
for a ``savefile'', given a
.B "FILE\ *"
.TP
.BR pcap_fopen_offline_with_tstamp_precision (3PCAP)
open a
.B pcap_t
for a ``savefile'', given a
.BR "FILE\ *" ,
and specify the precision to provide for packet time stamps
.TP
.BR pcap_open_dead (3PCAP)
create a ``fake''
.B pcap_t
@ -424,6 +437,16 @@ get description for a time stamp type
.BR pcap_tstamp_type_name_to_val (3PCAP)
get time stamp type corresponding to a name
.TP
.BR pcap_set_tstamp_precision (3PCAP)
set time stamp precision for a not-yet-activated
.B pcap_t
for live capture
.TP
.BR pcap_get_tstamp_precision (3PCAP)
get the time stamp precision of a
.B pcap_t
for live capture
.TP
.BR pcap_datalink (3PCAP)
get link-layer header type for a
.B pcap_t
@ -552,7 +575,7 @@ bytes of the packet on success, and NULL on error.
.BR pcap_next_ex ()
is passed two pointer arguments, one of which points to a
.IR struct pcap_pkthdr *
and one of which points to a
and one of which points to a
.IR "const u_char" *.
It sets the first pointer to point to a
.I struct pcap_pkthdr
@ -580,7 +603,9 @@ for packets to become available. On some, but
all, platforms, if a read timeout was specified, the wait will terminate
after the read timeout expires; applications should be prepared for
this, as it happens on some platforms, but should not rely on it, as it
does not happen on other platforms.
does not happen on other platforms. Note that the wait might, or might
not, terminate even if no packets are available; applications should be
prepared for this to happen, but must not rely on it happening.
.PP
A handle can be put into ``non-blocking mode'', so that those routines
will, rather than blocking, return an indication that no packets are
@ -596,8 +621,8 @@ Non-blocking mode is often combined with routines such as
.BR select (2)
or
.BR poll (2)
or other routines a platform offers to wait for the availability of data
on any of a set of descriptors. To obtain, for a handle, a descriptor
or other routines a platform offers to wait for any of a set of
descriptors to be ready to read. To obtain, for a handle, a descriptor
that can be used in those routines, call
.BR pcap_get_selectable_fd ().
Not all handles have such a descriptor available;
@ -606,7 +631,14 @@ will return \-1 if no such descriptor exists. In addition, for various
reasons, one or more of those routines will not work properly with the
descriptor; the documentation for
.BR pcap_get_selectable_fd ()
gives details.
gives details. Note that, just as an attempt to read packets from a
.B pcap_t
may not return any packets if the read timeout expires, a
.BR select (),
.BR poll (),
or other such call may, if the read timeout expires, indicate that a
descriptor is ready to read even if there are no packets available to
read.
.TP
.B Routines
.RS

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap.c,v 1.5 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: pcap.c,v 1.6 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pcap.c,v 1.5 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: pcap.c,v 1.6 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -285,7 +285,8 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
pcap_t *
pcap_create(const char *source, char *errbuf)
{
return (dag_create(source, errbuf));
int is_ours;
return (dag_create(source, errbuf, &is_ours));
}
#elif defined(SEPTEL_ONLY)
int
@ -297,7 +298,8 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
pcap_t *
pcap_create(const char *source, char *errbuf)
{
return (septel_create(source, errbuf));
int is_ours;
return (septel_create(source, errbuf, &is_ours));
}
#elif defined(SNF_ONLY)
int
@ -309,7 +311,8 @@ pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)
pcap_t *
pcap_create(const char *source, char *errbuf)
{
return (snf_create(source, errbuf));
int is_ours;
return (snf_create(source, errbuf, &is_ours));
}
#else /* regular pcap */
struct capture_source_type {
@ -566,6 +569,12 @@ pcap_create_common(const char *source, char *ebuf, size_t size)
p->opt.immediate = 0;
p->opt.tstamp_type = -1; /* default to not setting time stamp type */
p->opt.tstamp_precision = PCAP_TSTAMP_PRECISION_MICRO;
/*
* Start out with no BPF code generation flags set.
*/
p->bpf_codegen_flags = 0;
return (p);
}
@ -1836,6 +1845,12 @@ pcap_open_dead_with_tstamp_precision(int linktype, int snaplen, u_int precision)
p->setmintocopy_op = pcap_setmintocopy_dead;
#endif
p->cleanup_op = pcap_cleanup_dead;
/*
* A "dead" pcap_t never requires special BPF code generation.
*/
p->bpf_codegen_flags = 0;
p->activated = 1;
return (p);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: bluetooth.h,v 1.2 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: bluetooth.h,v 1.3 2015/03/31 21:39:43 christos Exp $ */
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -32,7 +32,7 @@
* bluetooth data struct
* By Paolo Abeni <paolo.abeni@email.it>
*/
#ifndef _PCAP_BLUETOOTH_STRUCTS_H__
#define _PCAP_BLUETOOTH_STRUCTS_H__

View File

@ -1,4 +1,4 @@
/* $NetBSD: bpf.h,v 1.6 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: bpf.h,v 1.7 2015/03/31 21:39:43 christos Exp $ */
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@ -6,7 +6,7 @@
*
* This code is derived from the Stanford/CMU enet packet filter,
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* Redistribution and use in source and binary forms, with or without
@ -61,7 +61,8 @@
* or Tru64 UNIX-style multiple-include protection (or, at least,
* Tru64 UNIX 5.x-style; I don't have earlier versions available to check),
* or AIX-style multiple-include protection (or, at least, AIX 5.x-style;
* I don't have earlier versions available to check).
* I don't have earlier versions available to check), or QNX-style
* multiple-include protection (as per GitHub pull request #394).
*
* We do not check for BPF_MAJOR_VERSION, as that's defined by
* <linux/filter.h>, which is directly or indirectly included in some
@ -70,7 +71,7 @@
*
* This also provides our own multiple-include protection.
*/
#if !defined(_NET_BPF_H_) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h)
#if !defined(_NET_BPF_H_) && !defined(_NET_BPF_H_INCLUDED) && !defined(_BPF_H_) && !defined(_H_BPF) && !defined(lib_pcap_bpf_h)
#define lib_pcap_bpf_h
#ifdef __cplusplus
@ -89,7 +90,7 @@ typedef u_int bpf_u_int32;
#endif
/*
* Alignment macros. BPF_WORDALIGN rounds up to the next
* Alignment macros. BPF_WORDALIGN rounds up to the next
* even multiple of BPF_ALIGNMENT.
*
* Tcpdump's print-pflog.c uses this, so we define it here.
@ -108,7 +109,7 @@ struct bpf_program {
u_int bf_len;
struct bpf_insn *bf_insns;
};
/*
* Link-layer header type codes.
*
@ -433,7 +434,7 @@ struct bpf_program {
*/
#define DLT_SUNATM 123 /* Solaris+SunATM */
/*
/*
* Reserved as per request from Kent Dahlgren <kent@praesum.com>
* for private use.
*/
@ -676,7 +677,7 @@ struct bpf_program {
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ are used for prepending meta-information
* like interface index, interface name
* before standard Ethernet, PPP, Frelay & C-HDLC Frames
@ -693,7 +694,7 @@ struct bpf_program {
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for internal communication with a
* voice Adapter Card (PIC)
*/
@ -768,7 +769,7 @@ struct bpf_program {
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for internal communication with a
* integrated service module (ISM).
*/
@ -811,7 +812,7 @@ struct bpf_program {
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for capturing data on a secure tunnel interface.
*/
#define DLT_JUNIPER_ST 200
@ -903,11 +904,11 @@ struct bpf_program {
*/
#define DLT_IEEE802_15_4_NONASK_PHY 215
/*
/*
* David Gibson <david@gibson.dropbear.id.au> requested this for
* captures from the Linux kernel /dev/input/eventN devices. This
* is used to communicate keystrokes and mouse movements from the
* Linux kernel to display systems, such as Xorg.
* Linux kernel to display systems, such as Xorg.
*/
#define DLT_LINUX_EVDEV 216
@ -1107,7 +1108,7 @@ struct bpf_program {
#define DLT_JUNIPER_ATM_CEMIC 238
/*
* NetFilter LOG messages
* NetFilter LOG messages
* (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets)
*
* Requested by Jakub Zawadzki <darkjames-ws@darkjames.pl>
@ -1216,7 +1217,7 @@ struct bpf_program {
/*
* DLT type for upper-protocol layer PDU saves from wireshark.
*
*
* the actual contents are determined by two TAGs stored with each
* packet:
* EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the
@ -1316,7 +1317,19 @@ struct bpf_program {
*/
#define DLT_IPMI_HPM_2 260
#define DLT_MATCHING_MAX 260 /* highest value in the "matching" range */
/*
* per Joshua Wright <jwright@hasborg.com>, formats for Zwave captures.
*/
#define DLT_ZWAVE_R1_R2 261
#define DLT_ZWAVE_R3 262
/*
* per Steve Karg <skarg@users.sourceforge.net>, formats for Wattstopper
* Digital Lighting Management room bus serial protocol captures.
*/
#define DLT_WATTSTOPPER_DLM 263
#define DLT_MATCHING_MAX 263 /* highest value in the "matching" range */
/*
* DLT and savefile link type values are split into a class and
@ -1468,6 +1481,16 @@ struct bpf_insn {
bpf_u_int32 k;
};
/*
* Auxiliary data, for use when interpreting a filter intended for the
* Linux kernel when the kernel rejects the filter (requiring us to
* run it in userland). It contains VLAN tag information.
*/
struct bpf_aux_data {
u_short vlan_tag_present;
u_short vlan_tag;
};
/*
* Macros for insn array initializers.
*/
@ -1477,9 +1500,11 @@ struct bpf_insn {
#if __STDC__ || defined(__cplusplus)
extern int bpf_validate(const struct bpf_insn *, int);
extern u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
extern u_int bpf_filter_with_aux_data(const struct bpf_insn *, const u_char *, u_int, u_int, const struct bpf_aux_data *);
#else
extern int bpf_validate();
extern u_int bpf_filter();
extern u_int bpf_filter();
#endif
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: pcap.h,v 1.5 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: pcap.h,v 1.6 2015/03/31 21:39:43 christos Exp $ */
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
/*
@ -416,6 +416,7 @@ int pcap_fileno(pcap_t *);
pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
pcap_dumper_t *pcap_dump_open_append(pcap_t *, const char *);
FILE *pcap_dump_file(pcap_dumper_t *);
long pcap_dump_ftell(pcap_dumper_t *);
int pcap_dump_flush(pcap_dumper_t *);
@ -428,13 +429,13 @@ void pcap_freealldevs(pcap_if_t *);
const char *pcap_lib_version(void);
/*
* On at least some versions of NetBSD, we don't want to declare
* On at least some versions of NetBSD and QNX, we don't want to declare
* bpf_filter() here, as it's also be declared in <net/bpf.h>, with a
* different signature, but, on other BSD-flavored UN*Xes, it's not
* declared in <net/bpf.h>, so we *do* want to declare it here, so it's
* declared when we build pcap-bpf.c.
*/
#ifndef __NetBSD__
#if !defined(__NetBSD__) && !defined(__QNX__)
u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
#endif
int bpf_validate(const struct bpf_insn *f, int len);

View File

@ -1,4 +1,4 @@
/* $NetBSD: usb.h,v 1.2 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: usb.h,v 1.3 2015/03/31 21:39:43 christos Exp $ */
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
@ -13,8 +13,8 @@
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -32,11 +32,11 @@
* Basic USB data struct
* By Paolo Abeni <paolo.abeni@email.it>
*/
#ifndef _PCAP_USB_STRUCTS_H__
#define _PCAP_USB_STRUCTS_H__
/*
/*
* possible transfer mode
*/
#define URB_TRANSFER_IN 0x80

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pcap_breakloop.3pcap,v 1.2 2014/11/19 19:33:30 christos Exp $
.\" $NetBSD: pcap_breakloop.3pcap,v 1.3 2015/03/31 21:39:42 christos Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@ -93,7 +93,7 @@ If \-2 is returned from
.B pcap_dispatch()
or
.BR pcap_loop() ,
the flag is cleared, so a subsequent call will resume reading packets.
the flag is cleared, so a subsequent call will resume reading packets.
If a positive number is returned, the flag is not cleared, so a
subsequent call will return \-2 and clear the flag.
.SH SEE ALSO

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pcap_datalink_name_to_val.3pcap,v 1.2 2014/11/19 19:33:30 christos Exp $
.\" $NetBSD: pcap_datalink_name_to_val.3pcap,v 1.3 2015/03/31 21:39:42 christos Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@ -43,6 +43,6 @@ removed, to the corresponding link-layer header type value. The
translation is case-insensitive.
.SH RETURN VALUE
.B pcap_datalink_name_to_val()
returns 0 on success and \-1 on failure.
returns type value on success and \-1 on failure.
.SH SEE ALSO
pcap(3PCAP)

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pcap_dump.3pcap,v 1.2 2014/11/19 19:33:30 christos Exp $
.\" $NetBSD: pcap_dump.3pcap,v 1.3 2015/03/31 21:39:42 christos Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@ -42,9 +42,9 @@ Note that its calling arguments are suitable for use with
.B pcap_dispatch()
or
.BR pcap_loop() .
If called directly, the
If called directly, the
.I user
parameter is of type
parameter is of type
.B pcap_dumper_t
as returned by
.BR pcap_dump_open() .

View File

@ -29,6 +29,7 @@ pcap_dump_open, pcap_dump_fopen \- open a file to which to write packets
.LP
.ft B
pcap_dumper_t *pcap_dump_open(pcap_t *p, const char *fname);
pcap_dumper_t *pcap_dump_open_append(pcap_t *p, const char *fname);
pcap_dumper_t *pcap_dump_fopen(pcap_t *p, FILE *fp);
.ft
.fi
@ -60,9 +61,19 @@ or returned by an earlier call to
.BR pcap_open_live() ,
or
.BR pcap_open_dead() .
The link-layer type and snapshot length from
The time stamp precision, link-layer type, and snapshot length from
.I p
are used as the link-layer type and snapshot length of the output file.
.PP
.B pcap_dump_open_append()
is like
.B pcap_dump_open
but does not create the file if it does not exist and, if it does
already exist, and is a pcap file with the same byte order as the host
opening the file, and has the same time stamp precision, link-layer
header type, and snapshot length as
.IR p ,
it will write new packets at the end of the file.
.SH RETURN VALUES
A pointer to a
.B pcap_dumper_t

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pcap_get_selectable_fd.3pcap,v 1.2 2014/11/19 19:33:30 christos Exp $
.\" $NetBSD: pcap_get_selectable_fd.3pcap,v 1.3 2015/03/31 21:39:42 christos Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@ -38,9 +38,9 @@ int pcap_get_selectable_fd(pcap_t *p);
returns, on UNIX, a file descriptor number for a file descriptor on
which one can
do a
.B select()
or
.B poll()
.BR select() ,
.BR poll() ,
or other such call
to wait for it to be possible to read packets without blocking, if such
a descriptor exists, or \-1, if no such descriptor exists. Some network
devices opened with
@ -56,6 +56,12 @@ or
(for example, regular network devices on FreeBSD 4.3 and 4.4, and Endace
DAG devices), so \-1 is returned for those devices.
.PP
Note that a descriptor on which a read can be done without blocking may,
on some platforms, not have any packets to read if the read timeout has
expired. A call to
.B pcap_dispatch()
will return 0 in this case, but will not block.
.PP
Note that in:
.IP
FreeBSD prior to FreeBSD 4.6;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pcap_loop.3pcap,v 1.2 2014/11/19 19:33:30 christos Exp $
.\" $NetBSD: pcap_loop.3pcap,v 1.3 2015/03/31 21:39:42 christos Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@ -79,6 +79,13 @@ causes all the packets received in one buffer to be processed when
reading a live capture, and causes all the packets in the file to be
processed when reading a ``savefile''.
.PP
Note that, when doing a live capture on some platforms, if the read
timeout expires when there are no packets available,
.B pcap_dispatch()
will return 0, even when not in non-blocking mode, as there are no
packets to process. Applications should be prepared for this to happen,
but must not rely on it happening.
.PP
.ft B
(In older versions of libpcap, the behavior when
\fIcnt\fP

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pcap_setdirection.3pcap,v 1.2 2014/11/19 19:33:30 christos Exp $
.\" $NetBSD: pcap_setdirection.3pcap,v 1.3 2015/03/31 21:39:42 christos Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@ -39,7 +39,7 @@ is used to specify a direction that packets will be captured.
is one of the constants
.BR PCAP_D_IN ,
.B PCAP_D_OUT
or
or
.BR PCAP_D_INOUT .
.B PCAP_D_IN
will only capture packets received by the device,

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pcap_setnonblock.3pcap,v 1.2 2014/11/19 19:33:30 christos Exp $
.\" $NetBSD: pcap_setnonblock.3pcap,v 1.3 2015/03/31 21:39:42 christos Exp $
.\"
.\" Copyright (c) 1994, 1996, 1997
.\" The Regents of the University of California. All rights reserved.
@ -59,6 +59,14 @@ immediately rather than blocking waiting for packets to arrive.
and
.B pcap_next()
will not work in ``non-blocking'' mode.
.PP
When first activated with
.B pcap_activate()
or opened with
.B pcap_open_live() ,
a capture handle is not in ``non-blocking mode''; a call to
.B pcap_setnonblock()
is required in order to put it into ``non-blocking'' mode.
.SH RETURN VALUE
.B pcap_getnonblock()
returns the current ``non-blocking'' state of the capture descriptor; it

View File

@ -1,4 +1,4 @@
.\" $NetBSD: pcap_tstamp_type_name_to_val.3pcap,v 1.2 2014/11/19 19:33:30 christos Exp $
.\" $NetBSD: pcap_tstamp_type_name_to_val.3pcap,v 1.3 2015/03/31 21:39:42 christos Exp $
.\"
.\"
.\" Copyright (c) 1994, 1996, 1997
@ -40,7 +40,7 @@ translates a time stamp type name to the corresponding time stamp type
value. The translation is case-insensitive.
.SH RETURN VALUE
.B pcap_tstamp_type_name_to_val()
returns 0 on success and
returns time stamp type value on success and
.B PCAP_ERROR
on failure.
.SH SEE ALSO

View File

@ -1,4 +1,4 @@
/* $NetBSD: savefile.c,v 1.2 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: savefile.c,v 1.3 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: savefile.c,v 1.2 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: savefile.c,v 1.3 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -223,14 +223,14 @@ pcap_t* pcap_hopen_offline_with_tstamp_precision(intptr_t osfd, u_int precision,
FILE *file;
fd = _open_osfhandle(osfd, _O_RDONLY);
if ( fd < 0 )
if ( fd < 0 )
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, pcap_strerror(errno));
return NULL;
}
file = _fdopen(fd, "rb");
if ( file == NULL )
if ( file == NULL )
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, pcap_strerror(errno));
return NULL;
@ -349,6 +349,11 @@ found:
*/
p->oneshot_callback = pcap_oneshot;
/*
* Savefiles never require special BPF code generation.
*/
p->bpf_codegen_flags = 0;
p->activated = 1;
return (p);

View File

@ -1,4 +1,4 @@
/* $NetBSD: scanner.l,v 1.6 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: scanner.l,v 1.7 2015/03/31 21:39:42 christos Exp $ */
%{
/*
@ -22,11 +22,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: scanner.l,v 1.6 2014/11/19 19:33:30 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
__RCSID("$NetBSD: scanner.l,v 1.7 2015/03/31 21:39:42 christos Exp $");
#ifdef WIN32
#include <pcap-stdinc.h>
@ -285,6 +281,7 @@ vlan return VLAN;
mpls return MPLS;
pppoed return PPPOED;
pppoes return PPPOES;
geneve return GENEVE;
lane return LANE;
llc return LLC;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sf-pcap-ng.c,v 1.5 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: sf-pcap-ng.c,v 1.6 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@ -29,7 +29,7 @@ static const char rcsid[] _U_ =
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: sf-pcap-ng.c,v 1.5 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: sf-pcap-ng.c,v 1.6 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -669,7 +669,7 @@ pcap_ng_check_header(bpf_u_int32 magic, FILE *fp, u_int precision, char *errbuf,
/*
* Check whether the first 4 bytes of the file are the block
* type for a pcap-ng savefile.
* type for a pcap-ng savefile.
*/
if (magic != BT_SHB) {
/*
@ -1005,7 +1005,7 @@ pcap_ng_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data)
epbp->timestamp_low;
}
goto found;
case BT_SPB:
/*
* Get a pointer to the fixed-length portion of the
@ -1197,7 +1197,7 @@ pcap_ng_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char **data)
* Not a packet block, IDB, or SHB; ignore it.
*/
break;
}
}
}
found:
@ -1215,10 +1215,16 @@ found:
}
/*
* Convert the time stamp to a struct timeval.
* Convert the time stamp to seconds and fractions of a second,
* with the fractions being in units of the file-supplied resolution.
*/
sec = t / ps->ifaces[interface_id].tsresol + ps->ifaces[interface_id].tsoffset;
frac = t % ps->ifaces[interface_id].tsresol;
/*
* Convert the fractions from units of the file-supplied resolution
* to units of the user-requested resolution.
*/
switch (ps->ifaces[interface_id].scale_type) {
case PASS_THROUGH:
@ -1232,21 +1238,28 @@ found:
case SCALE_DOWN:
/*
* The interface resolution is different from what the
* user wants; scale up or down to that resolution.
* user wants; convert the fractions to units of the
* resolution the user requested by multiplying by the
* quotient of the user-requested resolution and the
* file-supplied resolution. We do that by multiplying
* by the user-requested resolution and dividing by the
* file-supplied resolution, as the quotient might not
* fit in an integer.
*
* XXX - if ps->ifaces[interface_id].tsresol is a power
* of 10, we could just multiply by the quotient of
* ps->ifaces[interface_id].tsresol and ps->user_tsresol
* in the scale-up case, and divide by the quotient of
* ps->user_tsresol and ps->ifaces[interface_id].tsresol
* in the scale-down case, as we know those are integers,
* which would involve fewer arithmetic operations.
* in the scale-up case, and divide by the quotient of
* ps->ifaces[interface_id].tsresol and ps->user_tsresol
* in the scale-down case, as we know those will be integers.
* That would involve fewer arithmetic operations, and
* would run less risk of overflow.
*
* Is there something clever we could do if
* ps->ifaces[interface_id].tsresol is a power of 2?
*/
frac *= ps->ifaces[interface_id].tsresol;
frac /= ps->user_tsresol;
frac *= ps->user_tsresol;
frac /= ps->ifaces[interface_id].tsresol;
break;
}
hdr->ts.tv_sec = sec;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sf-pcap.c,v 1.5 2014/11/19 19:33:30 christos Exp $ */
/* $NetBSD: sf-pcap.c,v 1.6 2015/03/31 21:39:42 christos Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
@ -36,7 +36,7 @@ static const char rcsid[] _U_ =
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: sf-pcap.c,v 1.5 2014/11/19 19:33:30 christos Exp $");
__RCSID("$NetBSD: sf-pcap.c,v 1.6 2015/03/31 21:39:42 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -687,7 +687,7 @@ pcap_dump_open(pcap_t *p, const char *fname)
*/
pcap_dumper_t *
pcap_dump_fopen(pcap_t *p, FILE *f)
{
{
int linktype;
linktype = dlt_to_linktype(p->linktype);
@ -702,6 +702,168 @@ pcap_dump_fopen(pcap_t *p, FILE *f)
return (pcap_setup_dump(p, linktype, f, "stream"));
}
pcap_dumper_t *
pcap_dump_open_append(pcap_t *p, const char *fname)
{
FILE *f;
int linktype;
int amt_read;
struct pcap_file_header ph;
linktype = dlt_to_linktype(p->linktype);
if (linktype == -1) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: link-layer type %d isn't supported in savefiles",
fname, linktype);
return (NULL);
}
if (fname[0] == '-' && fname[1] == '\0')
return (pcap_setup_dump(p, linktype, stdout, "standard output"));
#if !defined(WIN32) && !defined(MSDOS)
f = fopen(fname, "r+");
#else
f = fopen(fname, "rb+");
#endif
if (f == NULL) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
fname, pcap_strerror(errno));
return (NULL);
}
/*
* Try to read a pcap header.
*/
amt_read = fread(&ph, 1, sizeof (ph), f);
if (amt_read != sizeof (ph)) {
if (ferror(f)) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
fname, pcap_strerror(errno));
fclose(f);
return (NULL);
} else if (feof(f) && amt_read > 0) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: truncated pcap file header", fname);
fclose(f);
return (NULL);
}
}
#if defined(WIN32) || defined(MSDOS)
/*
* We turn off buffering.
* XXX - why? And why not on the standard output?
*/
setbuf(f, NULL);
#endif
/*
* If a header is already present and:
*
* it's not for a pcap file of the appropriate resolution
* and the right byte order for this machine;
*
* the link-layer header types don't match;
*
* the snapshot lengths don't match;
*
* return an error.
*/
if (amt_read > 0) {
/*
* A header is already present.
* Do the checks.
*/
switch (ph.magic) {
case TCPDUMP_MAGIC:
if (p->opt.tstamp_precision != PCAP_TSTAMP_PRECISION_MICRO) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: different time stamp precision, cannot append to file", fname);
fclose(f);
return (NULL);
}
break;
case NSEC_TCPDUMP_MAGIC:
if (p->opt.tstamp_precision != PCAP_TSTAMP_PRECISION_NANO) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: different time stamp precision, cannot append to file", fname);
fclose(f);
return (NULL);
}
break;
case SWAPLONG(TCPDUMP_MAGIC):
case SWAPLONG(NSEC_TCPDUMP_MAGIC):
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: different byte order, cannot append to file", fname);
fclose(f);
return (NULL);
case KUZNETZOV_TCPDUMP_MAGIC:
case SWAPLONG(KUZNETZOV_TCPDUMP_MAGIC):
case NAVTEL_TCPDUMP_MAGIC:
case SWAPLONG(NAVTEL_TCPDUMP_MAGIC):
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: not a pcap file to which we can append", fname);
fclose(f);
return (NULL);
default:
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: not a pcap file", fname);
fclose(f);
return (NULL);
}
/*
* Good version?
*/
if (ph.version_major != PCAP_VERSION_MAJOR ||
ph.version_minor != PCAP_VERSION_MINOR) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: version is %u.%u, cannot append to file", fname,
ph.version_major, ph.version_minor);
fclose(f);
return (NULL);
}
if (linktype != (int)ph.linktype) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: different linktype, cannot append to file", fname);
fclose(f);
return (NULL);
}
if (p->snapshot != (int)ph.snaplen) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"%s: different snaplen, cannot append to file", fname);
fclose(f);
return (NULL);
}
} else {
/*
* A header isn't present; attempt to write it.
*/
if (sf_write_header(p, f, linktype, p->tzoff, p->snapshot) == -1) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Can't write to %s: %s",
fname, pcap_strerror(errno));
(void)fclose(f);
return (NULL);
}
}
/*
* Start writing at the end of the file.
*/
if (fseek(f, 0, SEEK_END) == -1) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Can't seek to end of %s: %s",
fname, pcap_strerror(errno));
(void)fclose(f);
return (NULL);
}
return ((pcap_dumper_t *)f);
}
FILE *
pcap_dump_file(pcap_dumper_t *p)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: filtertest.c,v 1.2 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: filtertest.c,v 1.3 2015/03/31 21:39:43 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
@ -28,7 +28,7 @@ The Regents of the University of California. All rights reserved.\n";
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: filtertest.c,v 1.2 2014/11/19 19:33:31 christos Exp $");
__RCSID("$NetBSD: filtertest.c,v 1.3 2015/03/31 21:39:43 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -62,6 +62,9 @@ static void warn(const char *, ...)
extern int optind;
extern int opterr;
extern char *optarg;
#ifdef BDEBUG
int dflag;
#endif
/*
* On Windows, we need to open the file in binary mode, so that
@ -183,10 +186,13 @@ main(int argc, char **argv)
{
char *cp;
int op;
#ifndef BDEBUG
int dflag;
#endif
char *infile;
int Oflag;
long snaplen;
char *p;
int dlt;
bpf_u_int32 netmask = PCAP_NETMASK_UNKNOWN;
char *cmdbuf;
@ -197,11 +203,19 @@ main(int argc, char **argv)
if(wsockinit() != 0) return 1;
#endif /* WIN32 */
#ifndef BDEBUG
dflag = 1;
#else
/* if optimizer debugging is enabled, output DOT graph
* `dflag=4' is equivalent to -dddd to follow -d/-dd/-ddd
* convention in tcpdump command line
*/
dflag = 4;
#endif
infile = NULL;
Oflag = 1;
snaplen = 68;
if ((cp = strrchr(argv[0], '/')) != NULL)
program_name = cp + 1;
else
@ -257,9 +271,12 @@ main(int argc, char **argv)
}
dlt = pcap_datalink_name_to_val(argv[optind]);
if (dlt < 0)
error("invalid data link type %s", argv[optind]);
if (dlt < 0) {
dlt = (int)strtol(argv[optind], &p, 10);
if (p == argv[optind] || *p != '\0')
error("invalid data link type %s", argv[optind]);
}
if (infile)
cmdbuf = read_infile(infile);
else
@ -271,8 +288,21 @@ main(int argc, char **argv)
if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0)
error("%s", pcap_geterr(pd));
if (!bpf_validate(fcode.bf_insns, fcode.bf_len))
warn("Filter doesn't pass validation");
#ifdef BDEBUG
// replace line feed with space
for (cp = cmdbuf; *cp != '\0'; ++cp) {
if (*cp == '\r' || *cp == '\n') {
*cp = ' ';
}
}
// only show machine code if BDEBUG defined, since dflag > 3
printf("machine codes for filter: %s\n", cmdbuf);
#endif
bpf_dump(&fcode, dflag);
pcap_close(pd);
exit(0);

View File

@ -1,7 +1,7 @@
/* $NetBSD: findalldevstest.c,v 1.2 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: findalldevstest.c,v 1.3 2015/03/31 21:39:43 christos Exp $ */
#include <sys/cdefs.h>
__RCSID("$NetBSD: findalldevstest.c,v 1.2 2014/11/19 19:33:31 christos Exp $");
__RCSID("$NetBSD: findalldevstest.c,v 1.3 2015/03/31 21:39:43 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -16,7 +16,7 @@ __RCSID("$NetBSD: findalldevstest.c,v 1.2 2014/11/19 19:33:31 christos Exp $");
#include <pcap.h>
static void ifprint(pcap_if_t *d);
static int ifprint(pcap_if_t *d);
static char *iptos(bpf_u_int32 in);
int main(int argc, char **argv)
@ -25,7 +25,8 @@ int main(int argc, char **argv)
pcap_if_t *d;
char *s;
bpf_u_int32 net, mask;
int exit_status = 0;
char errbuf[PCAP_ERRBUF_SIZE+1];
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
@ -34,12 +35,14 @@ int main(int argc, char **argv)
}
for(d=alldevs;d;d=d->next)
{
ifprint(d);
if (!ifprint(d))
exit_status = 2;
}
if ( (s = pcap_lookupdev(errbuf)) == NULL)
{
fprintf(stderr,"Error in pcap_lookupdev: %s\n",errbuf);
exit_status = 2;
}
else
{
@ -49,21 +52,23 @@ int main(int argc, char **argv)
if (pcap_lookupnet(s, &net, &mask, errbuf) < 0)
{
fprintf(stderr,"Error in pcap_lookupnet: %s\n",errbuf);
exit_status = 2;
}
else
{
printf("Preferred device is on network: %s/%s\n",iptos(net), iptos(mask));
}
exit(0);
exit(exit_status);
}
static void ifprint(pcap_if_t *d)
static int ifprint(pcap_if_t *d)
{
pcap_addr_t *a;
#ifdef INET6
char ntop_buf[INET6_ADDRSTRLEN];
#endif
int status = 1; /* success */
printf("%s\n",d->name);
if (d->description)
@ -71,8 +76,8 @@ static void ifprint(pcap_if_t *d)
printf("\tLoopback: %s\n",(d->flags & PCAP_IF_LOOPBACK)?"yes":"no");
for(a=d->addresses;a;a=a->next) {
switch(a->addr->sa_family)
{
if (a->addr != NULL)
switch(a->addr->sa_family) {
case AF_INET:
printf("\tAddress Family: AF_INET\n");
if (a->addr)
@ -116,9 +121,15 @@ static void ifprint(pcap_if_t *d)
default:
printf("\tAddress Family: Unknown (%d)\n", a->addr->sa_family);
break;
}
else
{
fprintf(stderr, "\tWarning: a->addr is NULL, skipping this address.\n");
status = 0;
}
}
printf("\n");
return status;
}
/* From tcptraceroute */

View File

@ -1,4 +1,4 @@
/* $NetBSD: valgrindtest.c,v 1.2 2014/11/19 19:33:31 christos Exp $ */
/* $NetBSD: valgrindtest.c,v 1.3 2015/03/31 21:39:43 christos Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
@ -28,7 +28,7 @@ The Regents of the University of California. All rights reserved.\n";
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: valgrindtest.c,v 1.2 2014/11/19 19:33:31 christos Exp $");
__RCSID("$NetBSD: valgrindtest.c,v 1.3 2015/03/31 21:39:43 christos Exp $");
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -236,7 +236,7 @@ main(int argc, char **argv)
dorfmon = 0;
useactivate = 0;
infile = NULL;
if ((cp = strrchr(argv[0], '/')) != NULL)
program_name = cp + 1;
else

View File

@ -1,5 +1,5 @@
# $NetBSD: shlib_version,v 1.2 2013/04/06 17:29:12 christos Exp $
# $NetBSD: shlib_version,v 1.3 2015/03/31 21:39:43 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=5
minor=0
minor=1