aboutsummaryrefslogtreecommitdiff
path: root/pcap-nit.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-05-08 13:06:27 -0700
committerGuy Harris <guy@alum.mit.edu>2013-05-08 13:06:27 -0700
commit48bc6c35b191857f39b628bd586bd94a03fd13d7 (patch)
treeb44a5a8e6e645194d16d4ddef0a03f0e61509a2d /pcap-nit.c
parent98b7898b2a9906714cc91c818a820f7e47da41b2 (diff)
Add an API to set "immediate mode".
In "immediate mode", packets are delivered as soon as they arrive.
Diffstat (limited to 'pcap-nit.c')
-rw-r--r--pcap-nit.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/pcap-nit.c b/pcap-nit.c
index 8e357211..5610b293 100644
--- a/pcap-nit.c
+++ b/pcap-nit.c
@@ -218,28 +218,42 @@ pcap_inject_nit(pcap_t *p, const void *buf, size_t size)
}
static int
-nit_setflags(int fd, int promisc, int to_ms, char *ebuf)
+nit_setflags(pcap_t *p)
{
struct nit_ioc nioc;
memset(&nioc, 0, sizeof(nioc));
- nioc.nioc_bufspace = BUFSPACE;
- nioc.nioc_chunksize = CHUNKSIZE;
nioc.nioc_typetomatch = NT_ALLTYPES;
nioc.nioc_snaplen = p->snapshot;
nioc.nioc_bufalign = sizeof(int);
nioc.nioc_bufoffset = 0;
- if (to_ms != 0) {
+ if (p->opt.buffer_size != 0)
+ nioc.nioc_bufspace = p->opt.buffer_size;
+ else {
+ /* Default buffer size */
+ nioc.nioc_bufspace = BUFSPACE;
+ }
+
+ if (p->opt.immediate) {
+ /*
+ * XXX - will this cause packets to be delivered immediately?
+ * XXX - given that this is for SunOS prior to 4.0, do
+ * we care?
+ */
+ nioc.nioc_chunksize = 0;
+ } else
+ nioc.nioc_chunksize = CHUNKSIZE;
+ if (p->opt.timeout != 0) {
nioc.nioc_flags |= NF_TIMEOUT;
- nioc.nioc_timeout.tv_sec = to_ms / 1000;
- nioc.nioc_timeout.tv_usec = (to_ms * 1000) % 1000000;
+ nioc.nioc_timeout.tv_sec = p->opt.timeout / 1000;
+ nioc.nioc_timeout.tv_usec = (p->opt.timeout * 1000) % 1000000;
}
- if (promisc)
+ if (p->opt.promisc)
nioc.nioc_flags |= NF_PROMISC;
- if (ioctl(fd, SIOCSNIT, &nioc) < 0) {
- snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCSNIT: %s",
+ if (ioctl(p->fd, SIOCSNIT, &nioc) < 0) {
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "SIOCSNIT: %s",
pcap_strerror(errno));
return (-1);
}
@@ -282,7 +296,8 @@ pcap_activate_nit(pcap_t *p)
"bind: %s: %s", snit.snit_ifname, pcap_strerror(errno));
goto bad;
}
- nit_setflags(p->fd, p->opt.promisc, p->opt.timeout, p->errbuf);
+ if (nit_setflags(p) < 0)
+ goto bad;
/*
* NIT supports only ethernets.