version 1.3, 2013/07/09 00:35:36
|
version 1.3.8.2, 2013/10/21 15:39:15
|
Line 337 io_etherRecv(int eth, void * __restrict buf, size_t bu
|
Line 337 io_etherRecv(int eth, void * __restrict buf, size_t bu
|
|
|
if (!zcbuf) { |
if (!zcbuf) { |
rlen = read(eth, buf, buflen); |
rlen = read(eth, buf, buflen); |
if (rlen == -1) | if (rlen == -1) { |
LOGERR; |
LOGERR; |
|
return -1; |
|
} |
} else { |
} else { |
#ifdef __FreeBSD__ |
#ifdef __FreeBSD__ |
rlen = nextZCbuf(eth, (struct bpf_zbuf*) zcbuf, buf, buflen); |
rlen = nextZCbuf(eth, (struct bpf_zbuf*) zcbuf, buf, buflen); |
Line 365 io_etherRecv(int eth, void * __restrict buf, size_t bu
|
Line 367 io_etherRecv(int eth, void * __restrict buf, size_t bu
|
|
|
memmove(buf, buf + h->bh_hdrlen, rlen); |
memmove(buf, buf + h->bh_hdrlen, rlen); |
return rlen; |
return rlen; |
|
} |
|
|
|
/* |
|
* io_etherFilter() - BPF filter routine |
|
* |
|
* @eth = bpf handle |
|
* @io = filter direction |
|
* (IO_ETHER_FILTER_PROMISC|IO_ETHER_FILTER_NOTREAD|IO_ETHER_FILTER_READ|IO_ETHER_FILTER_WRITE) |
|
* @insn = BPF filter instruction array |
|
* @insnlen = Length of BPF filter instruction array |
|
* return: -1 error or 0 ok |
|
*/ |
|
int |
|
io_etherFilter(int eth, int io, struct bpf_insn * __restrict insn, size_t insnlen) |
|
{ |
|
int ret = 0; |
|
struct bpf_program fcode = { 0 }; |
|
|
|
if (io != IO_ETHER_FILTER_PROMISC && (!insn || !insnlen)) { |
|
io_SetErr(EINVAL, "invalid arguments"); |
|
return -1; |
|
} |
|
|
|
switch (io) { |
|
case IO_ETHER_FILTER_PROMISC: /* promiscuous mode */ |
|
ret = ioctl(eth, BIOCPROMISC, NULL); |
|
break; |
|
case IO_ETHER_FILTER_NOTREAD: /* read not filter */ |
|
fcode.bf_len = insnlen / sizeof(struct bpf_insn); |
|
fcode.bf_insns = insn; |
|
ret = ioctl(eth, BIOCSETFNR, &fcode); |
|
break; |
|
case IO_ETHER_FILTER_READ: /* read filter */ |
|
fcode.bf_len = insnlen / sizeof(struct bpf_insn); |
|
fcode.bf_insns = insn; |
|
ret = ioctl(eth, BIOCSETF, &fcode); |
|
break; |
|
case IO_ETHER_FILTER_WRITE: /* write filter */ |
|
fcode.bf_len = insnlen / sizeof(struct bpf_insn); |
|
fcode.bf_insns = insn; |
|
ret = ioctl(eth, BIOCSETWF, &fcode); |
|
break; |
|
} |
|
|
|
if (ret == -1) |
|
LOGERR; |
|
return ret; |
} |
} |