version 1.2, 2013/06/26 22:48:53
|
version 1.3, 2013/07/09 00:35:36
|
Line 135 allocZCbuf(u_int len)
|
Line 135 allocZCbuf(u_int len)
|
* @csIface = interface name |
* @csIface = interface name |
* @flags = open flags |
* @flags = open flags |
* @whdr = with complete headers |
* @whdr = with complete headers |
|
* @wdlt = with data link type |
* @buflen = buffer length |
* @buflen = buffer length |
* @zcbuf = zero copy buffer, if BPF supports it and isn't NULL |
* @zcbuf = zero copy buffer, if BPF supports it and isn't NULL |
* return: -1 error or >-1 bpf handle |
* return: -1 error or >-1 bpf handle |
*/ |
*/ |
int |
int |
io_etherOpen(const char *csIface, int flags, int whdr, u_int *buflen, void **zcbuf) | io_etherOpen(const char *csIface, int flags, int whdr, int wdlt, |
| u_int *buflen, void **zcbuf) |
{ |
{ |
int eth = -1; |
int eth = -1; |
register int i; |
register int i; |
Line 229 io_etherOpen(const char *csIface, int flags, int whdr,
|
Line 231 io_etherOpen(const char *csIface, int flags, int whdr,
|
io_etherClose(eth, zcbuf); |
io_etherClose(eth, zcbuf); |
return -1; |
return -1; |
} |
} |
|
if (wdlt && ioctl(eth, BIOCSDLT, &wdlt) == -1) { |
|
LOGERR; |
|
io_etherClose(eth, zcbuf); |
|
return -1; |
|
} |
if (ioctl(eth, BIOCIMMEDIATE, &n) == -1) { |
if (ioctl(eth, BIOCIMMEDIATE, &n) == -1) { |
LOGERR; |
LOGERR; |
io_etherClose(eth, zcbuf); |
io_etherClose(eth, zcbuf); |
Line 321 ssize_t
|
Line 328 ssize_t
|
io_etherRecv(int eth, void * __restrict buf, size_t buflen, void * __restrict zcbuf) |
io_etherRecv(int eth, void * __restrict buf, size_t buflen, void * __restrict zcbuf) |
{ |
{ |
ssize_t rlen = 0; |
ssize_t rlen = 0; |
|
struct bpf_hdr *h; |
|
|
if (!buf || !buflen) { |
if (!buf || !buflen) { |
io_SetErr(EINVAL, "invalid arguments"); |
io_SetErr(EINVAL, "invalid arguments"); |
Line 342 io_etherRecv(int eth, void * __restrict buf, size_t bu
|
Line 350 io_etherRecv(int eth, void * __restrict buf, size_t bu
|
#endif |
#endif |
} |
} |
|
|
|
h = (struct bpf_hdr*) buf; |
|
rlen -= h->bh_hdrlen; |
|
|
|
if (h->bh_caplen != rlen) { |
|
if (h->bh_caplen < rlen) |
|
rlen = h->bh_caplen; |
|
else { |
|
io_SetErr(EIO, "Captured %d bytes should be at most %d bytes", |
|
h->bh_caplen, rlen); |
|
return -1; |
|
} |
|
} |
|
|
|
memmove(buf, buf + h->bh_hdrlen, rlen); |
return rlen; |
return rlen; |
} |
} |