From 20d9e08cde232247531358fd448ad845c89c7a16 Mon Sep 17 00:00:00 2001 From: itojun Date: Thu, 27 Apr 2000 09:11:11 +0000 Subject: do not use sprintf(). always use snprintf(). from NetBSD/OpenBSD src/lib/libpcap. use freeifaddrs() if exists. --- pcap-nit.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'pcap-nit.c') 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 @@ -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; -- cgit v1.2.3