aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpf_image.c6
-rwxr-xr-xconfigure2
-rw-r--r--configure.in6
-rw-r--r--gencode.c5
-rw-r--r--inet.c50
-rw-r--r--optimize.c4
-rw-r--r--pcap-bpf.c43
-rw-r--r--pcap-dlpi.c100
-rw-r--r--pcap-linux.c37
-rw-r--r--pcap-nit.c17
-rw-r--r--pcap-null.c9
-rw-r--r--pcap-pf.c36
-rw-r--r--pcap-snit.c27
-rw-r--r--pcap-snoop.c32
-rw-r--r--pcap.312
-rw-r--r--pcap.c4
-rw-r--r--savefile.c36
17 files changed, 274 insertions, 152 deletions
diff --git a/bpf_image.c b/bpf_image.c
index 66265c8..c7d3aae 100644
--- a/bpf_image.c
+++ b/bpf_image.c
@@ -21,7 +21,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/bpf_image.c,v 1.22 1999-10-07 23:46:40 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/bpf_image.c,v 1.23 2000-04-27 09:11:11 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -277,8 +277,8 @@ bpf_image(p, n)
fmt = "";
break;
}
- (void)sprintf(operand, fmt, v);
- (void)sprintf(image,
+ (void)snprintf(operand, sizeof operand, fmt, v);
+ (void)snprintf(image, sizeof image,
(BPF_CLASS(p->code) == BPF_JMP &&
BPF_OP(p->code) != BPF_JA) ?
"(%03d) %-8s %-16s jt %d\tjf %d"
diff --git a/configure b/configure
index ed3533a..ae663a3 100755
--- a/configure
+++ b/configure
@@ -1368,7 +1368,7 @@ fi
fi
fi
-for ac_func in ether_hostton strerror
+for ac_func in ether_hostton strerror freeifaddrs
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:1375: checking for $ac_func" >&5
diff --git a/configure.in b/configure.in
index 8be0924..11d59bb 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
-dnl @(#) $Header: /tcpdump/master/libpcap/configure.in,v 1.75 2000-04-09 17:44:26 assar Exp $ (LBL)
+dnl @(#) $Header: /tcpdump/master/libpcap/configure.in,v 1.76 2000-04-27 09:11:11 itojun Exp $ (LBL)
dnl
dnl Copyright (c) 1994, 1995, 1996, 1997
dnl The Regents of the University of California. All rights reserved.
@@ -6,7 +6,7 @@ dnl
dnl Process this file with autoconf to produce a configure script.
dnl
-AC_REVISION($Revision: 1.75 $)
+AC_REVISION($Revision: 1.76 $)
AC_INIT(pcap.c)
AC_CANONICAL_SYSTEM
@@ -27,7 +27,7 @@ AC_CHECK_HEADERS(malloc.h sys/ioccom.h sys/sockio.h ifaddrs.h)
AC_LBL_FIXINCLUDES
-AC_CHECK_FUNCS(ether_hostton strerror)
+AC_CHECK_FUNCS(ether_hostton strerror freeifaddrs)
dnl to pacify those who hate protochain insn
AC_MSG_CHECKING(if --disable-protochain option is specified)
diff --git a/gencode.c b/gencode.c
index 670c9f0..e5fccc3 100644
--- a/gencode.c
+++ b/gencode.c
@@ -21,7 +21,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.105 2000-04-01 11:44:59 assar Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.106 2000-04-27 09:11:11 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -97,7 +97,8 @@ bpf_error(fmt, va_alist)
va_start(ap);
#endif
if (bpf_pcap != NULL)
- (void)vsprintf(pcap_geterr(bpf_pcap), fmt, ap);
+ (void)vsnprintf(pcap_geterr(bpf_pcap), PCAP_ERRBUF_SIZE,
+ fmt, ap);
va_end(ap);
longjmp(top_ctx, 1);
/* NOTREACHED */
diff --git a/inet.c b/inet.c
index c9830c6..dae6ad4 100644
--- a/inet.c
+++ b/inet.c
@@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.29 2000-04-13 04:58:09 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.30 2000-04-27 09:11:12 itojun Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -95,7 +95,8 @@ pcap_lookupdev(errbuf)
static char device[IF_NAMESIZE + 1];
if (getifaddrs(&ifap) != 0) {
- (void)sprintf(errbuf, "getifaddrs: %s", pcap_strerror(errno));
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "getifaddrs: %s", pcap_strerror(errno));
return NULL;
}
@@ -123,14 +124,23 @@ pcap_lookupdev(errbuf)
}
}
if (mp == NULL) {
- (void)strcpy(errbuf, "no suitable device found");
+ (void)strncpy(errbuf, "no suitable device found",
+ PCAP_ERRBUF_SIZE);
+#ifdef HAVE_FREEIFADDRS
+ freeifaddrs(ifap);
+#else
free(ifap);
+#endif
return (NULL);
}
(void)strncpy(device, mp->ifa_name, sizeof(device) - 1);
device[sizeof(device) - 1] = '\0';
+#ifdef HAVE_FREEIFADDRS
+ freeifaddrs(ifap);
+#else
free(ifap);
+#endif
return (device);
#else
register int fd, minunit, n;
@@ -144,7 +154,8 @@ pcap_lookupdev(errbuf)
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
- (void)sprintf(errbuf, "socket: %s", pcap_strerror(errno));
+ (void)snprintf(errbuf, PCAP_ERRBUFF_SIZE,
+ "socket: %s", pcap_strerror(errno));
return (NULL);
}
@@ -154,7 +165,8 @@ pcap_lookupdev(errbuf)
buf = malloc (buf_size);
if (buf == NULL) {
close (fd);
- (void)sprintf(errbuf, "out of memory");
+ (void)snprintf(errbuf, PCAP_ERRBUFF_SIZE,
+ "out of memory");
return (NULL);
}
@@ -164,8 +176,8 @@ pcap_lookupdev(errbuf)
if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0
&& errno != EINVAL) {
free (buf);
- (void)sprintf(errbuf, "SIOCGIFCONF: %s",
- pcap_strerror(errno));
+ (void)snprintf(errbuf, PCAP_ERRBUFF_SIZE,
+ "SIOCGIFCONF: %s", pcap_strerror(errno));
(void)close(fd);
return (NULL);
}
@@ -202,7 +214,8 @@ pcap_lookupdev(errbuf)
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) {
if (errno == ENXIO)
continue;
- (void)sprintf(errbuf, "SIOCGIFFLAGS: %.*s: %s",
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "SIOCGIFFLAGS: %.*s: %s",
(int)sizeof(ifr.ifr_name), ifr.ifr_name,
pcap_strerror(errno));
(void)close(fd);
@@ -224,7 +237,8 @@ pcap_lookupdev(errbuf)
}
(void)close(fd);
if (mp == NULL) {
- (void)strcpy(errbuf, "no suitable device found");
+ (void)strlcpy(errbuf, "no suitable device found",
+ PCAP_ERRBUF_SIZE);
free(buf);
return (NULL);
}
@@ -248,7 +262,8 @@ pcap_lookupnet(device, netp, maskp, errbuf)
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
- (void)sprintf(errbuf, "socket: %s", pcap_strerror(errno));
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
+ pcap_strerror(errno));
return (-1);
}
memset(&ifr, 0, sizeof(ifr));
@@ -259,10 +274,11 @@ pcap_lookupnet(device, netp, maskp, errbuf)
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
if (errno == EADDRNOTAVAIL) {
- (void)sprintf(errbuf, "%s: no IPv4 address assigned",
- device);
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "%s: no IPv4 address assigned", device);
} else {
- (void)sprintf(errbuf, "SIOCGIFADDR: %s: %s",
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "SIOCGIFADDR: %s: %s",
device, pcap_strerror(errno));
}
(void)close(fd);
@@ -271,8 +287,8 @@ pcap_lookupnet(device, netp, maskp, errbuf)
sin = (struct sockaddr_in *)&ifr.ifr_addr;
*netp = sin->sin_addr.s_addr;
if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
- (void)sprintf(errbuf, "SIOCGIFNETMASK: %s: %s",
- device, pcap_strerror(errno));
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "SIOCGIFNETMASK: %s: %s", device, pcap_strerror(errno));
(void)close(fd);
return (-1);
}
@@ -286,8 +302,8 @@ pcap_lookupnet(device, netp, maskp, errbuf)
else if (IN_CLASSC(*netp))
*maskp = IN_CLASSC_NET;
else {
- (void)sprintf(errbuf, "inet class for 0x%x unknown",
- *netp);
+ (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "inet class for 0x%x unknown", *netp);
return (-1);
}
}
diff --git a/optimize.c b/optimize.c
index 8399939..ee22e06 100644
--- a/optimize.c
+++ b/optimize.c
@@ -22,7 +22,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.61 1999-10-19 15:18:30 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.62 2000-04-27 09:11:12 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -1936,7 +1936,7 @@ convert_code_r(p)
dst->k = src->s.k;
/* fill block-local relative jump */
- if (BPF_CLASS(src->s.code) != BPF_JMP || src->s.code == BPF_JMP|BPF_JA) {
+ if (BPF_CLASS(src->s.code) != BPF_JMP || src->s.code == (BPF_JMP|BPF_JA)) {
#if 0
if (src->s.jt || src->s.jf) {
bpf_error("illegal jmp destination");
diff --git a/pcap-bpf.c b/pcap-bpf.c
index a0af02a..b1162f7 100644
--- a/pcap-bpf.c
+++ b/pcap-bpf.c
@@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.32 1999-10-19 15:18:30 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.33 2000-04-27 09:11:12 itojun Exp $ (LBL)";
#endif
#include <sys/param.h> /* optionally get BSD define */
@@ -55,7 +55,8 @@ pcap_stats(pcap_t *p, struct pcap_stat *ps)
struct bpf_stat s;
if (ioctl(p->fd, BIOCGSTATS, (caddr_t)&s) < 0) {
- sprintf(p->errbuf, "BIOCGSTATS: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCGSTATS: %s",
+ pcap_strerror(errno));
return (-1);
}
@@ -99,7 +100,8 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
/* fall through */
#endif
}
- sprintf(p->errbuf, "read: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read: %s",
+ pcap_strerror(errno));
return (-1);
}
bp = p->buffer;
@@ -136,13 +138,13 @@ bpf_open(pcap_t *p, char *errbuf)
{
int fd;
int n = 0;
- char device[sizeof "/dev/bpf000"];
+ char device[sizeof "/dev/bpf0000000000"];
/*
* Go through all the minors and find one that isn't in use.
*/
do {
- (void)sprintf(device, "/dev/bpf%d", n++);
+ (void)snprintf(device, sizeof(device), "/dev/bpf%d", n++);
fd = open(device, O_RDONLY);
} while (fd < 0 && errno == EBUSY);
@@ -150,7 +152,8 @@ bpf_open(pcap_t *p, char *errbuf)
* XXX better message for all minors used
*/
if (fd < 0)
- sprintf(errbuf, "%s: %s", device, pcap_strerror(errno));
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
+ device, pcap_strerror(errno));
return (fd);
}
@@ -166,7 +169,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p = (pcap_t *)malloc(sizeof(*p));
if (p == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
+ pcap_strerror(errno));
return (NULL);
}
bzero(p, sizeof(*p));
@@ -178,12 +182,14 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p->snapshot = snaplen;
if (ioctl(fd, BIOCVERSION, (caddr_t)&bv) < 0) {
- sprintf(ebuf, "BIOCVERSION: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCVERSION: %s",
+ pcap_strerror(errno));
goto bad;
}
if (bv.bv_major != BPF_MAJOR_VERSION ||
bv.bv_minor < BPF_MINOR_VERSION) {
- sprintf(ebuf, "kernel bpf filter out of date");
+ snprintf(ebuf, PCAP_ERRBUF_SIZE,
+ "kernel bpf filter out of date");
goto bad;
}
v = 32768; /* XXX this should be a user-accessible hook */
@@ -196,12 +202,14 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
(void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
- sprintf(ebuf, "%s: %s", device, pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s: %s",
+ device, pcap_strerror(errno));
goto bad;
}
/* Get the data link layer type. */
if (ioctl(fd, BIOCGDLT, (caddr_t)&v) < 0) {
- sprintf(ebuf, "BIOCGDLT: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGDLT: %s",
+ pcap_strerror(errno));
goto bad;
}
#ifdef __OpenBSD__
@@ -240,8 +248,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
to.tv_sec = to_ms / 1000;
to.tv_usec = (to_ms * 1000) % 1000000;
if (ioctl(p->fd, BIOCSRTIMEOUT, (caddr_t)&to) < 0) {
- sprintf(ebuf, "BIOCSRTIMEOUT: %s",
- pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCSRTIMEOUT: %s",
+ pcap_strerror(errno));
goto bad;
}
}
@@ -250,13 +258,15 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
(void)ioctl(p->fd, BIOCPROMISC, NULL);
if (ioctl(fd, BIOCGBLEN, (caddr_t)&v) < 0) {
- sprintf(ebuf, "BIOCGBLEN: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGBLEN: %s",
+ pcap_strerror(errno));
goto bad;
}
p->bufsize = v;
p->buffer = (u_char *)malloc(p->bufsize);
if (p->buffer == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
+ pcap_strerror(errno));
goto bad;
}
@@ -280,7 +290,8 @@ pcap_setfilter(pcap_t *p, struct bpf_program *fp)
else if (p->sf.rfile != NULL)
p->fcode = *fp;
else if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) {
- sprintf(p->errbuf, "BIOCSETF: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "BIOCSETF: %s",
+ pcap_strerror(errno));
return (-1);
}
return (0);
diff --git a/pcap-dlpi.c b/pcap-dlpi.c
index dee8e7d..24edbce 100644
--- a/pcap-dlpi.c
+++ b/pcap-dlpi.c
@@ -38,7 +38,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.53 2000-01-25 02:25:04 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.54 2000-04-27 09:11:13 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -251,24 +251,29 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
*/
cp = strpbrk(device, "0123456789");
if (cp == NULL) {
- sprintf(ebuf, "%s missing unit number", device);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "%s missing unit number", device);
goto bad;
}
ppa = strtol(cp, &eos, 10);
if (*eos != '\0') {
- sprintf(ebuf, "%s bad unit number", device);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "%s bad unit number", device);
goto bad;
}
if (*device == '/')
strcpy(dname, device);
- else
- sprintf(dname, "%s/%s", PCAP_DEV_PREFIX, device);
+ else {
+ snprintf(dname, sizeof(dname),
+ "%s/%s", PCAP_DEV_PREFIX, device);
+ }
#ifdef HAVE_DEV_DLPI
/* Map network device to /dev/dlpi unit */
cp = "/dev/dlpi";
if ((p->fd = open(cp, O_RDWR)) < 0) {
- sprintf(ebuf, "%s: %s", cp, pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "%s: %s", cp, pcap_strerror(errno));
goto bad;
}
/* Map network interface to /dev/dlpi unit */
@@ -282,13 +287,15 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
*cp = '\0';
if ((p->fd = open(dname, O_RDWR)) < 0) {
if (errno != ENOENT) {
- sprintf(ebuf, "%s: %s", dname, pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "%s: %s", dname,
+ pcap_strerror(errno));
goto bad;
}
/* Try again with unit number */
if ((p->fd = open(dname2, O_RDWR)) < 0) {
- sprintf(ebuf, "%s: %s", dname2, pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "%s: %s", dname2,
+ pcap_strerror(errno));
goto bad;
}
/* XXX Assume unit zero */
@@ -398,7 +405,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
break;
default:
- sprintf(ebuf, "unknown mac type 0x%lu", infop->dl_mac_type);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "unknown mac type 0x%lu",
+ infop->dl_mac_type);
goto bad;
}
@@ -407,7 +415,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
** This is a non standard SunOS hack to get the ethernet header.
*/
if (strioctl(p->fd, DLIOCRAW, 0, NULL) < 0) {
- sprintf(ebuf, "DLIOCRAW: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "DLIOCRAW: %s",
+ pcap_strerror(errno));
goto bad;
}
#endif
@@ -417,7 +426,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
** Another non standard call to get the data nicely buffered
*/
if (ioctl(p->fd, I_PUSH, "bufmod") != 0) {
- sprintf(ebuf, "I_PUSH bufmod: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "I_PUSH bufmod: %s",
+ pcap_strerror(errno));
goto bad;
}
@@ -444,7 +454,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
#endif
if (ss > 0 &&
strioctl(p->fd, SBIOCSSNAP, sizeof(ss), (char *)&ss) != 0) {
- sprintf(ebuf, "SBIOCSSNAP: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "SBIOCSSNAP: %s",
+ pcap_strerror(errno));
goto bad;
}
@@ -452,12 +463,14 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
** Set up the bufmod flags
*/
if (strioctl(p->fd, SBIOCGFLAGS, sizeof(flag), (char *)&flag) < 0) {
- sprintf(ebuf, "SBIOCGFLAGS: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "SBIOCGFLAGS: %s",
+ pcap_strerror(errno));
goto bad;
}
flag |= SB_NO_DROPS;
if (strioctl(p->fd, SBIOCSFLAGS, sizeof(flag), (char *)&flag) != 0) {
- sprintf(ebuf, "SBIOCSFLAGS: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "SBIOCSFLAGS: %s",
+ pcap_strerror(errno));
goto bad;
}
/*
@@ -469,7 +482,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
to.tv_sec = to_ms / 1000;
to.tv_usec = (to_ms * 1000) % 1000000;
if (strioctl(p->fd, SBIOCSTIME, sizeof(to), (char *)&to) != 0) {
- sprintf(ebuf, "SBIOCSTIME: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "SBIOCSTIME: %s",
+ pcap_strerror(errno));
goto bad;
}
}
@@ -479,7 +493,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
** As the last operation flush the read side.
*/
if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) {
- sprintf(ebuf, "FLUSHR: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "FLUSHR: %s",
+ pcap_strerror(errno));
goto bad;
}
/* Allocate data buffer */
@@ -512,7 +527,8 @@ send_request(int fd, char *ptr, int len, char *what, char *ebuf)
flags = 0;
if (putmsg(fd, &ctl, (struct strbuf *) NULL, flags) < 0) {
- sprintf(ebuf, "send_request: putmsg \"%s\": %s",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "send_request: putmsg \"%s\": %s",
what, pcap_strerror(errno));
return (-1);
}
@@ -532,7 +548,7 @@ recv_ack(int fd, int size, const char *what, char *bufp, char *ebuf)
flags = 0;
if (getmsg(fd, &ctl, (struct strbuf*)NULL, &flags) < 0) {
- sprintf(ebuf, "recv_ack: %s getmsg: %s",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "recv_ack: %s getmsg: %s",
what, pcap_strerror(errno));
return (-1);
}
@@ -554,37 +570,40 @@ recv_ack(int fd, int size, const char *what, char *bufp, char *ebuf)
switch (dlp->error_ack.dl_errno) {
case DL_BADPPA:
- sprintf(ebuf, "recv_ack: %s bad ppa (device unit)",
- what);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "recv_ack: %s bad ppa (device unit)", what);
break;
case DL_SYSERR:
- sprintf(ebuf, "recv_ack: %s: %s",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "recv_ack: %s: %s",
what, pcap_strerror(dlp->error_ack.dl_unix_errno));
break;
case DL_UNSUPPORTED:
- sprintf(ebuf,
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
"recv_ack: %s: Service not supplied by provider",
what);
break;
default:
- sprintf(ebuf, "recv_ack: %s error 0x%x",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "recv_ack: %s error 0x%x",
what, (bpf_u_int32)dlp->error_ack.dl_errno);
break;
}
return (-1);
default:
- sprintf(ebuf, "recv_ack: %s unexpected primitive ack 0x%x ",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "recv_ack: %s unexpected primitive ack 0x%x ",
what, (bpf_u_int32)dlp->dl_primitive);
return (-1);
}
if (ctl.len < size) {
- sprintf(ebuf, "recv_ack: %s ack too small (%d < %d)",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "recv_ack: %s ack too small (%d < %d)",
what, ctl.len, size);
return (-1);
}
@@ -734,7 +753,8 @@ get_dlpi_ppa(register int fd, register const char *device, register int unit,
bpf_u_int32 buf[MAXDLBUF];
if (stat(device, &statbuf) < 0) {
- sprintf(ebuf, "stat: %s: %s", device, pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "stat: %s: %s", device, pcap_strerror(errno));
return (-1);
}
majdev = major(statbuf.st_rdev);
@@ -757,11 +777,13 @@ get_dlpi_ppa(register int fd, register const char *device, register int unit,
ip = (dl_hp_ppa_info_t *)((u_char *)ip + ip->dl_next_offset);
}
if (i == ap->dl_count) {
- sprintf(ebuf, "can't find PPA for %s", device);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "can't find PPA for %s", device);
return (-1);
}
if (ip->dl_hdw_state == HDW_DEAD) {
- sprintf(ebuf, "%s: hardware state: DOWN\n", device);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "%s: hardware state: DOWN\n", device);
return (-1);
}
return ((int)ip->dl_ppa);
@@ -796,17 +818,20 @@ get_dlpi_ppa(register int fd, register const char *ifname, register int unit,
if (cp != NULL)
ifname = cp + 1;
if (nlist(path_vmunix, &nl) < 0) {
- sprintf(ebuf, "nlist %s failed", path_vmunix);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "nlist %s failed",
+ path_vmunix);
return (-1);
}
if (nl[NL_IFNET].n_value == 0) {
- sprintf(ebuf, "could't find %s kernel symbol",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "could't find %s kernel symbol",
nl[NL_IFNET].n_name);
return (-1);
}
kd = open("/dev/kmem", O_RDONLY);
if (kd < 0) {
- sprintf(ebuf, "kmem open: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "kmem open: %s",
+ pcap_strerror(errno));
return (-1);
}
if (dlpi_kread(kd, nl[NL_IFNET].n_value,
@@ -822,13 +847,13 @@ get_dlpi_ppa(register int fd, register const char *ifname, register int unit,
(void)close(kd);
return (-1);
}
- sprintf(tifname, "%.*s%d",
+ snprintf(tifname, sizeof(tifname), "%.*s%d",
(int)sizeof(if_name), if_name, ifnet.if_unit);
if (strcmp(tifname, ifname) == 0)
return (ifnet.if_index);
}
- sprintf(ebuf, "Can't find %s", ifname);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "Can't find %s", ifname);
return (-1);
}
@@ -839,15 +864,18 @@ dlpi_kread(register int fd, register off_t addr,
register int cc;
if (lseek(fd, addr, SEEK_SET) < 0) {
- sprintf(ebuf, "lseek: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "lseek: %s",
+ pcap_strerror(errno));
return (-1);
}
cc = read(fd, buf, len);
if (cc < 0) {
- sprintf(ebuf, "read: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "read: %s",
+ pcap_strerror(errno));
return (-1);
} else if (cc != len) {
- sprintf(ebuf, "short read (%d != %d)", cc, len);
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "short read (%d != %d)", cc,
+ len);
return (-1);
}
return (cc);
diff --git a/pcap-linux.c b/pcap-linux.c
index e1ff4d1..9b95182 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.15 1999-10-07 23:46:40 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.16 2000-04-27 09:11:13 itojun Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -96,7 +96,8 @@ again:
case EWOULDBLOCK:
return (0); /* XXX */
}
- sprintf(p->errbuf, "read: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, sizeof(p->errbuf),
+ "read: %s", pcap_strerror(errno));
return (-1);
}
} while (strcmp(p->md.device, from.sa_data));
@@ -125,7 +126,7 @@ again:
++p->md.stat.ps_recv;
/* Get timestamp */
if (ioctl(p->fd, SIOCGSTAMP, &h.ts) < 0) {
- sprintf(p->errbuf, "SIOCGSTAMP: %s",
+ snprintf(p->errbuf, sizeof(p->errbuf), "SIOCGSTAMP: %s",
pcap_strerror(errno));
return (-1);
}
@@ -147,7 +148,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p = (pcap_t *)malloc(sizeof(*p));
if (p == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, PCAP_ERRBUFF_SIZE,
+ "malloc: %s", pcap_strerror(errno));
return (NULL);
}
memset(p, 0, sizeof(*p));
@@ -155,7 +157,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
if (fd < 0) {
- sprintf(ebuf, "socket: %s", pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, "socket: %s",
+ pcap_strerror(errno));
goto bad;
}
p->fd = fd;
@@ -165,14 +168,16 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
sa.sa_family = AF_INET;
(void)strncpy(sa.sa_data, device, sizeof(sa.sa_data));
if (bind(p->fd, &sa, sizeof(sa))) {
- sprintf(ebuf, "bind: %s: %s", device, pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, "bind: %s: %s", device,
+ pcap_strerror(errno));
goto bad;
}
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(p->fd, SIOCGIFHWADDR, &ifr) < 0 ) {
- sprintf(ebuf, "SIOCGIFHWADDR: %s", pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, "SIOCGIFHWADDR: %s",
+ pcap_strerror(errno));
goto bad;
}
broadcast = 0;
@@ -251,7 +256,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
#endif
default:
- sprintf(ebuf, "unknown physical layer type 0x%x",
+ snprint(ebuf, PCAP_ERRBUFF_SIZE,
+ "unknown physical layer type 0x%x",
ifr.ifr_hwaddr.sa_family);
goto bad;
}
@@ -260,7 +266,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
if (ioctl(p->fd, SIOCGIFMTU, &ifr) < 0 ) {
- sprintf(ebuf, "SIOCGIFMTU: %s", pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, "SIOCGIFMTU: %s",
+ pcap_strerror(errno));
goto bad;
}
@@ -269,7 +276,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p->buffer = (u_char *)malloc(p->bufsize + p->offset);
if (p->buffer == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, "malloc: %s",
+ pcap_strerror(errno));
goto bad;
}
@@ -278,13 +286,15 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, device);
if (ioctl(p->fd, SIOCGIFFLAGS, &ifr) < 0 ) {
- sprintf(ebuf, "SIOCGIFFLAGS: %s", pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, "SIOCGIFFLAGS: %s",
+ pcap_strerror(errno));
goto bad;
}
saved_ifr = ifr;
ifr.ifr_flags |= IFF_PROMISC;
if (ioctl(p->fd, SIOCSIFFLAGS, &ifr) < 0 ) {
- sprintf(ebuf, "SIOCSIFFLAGS: %s", pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, "SIOCSIFFLAGS: %s",
+ pcap_strerror(errno));
goto bad;
}
ifr.ifr_flags &= ~IFF_PROMISC;
@@ -293,7 +303,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p->md.device = strdup(device);
if (p->md.device == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprint(ebuf, PCAP_ERRBUFF_SIZE, "malloc: %s",
+ pcap_strerror(errno));
goto bad;
}
p->snapshot = snaplen;
diff --git a/pcap-nit.c b/pcap-nit.c
index a2e2a43..cb4a573 100644
--- a/pcap-nit.c
+++ b/pcap-nit.c
@@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.31 1999-10-07 23:46:40 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-nit.c,v 1.32 2000-04-27 09:11:13 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -91,7 +91,7 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
if (cc < 0) {
if (errno == EWOULDBLOCK)
return (0);
- sprintf(p->errbuf, "pcap_read: %s",
+ snprintf(p->errbuf, sizeof(p->errbuf), "pcap_read: %s",
pcap_strerror(errno));
return (-1);
}
@@ -125,7 +125,8 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
continue;
default:
- sprintf(p->errbuf, "bad nit state %d", nh->nh_state);
+ snprintf(p->errbuf, sizeof(p->errbuf),
+ "bad nit state %d", nh->nh_state);
return (-1);
}
++p->md.stat.ps_recv;
@@ -174,7 +175,8 @@ nit_setflags(int fd, int promisc, int to_ms, char *ebuf)
nioc.nioc_flags |= NF_PROMISC;
if (ioctl(fd, SIOCSNIT, &nioc) < 0) {
- sprintf(ebuf, "SIOCSNIT: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "SIOCSNIT: %s",
+ pcap_strerror(errno));
return (-1);
}
return (0);
@@ -202,15 +204,16 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
bzero(p, sizeof(*p));
p->fd = fd = socket(AF_NIT, SOCK_RAW, NITPROTO_RAW);
if (fd < 0) {
- sprintf(ebuf, "socket: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "socket: %s", pcap_strerror(errno));
goto bad;
}
snit.snit_family = AF_NIT;
(void)strncpy(snit.snit_ifname, device, NITIFSIZ);
if (bind(fd, (struct sockaddr *)&snit, sizeof(snit))) {
- sprintf(ebuf, "bind: %s: %s", snit.snit_ifname,
- pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "bind: %s: %s", snit.snit_ifname, pcap_strerror(errno));
goto bad;
}
p->snapshot = snaplen;
diff --git a/pcap-null.c b/pcap-null.c
index cbc818b..963088f 100644
--- a/pcap-null.c
+++ b/pcap-null.c
@@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.7 1999-10-07 23:46:40 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-null.c,v 1.8 2000-04-27 09:11:13 itojun Exp $ (LBL)";
#endif
#include <sys/param.h> /* optionally get BSD define */
@@ -40,7 +40,7 @@ int
pcap_stats(pcap_t *p, struct pcap_stat *ps)
{
- (void)sprintf(p->errbuf, "pcap_stats: %s", nosup);
+ (void)snprintf(p->errbuf, sizeof(p->errbuf), "pcap_stats: %s", nosup);
return (-1);
}
@@ -48,7 +48,7 @@ int
pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
- (void)sprintf(p->errbuf, "pcap_read: %s", nosup);
+ (void)snprintf(p->errbuf, sizeof(p->errbuf), "pcap_read: %s", nosup);
return (-1);
}
@@ -65,7 +65,8 @@ pcap_setfilter(pcap_t *p, struct bpf_program *fp)
{
if (p->sf.rfile == NULL) {
- (void)sprintf(p->errbuf, "pcap_setfilter: %s", nosup);
+ (void)snprintf(p->errbuf, sizeof(p->errbuf),
+ "pcap_setfilter: %s", nosup);
return (-1);
}
p->fcode = *fp;
diff --git a/pcap-pf.c b/pcap-pf.c
index 542de8a..7aba3ab 100644
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -24,7 +24,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.54 1999-10-07 23:46:40 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.55 2000-04-27 09:11:13 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -108,7 +108,7 @@ pcap_read(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
(void)lseek(pc->fd, 0L, SEEK_SET);
goto again;
}
- sprintf(pc->errbuf, "pf read: %s",
+ snprintf(pc->errbuf, sizeof(pc->errbuf), "pf read: %s",
pcap_strerror(errno));
return (-1);
}
@@ -127,7 +127,8 @@ pcap_read(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
#endif
while (cc > 0) {
if (cc < sizeof(*sp)) {
- sprintf(pc->errbuf, "pf short read (%d)", cc);
+ snprintf(pc->errbuf, sizeof(pc->errbuf),
+ "pf short read (%d)", cc);
return (-1);
}
#ifdef LBL_ALIGN
@@ -138,7 +139,8 @@ pcap_read(pcap_t *pc, int cnt, pcap_handler callback, u_char *user)
#endif
sp = (struct enstamp *)bp;
if (sp->ens_stamplen != sizeof(*sp)) {
- sprintf(pc->errbuf, "pf short stamplen (%d)",
+ snprintf(pc->errbuf, sizeof(pc->errbuf),
+ "pf short stamplen (%d)",
sp->ens_stamplen);
return (-1);
}
@@ -210,13 +212,14 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p = (pcap_t *)malloc(sizeof(*p));
if (p == NULL) {
- sprintf(ebuf, "pcap_open_live: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "pcap_open_live: %s", pcap_strerror(errno));
return (0);
}
bzero((char *)p, sizeof(*p));
p->fd = pfopen(device, O_RDONLY);
if (p->fd < 0) {
- sprintf(ebuf, "pf open: %s: %s\n\
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "pf open: %s: %s\n\
your system may not be properly configured; see \"man packetfilter(4)\"\n",
device, pcap_strerror(errno));
goto bad;
@@ -226,7 +229,8 @@ your system may not be properly configured; see \"man packetfilter(4)\"\n",
if (promisc)
enmode |= ENPROMISC;
if (ioctl(p->fd, EIOCMBIS, (caddr_t)&enmode) < 0) {
- sprintf(ebuf, "EIOCMBIS: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "EIOCMBIS: %s",
+ pcap_strerror(errno));
goto bad;
}
#ifdef ENCOPYALL
@@ -236,12 +240,14 @@ your system may not be properly configured; see \"man packetfilter(4)\"\n",
#endif
/* set the backlog */
if (ioctl(p->fd, EIOCSETW, (caddr_t)&backlog) < 0) {
- sprintf(ebuf, "EIOCSETW: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "EIOCSETW: %s",
+ pcap_strerror(errno));
goto bad;
}
/* discover interface type */
if (ioctl(p->fd, EIOCDEVP, (caddr_t)&devparams) < 0) {
- sprintf(ebuf, "EIOCDEVP: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "EIOCDEVP: %s",
+ pcap_strerror(errno));
goto bad;
}
/* HACK: to compile prior to Ultrix 4.2 */
@@ -282,7 +288,8 @@ your system may not be properly configured; see \"man packetfilter(4)\"\n",
snaplen += pcap_fddipad;
#endif
if (ioctl(p->fd, EIOCTRUNCATE, (caddr_t)&snaplen) < 0) {
- sprintf(ebuf, "EIOCTRUNCATE: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "EIOCTRUNCATE: %s",
+ pcap_strerror(errno));
goto bad;
}
p->snapshot = snaplen;
@@ -291,7 +298,8 @@ your system may not be properly configured; see \"man packetfilter(4)\"\n",
Filter.enf_Priority = 37; /* anything > 2 */
Filter.enf_FilterLen = 0; /* means "always true" */
if (ioctl(p->fd, EIOCSETF, (caddr_t)&Filter) < 0) {
- sprintf(ebuf, "EIOCSETF: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "EIOCSETF: %s",
+ pcap_strerror(errno));
goto bad;
}
@@ -300,7 +308,7 @@ your system may not be properly configured; see \"man packetfilter(4)\"\n",
timeout.tv_sec = to_ms / 1000;
timeout.tv_usec = (to_ms * 1000) % 1000000;
if (ioctl(p->fd, EIOCSRTIMEOUT, (caddr_t)&timeout) < 0) {
- sprintf(ebuf, "EIOCSRTIMEOUT: %s",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "EIOCSRTIMEOUT: %s",
pcap_strerror(errno));
goto bad;
}
@@ -326,8 +334,8 @@ pcap_setfilter(pcap_t *p, struct bpf_program *fp)
struct bpf_version bv;
if (ioctl(p->fd, BIOCVERSION, (caddr_t)&bv) < 0) {
- sprintf(p->errbuf, "BIOCVERSION: %s",
- pcap_strerror(errno));
+ snprintf(p->errbuf, sizeof(p->errbuf),
+ "BIOCVERSION: %s", pcap_strerror(errno));
return (-1);
}
else if (bv.bv_major != BPF_MAJOR_VERSION ||
diff --git a/pcap-snit.c b/pcap-snit.c
index 6971d3b..a80491e 100644
--- a/pcap-snit.c
+++ b/pcap-snit.c
@@ -25,7 +25,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.45 1999-10-07 23:46:40 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-snit.c,v 1.46 2000-04-27 09:11:13 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -110,7 +110,7 @@ pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
if (cc < 0) {
if (errno == EWOULDBLOCK)
return (0);
- sprintf(p->errbuf, "pcap_read: %s",
+ snprintf(p->errbuf, sizeof(p->errbuf), "pcap_read: %s",
pcap_strerror(errno));
return (-1);
}
@@ -182,7 +182,8 @@ nit_setflags(int fd, int promisc, int to_ms, char *ebuf)
si.ic_len = sizeof(timeout);
si.ic_dp = (char *)&timeout;
if (ioctl(fd, I_STR, (char *)&si) < 0) {
- sprintf(ebuf, "NIOCSTIME: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "NIOCSTIME: %s",
+ pcap_strerror(errno));
return (-1);
}
}
@@ -193,7 +194,8 @@ nit_setflags(int fd, int promisc, int to_ms, char *ebuf)
si.ic_len = sizeof(flags);
si.ic_dp = (char *)&flags;
if (ioctl(fd, I_STR, (char *)&si) < 0) {
- sprintf(ebuf, "NIOCSFLAGS: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "NIOCSFLAGS: %s",
+ pcap_strerror(errno));
return (-1);
}
return (0);
@@ -224,17 +226,20 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
bzero(p, sizeof(*p));
p->fd = fd = open(dev, O_RDONLY);
if (fd < 0) {
- sprintf(ebuf, "%s: %s", dev, pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "%s: %s", dev,
+ pcap_strerror(errno));
goto bad;
}
/* arrange to get discrete messages from the STREAM and use NIT_BUF */
if (ioctl(fd, I_SRDOPT, (char *)RMSGD) < 0) {
- sprintf(ebuf, "I_SRDOPT: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "I_SRDOPT: %s",
+ pcap_strerror(errno));
goto bad;
}
if (ioctl(fd, I_PUSH, "nbuf") < 0) {
- sprintf(ebuf, "push nbuf: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "push nbuf: %s",
+ pcap_strerror(errno));
goto bad;
}
/* set the chunksize */
@@ -243,7 +248,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
si.ic_len = sizeof(chunksize);
si.ic_dp = (char *)&chunksize;
if (ioctl(fd, I_STR, (char *)&si) < 0) {
- sprintf(ebuf, "NIOCSCHUNK: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "NIOCSCHUNK: %s",
+ pcap_strerror(errno));
goto bad;
}
@@ -254,7 +260,7 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
si.ic_len = sizeof(ifr);
si.ic_dp = (char *)&ifr;
if (ioctl(fd, I_STR, (char *)&si) < 0) {
- sprintf(ebuf, "NIOCBIND: %s: %s",
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "NIOCBIND: %s: %s",
ifr.ifr_name, pcap_strerror(errno));
goto bad;
}
@@ -264,7 +270,8 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
si.ic_len = sizeof(snaplen);
si.ic_dp = (char *)&snaplen;
if (ioctl(fd, I_STR, (char *)&si) < 0) {
- sprintf(ebuf, "NIOCSSNAP: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "NIOCSSNAP: %s",
+ pcap_strerror(errno));
goto bad;
}
p->snapshot = snaplen;
diff --git a/pcap-snoop.c b/pcap-snoop.c
index 16d5cbe..6557d72 100644
--- a/pcap-snoop.c
+++ b/pcap-snoop.c
@@ -20,7 +20,7 @@
*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.21 2000-02-08 20:46:45 kenh Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.22 2000-04-27 09:11:14 itojun Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -76,7 +76,8 @@ again:
case EWOULDBLOCK:
return (0); /* XXX */
}
- sprintf(p->errbuf, "read: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, sizeof(p->errbuf),
+ "read: %s", pcap_strerror(errno));
return (-1);
}
sh = (struct snoopheader *)p->buffer;
@@ -106,7 +107,8 @@ pcap_stats(pcap_t *p, struct pcap_stat *ps)
rs = &rawstats;
bzero((char *)rs, sizeof(*rs));
if (ioctl(p->fd, SIOCRAWSTATS, (char *)rs) < 0) {
- sprintf(p->errbuf, "SIOCRAWSTATS: %s", pcap_strerror(errno));
+ snprintf(p->errbuf, sizeof(p->errbuf),
+ "SIOCRAWSTATS: %s", pcap_strerror(errno));
return (-1);
}
@@ -130,13 +132,15 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
p = (pcap_t *)malloc(sizeof(*p));
if (p == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "malloc: %s",
+ pcap_strerror(errno));
return (NULL);
}
bzero((char *)p, sizeof(*p));
fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_SNOOP);
if (fd < 0) {
- sprintf(ebuf, "snoop socket: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "snoop socket: %s",
+ pcap_strerror(errno));
goto bad;
}
p->fd = fd;
@@ -144,24 +148,28 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
sr.sr_family = AF_RAW;
(void)strncpy(sr.sr_ifname, device, sizeof(sr.sr_ifname));
if (bind(fd, (struct sockaddr *)&sr, sizeof(sr))) {
- sprintf(ebuf, "snoop bind: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "snoop bind: %s",
+ pcap_strerror(errno));
goto bad;
}
bzero((char *)&sf, sizeof(sf));
if (ioctl(fd, SIOCADDSNOOP, &sf) < 0) {
- sprintf(ebuf, "SIOCADDSNOOP: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "SIOCADDSNOOP: %s",
+ pcap_strerror(errno));
goto bad;
}
v = 64 * 1024;
(void)setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&v, sizeof(v));
if (ioctl(fd, SIOCSNOOPLEN, &snaplen) < 0) {
- sprintf(ebuf, "SIOCSNOOPLEN: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "SIOCSNOOPLEN: %s",
+ pcap_strerror(errno));
goto bad;
}
p->snapshot = snaplen;
v = 1;
if (ioctl(fd, SIOCSNOOPING, &v) < 0) {
- sprintf(ebuf, "SIOCSNOOPING: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "SIOCSNOOPING: %s",
+ pcap_strerror(errno));
goto bad;
}
/*
@@ -190,14 +198,16 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
} else if (strncmp("lo", device, 2) == 0) {
p->linktype = DLT_NULL;
} else {
- sprintf(ebuf, "snoop: unknown physical layer type");
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE,
+ "snoop: unknown physical layer type");
goto bad;
}
p->bufsize = 4096; /* XXX */
p->buffer = (u_char *)malloc(p->bufsize);
if (p->buffer == NULL) {
- sprintf(ebuf, "malloc: %s", pcap_strerror(errno));
+ snprintf(ebuf, PCAP_ERRBUFF_SIZE, "malloc: %s",
+ pcap_strerror(errno));
goto bad;
}
diff --git a/pcap.3 b/pcap.3
index c358c63..e60a86e 100644
--- a/pcap.3
+++ b/pcap.3
@@ -91,6 +91,18 @@ on the network, even those destined for other hosts, are accessible
through this mechanism.
.PP
.SH ROUTINES
+NOTE:
+.I errbuf
+in
+.B pcap_open_live(),
+.B pcap_open_offline(),
+.B pcap_lookupdev(),
+and
+.B pcap_lookupnet()
+is assumed to be able to hold at least
+.B PCAP_ERRBUFF_SIZE
+chars.
+.PP
.B pcap_open_live()
is used to obtain a packet capture descriptor to look
at packets on the network.
diff --git a/pcap.c b/pcap.c
index 0f1848e..808e4db 100644
--- a/pcap.c
+++ b/pcap.c
@@ -33,7 +33,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.29 1999-10-07 23:46:40 mcr Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.30 2000-04-27 09:11:14 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -180,7 +180,7 @@ pcap_strerror(int errnum)
if ((unsigned int)errnum < sys_nerr)
return ((char *)sys_errlist[errnum]);
- (void)sprintf(ebuf, "Unknown error: %d", errnum);
+ (void)snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum);
return(ebuf);
#endif
}
diff --git a/savefile.c b/savefile.c
index d437d32..50ea33c 100644
--- a/savefile.c
+++ b/savefile.c
@@ -30,7 +30,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.38 1999-11-21 01:11:58 assar Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.39 2000-04-27 09:11:14 itojun Exp $ (LBL)";
#endif
#include <sys/types.h>
@@ -112,7 +112,7 @@ pcap_open_offline(const char *fname, char *errbuf)
p = (pcap_t *)malloc(sizeof(*p));
if (p == NULL) {
- strcpy(errbuf, "out of swap");
+ strlcpy(errbuf, "out of swap", PCAP_ERRBUF_SIZE);
return (NULL);
}
@@ -127,24 +127,27 @@ pcap_open_offline(const char *fname, char *errbuf)
else {
fp = fopen(fname, "r");
if (fp == NULL) {
- sprintf(errbuf, "%s: %s", fname, pcap_strerror(errno));
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "%s: %s", fname,
+ pcap_strerror(errno));
goto bad;
}
}
if (fread((char *)&hdr, sizeof(hdr), 1, fp) != 1) {
- sprintf(errbuf, "fread: %s", pcap_strerror(errno));
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "fread: %s",
+ pcap_strerror(errno));
goto bad;
}
if (hdr.magic != TCPDUMP_MAGIC) {
if (SWAPLONG(hdr.magic) != TCPDUMP_MAGIC) {
- sprintf(errbuf, "bad dump file format");
+ snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "bad dump file format");
goto bad;
}
p->sf.swapped = 1;
swap_hdr(&hdr);
}
if (hdr.version_major < PCAP_VERSION_MAJOR) {
- sprintf(errbuf, "archaic file format");
+ snprintf(errbuf, PCAP_ERRBUF_SIZE, "archaic file format");
goto bad;
}
p->tzoff = hdr.thiszone;
@@ -171,7 +174,13 @@ pcap_open_offline(const char *fname, char *errbuf)
break;
}
+ if (p->bufsize < 0)
+ p->bufsize = BPF_MAXBUFSIZE;
p->sf.base = (u_char *)malloc(p->bufsize + BPF_ALIGNMENT);
+ if (p->sf.base == NULL) {
+ strlcpy(errbuf, "out of swap", PCAP_ERRBUF_SIZE);
+ goto bad;
+ }
p->buffer = p->sf.base + BPF_ALIGNMENT - (linklen % BPF_ALIGNMENT);
p->sf.version_major = hdr.version_major;
p->sf.version_minor = hdr.version_minor;
@@ -239,9 +248,11 @@ sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
static int tsize = 0;
if (hdr->caplen > 65535) {
- sprintf(p->errbuf, "bogus savefile header");
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "bogus savefile header");
return (-1);
}
+
if (tsize < hdr->caplen) {
tsize = ((hdr->caplen + 1023) / 1024) * 1024;
if (tp != NULL)
@@ -249,12 +260,14 @@ sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
tp = (u_char *)malloc(tsize);
if (tp == NULL) {
tsize = 0;
- sprintf(p->errbuf, "BUFMOD hack malloc");
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "BUFMOD hack malloc");
return (-1);
}
}
if (fread((char *)tp, hdr->caplen, 1, fp) != 1) {
- sprintf(p->errbuf, "truncated dump file");
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "truncated dump file");
return (-1);
}
/*
@@ -271,7 +284,8 @@ sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen)
/* read the packet itself */
if (fread((char *)buf, hdr->caplen, 1, fp) != 1) {
- sprintf(p->errbuf, "truncated dump file");
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "truncated dump file");
return (-1);
}
}
@@ -341,7 +355,7 @@ pcap_dump_open(pcap_t *p, const char *fname)
else {
f = fopen(fname, "w");
if (f == NULL) {
- sprintf(p->errbuf, "%s: %s",
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s",
fname, pcap_strerror(errno));
return (NULL);
}