diff options
Diffstat (limited to 'contrib/libpcap/pcap-pf.c')
-rw-r--r-- | contrib/libpcap/pcap-pf.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/contrib/libpcap/pcap-pf.c b/contrib/libpcap/pcap-pf.c index 96a4a50979b4..73469086d8a4 100644 --- a/contrib/libpcap/pcap-pf.c +++ b/contrib/libpcap/pcap-pf.c @@ -107,7 +107,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user) #ifdef LBL_ALIGN struct enstamp stamp; #endif - register int pad; + register u_int pad; again: cc = pc->cc; @@ -127,11 +127,11 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user) (void)lseek(pc->fd, 0L, SEEK_SET); goto again; } - snprintf(pc->errbuf, sizeof(pc->errbuf), "pf read: %s", + pcap_snprintf(pc->errbuf, sizeof(pc->errbuf), "pf read: %s", pcap_strerror(errno)); return (-1); } - bp = pc->buffer + pc->offset; + bp = (u_char *)pc->buffer + pc->offset; } else bp = pc->bp; /* @@ -160,7 +160,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user) } } if (cc < sizeof(*sp)) { - snprintf(pc->errbuf, sizeof(pc->errbuf), + pcap_snprintf(pc->errbuf, sizeof(pc->errbuf), "pf short read (%d)", cc); return (-1); } @@ -172,7 +172,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user) #endif sp = (struct enstamp *)bp; if (sp->ens_stamplen != sizeof(*sp)) { - snprintf(pc->errbuf, sizeof(pc->errbuf), + pcap_snprintf(pc->errbuf, sizeof(pc->errbuf), "pf short stamplen (%d)", sp->ens_stamplen); return (-1); @@ -232,12 +232,12 @@ pcap_inject_pf(pcap_t *p, const void *buf, size_t size) ret = write(p->fd, buf, size); if (ret == -1) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send: %s", + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send: %s", pcap_strerror(errno)); return (-1); } return (ret); -} +} static int pcap_stats_pf(pcap_t *p, struct pcap_stat *ps) @@ -321,14 +321,17 @@ pcap_activate_pf(pcap_t *p) * its argument, even though it takes a "char *" rather than a * "const char *" as its first argument. That appears to be * the case, at least on Digital UNIX 4.0. + * + * XXX - is there an error that means "no such device"? Is + * there one that means "that device doesn't support pf"? */ - p->fd = pfopen(p->opt.source, O_RDWR); + p->fd = pfopen(p->opt.device, O_RDWR); if (p->fd == -1 && errno == EACCES) - p->fd = pfopen(p->opt.source, O_RDONLY); + p->fd = pfopen(p->opt.device, O_RDONLY); if (p->fd < 0) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "pf open: %s: %s\n\ + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "pf open: %s: %s\n\ your system may not be properly configured; see the packetfilter(4) man page\n", - p->opt.source, pcap_strerror(errno)); + p->opt.device, pcap_strerror(errno)); goto bad; } pf->OrigMissed = -1; @@ -338,7 +341,7 @@ your system may not be properly configured; see the packetfilter(4) man page\n", if (p->opt.promisc) enmode |= ENPROMISC; if (ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode) < 0) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCMBIS: %s", + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCMBIS: %s", pcap_strerror(errno)); goto bad; } @@ -349,13 +352,13 @@ your system may not be properly configured; see the packetfilter(4) man page\n", #endif /* set the backlog */ if (ioctl(p->fd, EIOCSETW, (caddr_t)&backlog) < 0) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCSETW: %s", + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCSETW: %s", pcap_strerror(errno)); goto bad; } /* discover interface type */ if (ioctl(p->fd, EIOCDEVP, (caddr_t)&devparams) < 0) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCDEVP: %s", + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCDEVP: %s", pcap_strerror(errno)); goto bad; } @@ -437,7 +440,7 @@ your system may not be properly configured; see the packetfilter(4) man page\n", * framing", there's not much we can do, as that * doesn't specify a particular type of header. */ - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "unknown data-link type %u", devparams.end_dev_type); goto bad; } @@ -450,7 +453,7 @@ your system may not be properly configured; see the packetfilter(4) man page\n", } else p->fddipad = 0; if (ioctl(p->fd, EIOCTRUNCATE, (caddr_t)&p->snapshot) < 0) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCTRUNCATE: %s", + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCTRUNCATE: %s", pcap_strerror(errno)); goto bad; } @@ -459,7 +462,7 @@ your system may not be properly configured; see the packetfilter(4) man page\n", Filter.enf_Priority = 37; /* anything > 2 */ Filter.enf_FilterLen = 0; /* means "always true" */ if (ioctl(p->fd, EIOCSETF, (caddr_t)&Filter) < 0) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCSETF: %s", + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCSETF: %s", pcap_strerror(errno)); goto bad; } @@ -469,14 +472,14 @@ your system may not be properly configured; see the packetfilter(4) man page\n", timeout.tv_sec = p->opt.timeout / 1000; timeout.tv_usec = (p->opt.timeout * 1000) % 1000000; if (ioctl(p->fd, EIOCSRTIMEOUT, (caddr_t)&timeout) < 0) { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCSRTIMEOUT: %s", + pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "EIOCSRTIMEOUT: %s", pcap_strerror(errno)); goto bad; } } p->bufsize = BUFSPACE; - p->buffer = (u_char*)malloc(p->bufsize + p->offset); + p->buffer = malloc(p->bufsize + p->offset); if (p->buffer == NULL) { strlcpy(p->errbuf, pcap_strerror(errno), PCAP_ERRBUF_SIZE); goto bad; @@ -503,11 +506,11 @@ your system may not be properly configured; see the packetfilter(4) man page\n", } pcap_t * -pcap_create_interface(const char *device, char *ebuf) +pcap_create_interface(const char *device _U_, char *ebuf) { pcap_t *p; - p = pcap_create_common(device, ebuf, sizeof (struct pcap_pf)); + p = pcap_create_common(ebuf, sizeof (struct pcap_pf)); if (p == NULL) return (NULL); @@ -515,10 +518,20 @@ pcap_create_interface(const char *device, char *ebuf) return (p); } +/* + * XXX - is there an error from pfopen() that means "no such device"? + * Is there one that means "that device doesn't support pf"? + */ +static int +can_be_bound(const char *name _U_) +{ + return (1); +} + int pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf) { - return (0); + return (pcap_findalldevs_interfaces(alldevsp, errbuf, can_be_bound)); } static int @@ -547,7 +560,7 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp) * Yes. Try to install the filter. */ if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) { - snprintf(p->errbuf, sizeof(p->errbuf), + pcap_snprintf(p->errbuf, sizeof(p->errbuf), "BIOCSETF: %s", pcap_strerror(errno)); return (-1); } |