コード例 #1
0
ファイル: dlpisubs.c プロジェクト: frankxiongzz/nmacapi
/*
 * Push and configure the buffer module. Returns -1 for error, otherwise 0.
 */
int
pcap_conf_bufmod(pcap_t *p, int snaplen)
{
    struct timeval to;
    bpf_u_int32 ss, chunksize;

    /* Non-standard call to get the data nicely buffered. */
    if (ioctl(p->fd, I_PUSH, "bufmod") != 0) {
        pcap_stream_err("I_PUSH bufmod", errno, p->errbuf);
        return (-1);
    }

    ss = snaplen;
    if (ss > 0 &&
            strioctl(p->fd, SBIOCSSNAP, sizeof(ss), (char *)&ss) != 0) {
        pcap_stream_err("SBIOCSSNAP", errno, p->errbuf);
        return (-1);
    }

    if (p->opt.immediate) {
        /* Set the timeout to zero, for immediate delivery. */
        to.tv_sec = 0;
        to.tv_usec = 0;
        if (strioctl(p->fd, SBIOCSTIME, sizeof(to), (char *)&to) != 0) {
            pcap_stream_err("SBIOCSTIME", errno, p->errbuf);
            return (-1);
        }
    } else {
        /* Set up the bufmod timeout. */
        if (p->opt.timeout != 0) {
            to.tv_sec = p->opt.timeout / 1000;
            to.tv_usec = (p->opt.timeout * 1000) % 1000000;
            if (strioctl(p->fd, SBIOCSTIME, sizeof(to), (char *)&to) != 0) {
                pcap_stream_err("SBIOCSTIME", errno, p->errbuf);
                return (-1);
            }
        }

        /* Set the chunk length. */
        chunksize = CHUNKSIZE;
        if (strioctl(p->fd, SBIOCSCHUNK, sizeof(chunksize), (char *)&chunksize)
                != 0) {
            pcap_stream_err("SBIOCSCHUNKP", errno, p->errbuf);
            return (-1);
        }
    }

    return (0);
}
コード例 #2
0
/*
 * Push and configure the buffer module. Returns -1 for error, otherwise 0.
 */
int
pcap_conf_bufmod(pcap_t *p, int snaplen, int timeout)
{
	int retv = 0;

	bpf_u_int32 ss, chunksize;

	/* Non-standard call to get the data nicely buffered. */
	if (ioctl(p->fd, I_PUSH, "bufmod") != 0) {
		pcap_stream_err("I_PUSH bufmod", errno, p->errbuf);
		retv = -1;
	}

	ss = snaplen;
	if (ss > 0 &&
	    strioctl(p->fd, SBIOCSSNAP, sizeof(ss), (char *)&ss) != 0) {
		pcap_stream_err("SBIOCSSNAP", errno, p->errbuf);
		retv = -1;
	}

	/* Set up the bufmod timeout. */
	if (timeout != 0) {
		struct timeval to;

		to.tv_sec = timeout / 1000;
		to.tv_usec = (timeout * 1000) % 1000000;
		if (strioctl(p->fd, SBIOCSTIME, sizeof(to), (char *)&to) != 0) {
			pcap_stream_err("SBIOCSTIME", errno, p->errbuf);
			retv = -1;
		}
	}

	/* Set the chunk length. */
	chunksize = CHUNKSIZE;
	if (strioctl(p->fd, SBIOCSCHUNK, sizeof(chunksize), (char *)&chunksize)
	    != 0) {
		pcap_stream_err("SBIOCSCHUNKP", errno, p->errbuf);
		retv = -1;
	}

	return (retv);
}