from NetBSD/OpenBSD src/lib/libpcap.
use freeifaddrs() if exists.
#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>
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"
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
-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.
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
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)
*/
#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>
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 */
#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>
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;
}
}
}
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;
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);
}
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);
}
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);
}
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);
}
(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);
}
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));
(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);
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);
}
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);
}
}
*/
#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>
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");
*/
#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 */
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);
}
/* 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;
{
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);
* 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);
}
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));
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 */
(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__
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;
}
}
(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;
}
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);
#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>
*/
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 */
*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 */
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;
}
** 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
** 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;
}
#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;
}
** 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;
}
/*
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;
}
}
** 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 */
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);
}
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);
}
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);
}
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);
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);
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,
(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);
}
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);
*/
#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>
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));
++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);
}
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));
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;
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;
#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;
}
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;
}
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;
}
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;
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;
*/
#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>
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);
}
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;
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);
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;
*/
#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 */
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);
}
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);
}
{
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;
#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>
(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);
}
#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
#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);
}
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;
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
#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 */
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;
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;
}
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;
}
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 ||
#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>
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);
}
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);
}
}
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);
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 */
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;
}
si.ic_len = sizeof(ifr);
si.ic_dp = (char *)𝔦
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;
}
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;
*/
#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>
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;
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);
}
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;
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;
}
/*
} 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;
}
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.
#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>
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
}
#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>
p = (pcap_t *)malloc(sizeof(*p));
if (p == NULL) {
- strcpy(errbuf, "out of swap");
+ strlcpy(errbuf, "out of swap", PCAP_ERRBUF_SIZE);
return (NULL);
}
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;
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;
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)
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);
}
/*
/* 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);
}
}
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);
}