aboutsummaryrefslogtreecommitdiff
path: root/pcap-pf.c
diff options
context:
space:
mode:
authorJoseph Mingrone <jrm@FreeBSD.org>2024-09-05 19:46:35 +0000
committerJoseph Mingrone <jrm@FreeBSD.org>2024-09-05 19:46:35 +0000
commit025be3f592b920ff0a3e602e5aa8b60a34e5e617 (patch)
tree4f33277584e4a38c8bad5c2788584a00cf830ea4 /pcap-pf.c
parent6b96668d5b49eea57b7551349eca70928cc199ce (diff)
Diffstat (limited to 'pcap-pf.c')
-rw-r--r--pcap-pf.c59
1 files changed, 29 insertions, 30 deletions
diff --git a/pcap-pf.c b/pcap-pf.c
index bd27933eff69..cdad98821c0e 100644
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -22,9 +22,7 @@
* Extraction/creation by Jeffrey Mogul, DECWRL
*/
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
#include <sys/types.h>
#include <sys/time.h>
@@ -79,7 +77,7 @@ struct rtentry;
*/
struct pcap_pf {
int filtering_in_kernel; /* using kernel filter */
- u_long TotPkts; /* can't oflow for 79 hrs on ether */
+ u_long TotPkts; /* can't overflow for 79 hrs on ether */
u_long TotAccepted; /* count accepted by filter */
u_long TotDrops; /* count of dropped packets */
long TotMissed; /* missed by i/f during this run */
@@ -124,7 +122,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
(void)lseek(pc->fd, 0L, SEEK_SET);
goto again;
}
- pcap_fmt_errmsg_for_errno(pc->errbuf,
+ pcapint_fmt_errmsg_for_errno(pc->errbuf,
sizeof(pc->errbuf), errno, "pf read");
return (-1);
}
@@ -203,7 +201,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
* skipping that padding.
*/
if (pf->filtering_in_kernel ||
- pcap_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
+ pcapint_filter(pc->fcode.bf_insns, p, sp->ens_count, buflen)) {
struct pcap_pkthdr h;
pf->TotAccepted++;
h.ts = sp->ens_tstamp;
@@ -230,7 +228,7 @@ pcap_inject_pf(pcap_t *p, const void *buf, int size)
ret = write(p->fd, buf, size);
if (ret == -1) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "send");
return (-1);
}
@@ -335,7 +333,7 @@ pcap_activate_pf(pcap_t *p)
p->opt.device);
err = PCAP_ERROR_PERM_DENIED;
} else {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "pf open: %s", p->opt.device);
err = PCAP_ERROR;
}
@@ -360,7 +358,7 @@ pcap_activate_pf(pcap_t *p)
if (p->opt.promisc)
enmode |= ENPROMISC;
if (ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode) < 0) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "EIOCMBIS");
err = PCAP_ERROR;
goto bad;
@@ -372,14 +370,14 @@ pcap_activate_pf(pcap_t *p)
#endif
/* set the backlog */
if (ioctl(p->fd, EIOCSETW, (caddr_t)&backlog) < 0) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "EIOCSETW");
err = PCAP_ERROR;
goto bad;
}
/* discover interface type */
if (ioctl(p->fd, EIOCDEVP, (caddr_t)&devparams) < 0) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "EIOCDEVP");
err = PCAP_ERROR;
goto bad;
@@ -404,14 +402,15 @@ pcap_activate_pf(pcap_t *p)
* Ethernet framing).
*/
p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
- /*
- * If that fails, just leave the list empty.
- */
- if (p->dlt_list != NULL) {
- p->dlt_list[0] = DLT_EN10MB;
- p->dlt_list[1] = DLT_DOCSIS;
- p->dlt_count = 2;
+ if (p->dlt_list == NULL) {
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ errno, "malloc");
+ err = PCAP_ERROR;
+ goto bad;
}
+ p->dlt_list[0] = DLT_EN10MB;
+ p->dlt_list[1] = DLT_DOCSIS;
+ p->dlt_count = 2;
break;
case ENDT_FDDI:
@@ -476,7 +475,7 @@ pcap_activate_pf(pcap_t *p)
} else
p->fddipad = 0;
if (ioctl(p->fd, EIOCTRUNCATE, (caddr_t)&p->snapshot) < 0) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "EIOCTRUNCATE");
err = PCAP_ERROR;
goto bad;
@@ -486,7 +485,7 @@ pcap_activate_pf(pcap_t *p)
Filter.enf_Priority = 37; /* anything > 2 */
Filter.enf_FilterLen = 0; /* means "always true" */
if (ioctl(p->fd, EIOCSETF, (caddr_t)&Filter) < 0) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "EIOCSETF");
err = PCAP_ERROR;
goto bad;
@@ -497,7 +496,7 @@ pcap_activate_pf(pcap_t *p)
timeout.tv_sec = p->opt.timeout / 1000;
timeout.tv_usec = (p->opt.timeout * 1000) % 1000000;
if (ioctl(p->fd, EIOCSRTIMEOUT, (caddr_t)&timeout) < 0) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "EIOCSRTIMEOUT");
err = PCAP_ERROR;
goto bad;
@@ -507,7 +506,7 @@ pcap_activate_pf(pcap_t *p)
p->bufsize = BUFSPACE;
p->buffer = malloc(p->bufsize + p->offset);
if (p->buffer == NULL) {
- pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
errno, "malloc");
err = PCAP_ERROR;
goto bad;
@@ -523,18 +522,18 @@ pcap_activate_pf(pcap_t *p)
p->setfilter_op = pcap_setfilter_pf;
p->setdirection_op = NULL; /* Not implemented. */
p->set_datalink_op = NULL; /* can't change data link type */
- p->getnonblock_op = pcap_getnonblock_fd;
- p->setnonblock_op = pcap_setnonblock_fd;
+ p->getnonblock_op = pcapint_getnonblock_fd;
+ p->setnonblock_op = pcapint_setnonblock_fd;
p->stats_op = pcap_stats_pf;
return (0);
bad:
- pcap_cleanup_live_common(p);
+ pcapint_cleanup_live_common(p);
return (err);
}
pcap_t *
-pcap_create_interface(const char *device _U_, char *ebuf)
+pcapint_create_interface(const char *device _U_, char *ebuf)
{
pcap_t *p;
@@ -578,9 +577,9 @@ get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
}
int
-pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
+pcapint_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
{
- return (pcap_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
+ return (pcapint_findalldevs_interfaces(devlistp, errbuf, can_be_bound,
get_if_flags));
}
@@ -593,7 +592,7 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
/*
* See if BIOCVERSION works. If not, we assume the kernel doesn't
* support BPF-style filters (it's not documented in the bpf(7)
- * or packetfiler(7) man pages, but the code used to fail if
+ * or packetfilter(7) man pages, but the code used to fail if
* BIOCSETF worked but BIOCVERSION didn't, and I've seen it do
* kernel filtering in DU 4.0, so presumably BIOCVERSION works
* there, at least).
@@ -610,7 +609,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) {
- pcap_fmt_errmsg_for_errno(p->errbuf,
+ pcapint_fmt_errmsg_for_errno(p->errbuf,
sizeof(p->errbuf), errno, "BIOCSETF");
return (-1);
}
@@ -659,7 +658,7 @@ pcap_setfilter_pf(pcap_t *p, struct bpf_program *fp)
/*
* We couldn't do filtering in the kernel; do it in userland.
*/
- if (install_bpf_program(p, fp) < 0)
+ if (pcapint_install_bpf_program(p, fp) < 0)
return (-1);
/*