Lines Matching +full:no +full:- +full:pc +full:- +full:write

63 #include "pcap-int.h"
66 #include "os-proto.h"
98 pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
100 struct pcap_pf *pf = pc->priv;
108 cc = pc->cc;
110 cc = read(pc->fd, (char *)pc->buffer + pc->offset, pc->bufsize);
115 lseek(pc->fd, 0L, SEEK_CUR) + pc->bufsize < 0) {
122 (void)lseek(pc->fd, 0L, SEEK_SET);
125 pcapint_fmt_errmsg_for_errno(pc->errbuf,
126 sizeof(pc->errbuf), errno, "pf read");
127 return (-1);
129 bp = (u_char *)pc->buffer + pc->offset;
131 bp = pc->bp;
139 pad = pc->fddipad;
143 * If so, return immediately - if we haven't read any
144 * packets, clear the flag and return -2 to indicate
150 if (pc->break_loop) {
152 pc->break_loop = 0;
153 return (-2);
155 pc->cc = cc;
156 pc->bp = bp;
161 snprintf(pc->errbuf, sizeof(pc->errbuf),
163 return (-1);
170 if (sp->ens_stamplen != sizeof(*sp)) {
171 snprintf(pc->errbuf, sizeof(pc->errbuf),
173 sp->ens_stamplen);
174 return (-1);
177 p = bp + sp->ens_stamplen;
178 buflen = sp->ens_count;
179 if (buflen > pc->snapshot)
180 buflen = pc->snapshot;
183 inc = ENALIGN(buflen + sp->ens_stamplen);
184 cc -= inc;
186 pf->TotPkts++;
187 pf->TotDrops += sp->ens_dropped;
188 pf->TotMissed = sp->ens_ifoverflows;
189 if (pf->OrigMissed < 0)
190 pf->OrigMissed = pf->TotMissed;
193 * Short-circuit evaluation: if using BPF filter
194 * in kernel, no need to do it now - we already know
198 * that pc->fddipad was the amount of padding
203 if (pf->filtering_in_kernel ||
204 pcapint_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
206 pf->TotAccepted++;
207 h.ts = sp->ens_tstamp;
208 h.len = sp->ens_count - pad;
210 buflen -= pad;
214 pc->cc = cc;
215 pc->bp = bp;
220 pc->cc = 0;
229 ret = write(p->fd, buf, size);
230 if (ret == -1) {
231 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
233 return (-1);
241 struct pcap_pf *pf = p->priv;
248 * ran out of buffer space. (XXX - perhaps it should,
279 ps->ps_recv = pf->TotAccepted;
280 ps->ps_drop = pf->TotDrops;
281 ps->ps_ifdrop = pf->TotMissed - pf->OrigMissed;
296 struct pcap_pf *pf = p->priv;
298 int backlog = -1; /* request the most */
304 * Initially try a read/write open (to allow the inject
306 * issues, fall back to read-only. This allows a
307 * non-root user to be granted specific access to pcap
310 * XXX - we should have an API that has a flag that
311 * controls whether to open read-only or read-write,
317 * XXX - we assume here that "pfopen()" does not, in fact, modify
322 * XXX - is there an error that means "no such device"? Is
325 p->fd = pfopen(p->opt.device, O_RDWR);
326 if (p->fd == -1 && errno == EACCES)
327 p->fd = pfopen(p->opt.device, O_RDONLY);
328 if (p->fd < 0) {
330 snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
333 p->opt.device);
336 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
337 errno, "pf open: %s", p->opt.device);
351 if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN)
352 p->snapshot = MAXIMUM_SNAPLEN;
354 pf->OrigMissed = -1;
356 if (!p->opt.immediate)
358 if (p->opt.promisc)
360 if (ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode) < 0) {
361 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
369 (void)ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode);/* OK if this fails */
372 if (ioctl(p->fd, EIOCSETW, (caddr_t)&backlog) < 0) {
373 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
379 if (ioctl(p->fd, EIOCDEVP, (caddr_t)&devparams) < 0) {
380 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
392 p->linktype = DLT_EN10MB;
393 p->offset = 2;
396 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
401 * DOCSIS frames out on the wire inside the low-level
404 p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
405 if (p->dlt_list == NULL) {
406 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
411 p->dlt_list[0] = DLT_EN10MB;
412 p->dlt_list[1] = DLT_DOCSIS;
413 p->dlt_count = 2;
417 p->linktype = DLT_FDDI;
422 p->linktype = DLT_SLIP;
428 p->linktype = DLT_PPP;
438 p->linktype = DLT_EN10MB;
439 p->offset = 2;
445 p->linktype = DLT_IEEE802;
451 * XXX - what about ENDT_IEEE802? The pfilt.h header
452 * file calls this "IEEE 802 networks (non-Ethernet)",
459 * XXX - what about ENDT_HDLC and ENDT_NULL?
464 snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
465 "unknown data-link type %u", devparams.end_dev_type);
470 if (p->linktype == DLT_FDDI) {
471 p->fddipad = PCAP_FDDIPAD;
474 p->snapshot += PCAP_FDDIPAD;
476 p->fddipad = 0;
477 if (ioctl(p->fd, EIOCTRUNCATE, (caddr_t)&p->snapshot) < 0) {
478 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
487 if (ioctl(p->fd, EIOCSETF, (caddr_t)&Filter) < 0) {
488 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
494 if (p->opt.timeout != 0) {
496 timeout.tv_sec = p->opt.timeout / 1000;
497 timeout.tv_usec = (p->opt.timeout * 1000) % 1000000;
498 if (ioctl(p->fd, EIOCSRTIMEOUT, (caddr_t)&timeout) < 0) {
499 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
506 p->bufsize = BUFSPACE;
507 p->buffer = malloc(p->bufsize + p->offset);
508 if (p->buffer == NULL) {
509 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
518 p->selectable_fd = p->fd;
520 p->read_op = pcap_read_pf;
521 p->inject_op = pcap_inject_pf;
522 p->setfilter_op = pcap_setfilter_pf;
523 p->setdirection_op = NULL; /* Not implemented. */
524 p->set_datalink_op = NULL; /* can't change data link type */
525 p->getnonblock_op = pcapint_getnonblock_fd;
526 p->setnonblock_op = pcapint_setnonblock_fd;
527 p->stats_op = pcap_stats_pf;
544 p->activate_op = pcap_activate_pf;
549 * XXX - is there an error from pfopen() that means "no such device"?
565 * XXX - is there a way to find out whether an adapter has
589 struct pcap_pf *pf = p->priv;
594 * support BPF-style filters (it's not documented in the bpf(7)
600 if (ioctl(p->fd, BIOCVERSION, (caddr_t)&bv) >= 0) {
611 if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
612 pcapint_fmt_errmsg_for_errno(p->errbuf,
613 sizeof(p->errbuf), errno, "BIOCSETF");
614 return (-1);
620 * userland filter installed - that'd require
624 * XXX - this message should be supplied to the
631 pf->filtering_in_kernel = 1;
634 * Discard any previously-received packets,
641 p->cc = 0;
649 * XXX - this should really be supplied to the application
662 return (-1);
665 * XXX - this message should be supplied by the application as
669 pf->filtering_in_kernel = 0;