aboutsummaryrefslogtreecommitdiffstats
path: root/pcap-snoop.c
diff options
context:
space:
mode:
authorassar <assar>2000-04-30 07:32:56 +0000
committerassar <assar>2000-04-30 07:32:56 +0000
commit1f2deabd64aa3438b71da69ffe8ed2d0992be388 (patch)
tree82fe7ba2c20ffa39c7c6e8537bc1e305ed3e9b6d /pcap-snoop.c
parent5c3ea071a8bfd56016ca077b06bf38446fca7d10 (diff)
change sprintf -> snprintf from previous patch. also from Guy Harris
<gharris@flashcom.net>
Diffstat (limited to 'pcap-snoop.c')
-rw-r--r--pcap-snoop.c113
1 files changed, 58 insertions, 55 deletions
diff --git a/pcap-snoop.c b/pcap-snoop.c
index eedbf99..a862300 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.24 2000-04-29 10:09:23 assar Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.25 2000-04-30 07:32:56 assar Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -185,67 +185,70 @@ pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf)
strncmp("xpi", device, 3) == 0) {
p->linktype = DLT_FDDI;
p->offset = 3; /* XXX yeah? */
- ll_hdrlen = 13;
+ ll_hdrlen = 13;
} else if (strncmp("ppp", device, 3) == 0) {
p->linktype = DLT_RAW;
- ll_hdrlen = 0; /* DLT_RAW meaning "no PPP header, just the IP packet"? */
+ ll_hdrlen = 0; /* DLT_RAW meaning "no PPP header, just the IP packet"? */
} else if (strncmp("lo", device, 2) == 0) {
p->linktype = DLT_NULL;
- ll_hdrlen = 4; /* is this just like BSD's loopback device? */
+ ll_hdrlen = 4; /* is this just like BSD's loopback device? */
} else {
snprintf(ebuf, PCAP_ERRBUF_SIZE,
"snoop: unknown physical layer type");
- goto bad;
- }
- #ifdef SIOCGIFMTU
- /*
- * XXX - IRIX appears to give you an error if you try to set the
- * capture length to be greater than the MTU, so let's try to get
- * the MTU first and, if that succeeds, trim the snap length
- * to be no greater than the MTU.
- */
- (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
- if (ioctl(fd, SIOCGIFMTU, (char *)&ifr) < 0) {
- sprintf(ebuf, "SIOCGIFMTU: %s", pcap_strerror(errno));
- goto bad;
- }
- /*
- * OK, we got it.
- *
- * XXX - some versions of IRIX 6.5 define "ifr_mtu" and have an
- * "ifru_metric" member of the "ifr_ifru" union in an "ifreq"
- * structure, others don't.
- *
- * I've no idea what's going on, so, if "ifr_mtu" isn't defined,
- * we define it as "ifr_metric", as using that field appears to
- * work on the versions that lack "ifr_mtu" (and, on those that
- * don't lack it, "ifru_metric" and "ifru_mtu" are both "int"
- * members of the "ifr_ifru" union, which suggests that they
- * may be interchangeable in this case).
- */
- #ifndef ifr_mtu
- #define ifr_mtu ifr_metric
- #endif
- if (snaplen > ifr.ifr_mtu)
- snaplen = ifr.ifr_mtu;
- #endif
-
- /*
- * The argument to SIOCSNOOPLEN is the number of link-layer
- * payload bytes to capture - it doesn't count link-layer
- * header bytes.
- */
- snooplen = snaplen - ll_hdrlen;
- if (snooplen < 0)
- snooplen = 0;
- if (ioctl(fd, SIOCSNOOPLEN, &snooplen) < 0) {
- sprintf(ebuf, "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));
+ goto bad;
+ }
+#ifdef SIOCGIFMTU
+ /*
+ * XXX - IRIX appears to give you an error if you try to set the
+ * capture length to be greater than the MTU, so let's try to get
+ * the MTU first and, if that succeeds, trim the snap length
+ * to be no greater than the MTU.
+ */
+ (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
+ if (ioctl(fd, SIOCGIFMTU, (char *)&ifr) < 0) {
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCGIFMTU: %s",
+ pcap_strerror(errno));
+ goto bad;
+ }
+ /*
+ * OK, we got it.
+ *
+ * XXX - some versions of IRIX 6.5 define "ifr_mtu" and have an
+ * "ifru_metric" member of the "ifr_ifru" union in an "ifreq"
+ * structure, others don't.
+ *
+ * I've no idea what's going on, so, if "ifr_mtu" isn't defined,
+ * we define it as "ifr_metric", as using that field appears to
+ * work on the versions that lack "ifr_mtu" (and, on those that
+ * don't lack it, "ifru_metric" and "ifru_mtu" are both "int"
+ * members of the "ifr_ifru" union, which suggests that they
+ * may be interchangeable in this case).
+ */
+#ifndef ifr_mtu
+#define ifr_mtu ifr_metric
+#endif
+ if (snaplen > ifr.ifr_mtu)
+ snaplen = ifr.ifr_mtu;
+#endif
+
+ /*
+ * The argument to SIOCSNOOPLEN is the number of link-layer
+ * payload bytes to capture - it doesn't count link-layer
+ * header bytes.
+ */
+ snooplen = snaplen - ll_hdrlen;
+ if (snooplen < 0)
+ snooplen = 0;
+ if (ioctl(fd, SIOCSNOOPLEN, &snooplen) < 0) {
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCSNOOPLEN: %s",
+ pcap_strerror(errno));
+ goto bad;
+ }
+ p->snapshot = snaplen;
+ v = 1;
+ if (ioctl(fd, SIOCSNOOPING, &v) < 0) {
+ snprintf(ebuf, PCAP_ERRBUF_SIZE, "SIOCSNOOPING: %s",
+ pcap_strerror(errno));
goto bad;
}