summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etherent.c19
-rw-r--r--fad-getad.c3
-rw-r--r--fad-gifc.c3
-rw-r--r--fad-glifc.c3
-rw-r--r--nametoaddr.c7
-rw-r--r--pcap-bpf.c5
-rw-r--r--pcap-dag.c1
-rw-r--r--pcap-dlpi.c3
-rw-r--r--pcap-dpdk.c1
-rw-r--r--pcap-int.h19
-rw-r--r--pcap-linux.c7
-rw-r--r--pcap-netmap.c1
-rw-r--r--pcap-nit.c1
-rw-r--r--pcap-pf.c1
-rw-r--r--pcap-septel.c1
-rw-r--r--pcap-snf.c1
-rw-r--r--pcap-snit.c1
-rw-r--r--pcap-usb-linux.c5
-rw-r--r--pcap.c3
-rw-r--r--portability.h2
20 files changed, 45 insertions, 42 deletions
diff --git a/etherent.c b/etherent.c
index 5f499613..e883a9c7 100644
--- a/etherent.c
+++ b/etherent.c
@@ -25,7 +25,6 @@
#include <pcap-types.h>
-#include <ctype.h>
#include <memory.h>
#include <stdio.h>
#include <string.h>
@@ -45,14 +44,18 @@ static inline int skip_line(FILE *);
static inline u_char
xdtoi(u_char c)
{
- if (isdigit(c))
+ if (c >= '0' && c < '9')
return (u_char)(c - '0');
- else if (islower(c))
+ else if (c >= 'a' && c <= 'f')
return (u_char)(c - 'a' + 10);
else
return (u_char)(c - 'A' + 10);
}
+/*
+ * Skip linear white space (space and tab) and any CRs before LF.
+ * Stop when we hit a non-white-space character or an end-of-line LF.
+ */
static inline int
skip_space(FILE *f)
{
@@ -60,7 +63,7 @@ skip_space(FILE *f)
do {
c = getc(f);
- } while (isspace(c) && c != '\n');
+ } while (PCAP_ISLWSP(c) || c == '\r');
return c;
}
@@ -97,7 +100,7 @@ pcap_next_etherent(FILE *fp)
/* If this is a comment, or first thing on line
cannot be Ethernet address, skip the line. */
- if (!isxdigit(c)) {
+ if (!PCAP_ISXDIGIT(c)) {
c = skip_line(fp);
if (c == EOF)
return (NULL);
@@ -110,7 +113,7 @@ pcap_next_etherent(FILE *fp)
c = getc(fp);
if (c == EOF)
return (NULL);
- if (isxdigit(c)) {
+ if (PCAP_ISXDIGIT(c)) {
d <<= 4;
d |= xdtoi((u_char)c);
c = getc(fp);
@@ -126,7 +129,7 @@ pcap_next_etherent(FILE *fp)
}
/* Must be whitespace */
- if (!isspace(c)) {
+ if (!PCAP_ISSPACE(c)) {
c = skip_line(fp);
if (c == EOF)
return (NULL);
@@ -156,7 +159,7 @@ pcap_next_etherent(FILE *fp)
c = getc(fp);
if (c == EOF)
return (NULL);
- } while (!isspace(c) && --namesize != 0);
+ } while (!PCAP_ISSPACE(c) && --namesize != 0);
*bp = '\0';
/* Eat trailing junk */
diff --git a/fad-getad.c b/fad-getad.c
index 5236fbb9..ba8f9753 100644
--- a/fad-getad.c
+++ b/fad-getad.c
@@ -42,7 +42,6 @@
#include <net/if.h>
-#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -190,7 +189,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
* We have a ":"; is it followed by a number?
*/
q = p + 1;
- while (isdigit((unsigned char)*q))
+ while (PCAP_ISDIGIT(*q))
q++;
if (*q == '\0') {
/*
diff --git a/fad-gifc.c b/fad-gifc.c
index ccb93c36..8940876a 100644
--- a/fad-gifc.c
+++ b/fad-gifc.c
@@ -49,7 +49,6 @@ struct rtentry; /* declarations in <net/if.h> */
#include <net/if.h>
#include <netinet/in.h>
-#include <ctype.h>
#include <errno.h>
#include <memory.h>
#include <stdio.h>
@@ -394,7 +393,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
* We have a ":"; is it followed by a number?
*/
q = p + 1;
- while (isdigit((unsigned char)*q))
+ while (PCAP_ISDIGIT(*q))
q++;
if (*q == '\0') {
/*
diff --git a/fad-glifc.c b/fad-glifc.c
index f22f56d7..6b275eb3 100644
--- a/fad-glifc.c
+++ b/fad-glifc.c
@@ -50,7 +50,6 @@ struct rtentry; /* declarations in <net/if.h> */
#include <net/if.h>
#include <netinet/in.h>
-#include <ctype.h>
#include <errno.h>
#include <memory.h>
#include <stdio.h>
@@ -311,7 +310,7 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
* We have a ":"; is it followed by a number?
*/
q = p + 1;
- while (isdigit((unsigned char)*q))
+ while (PCAP_ISDIGIT(*q))
q++;
if (*q == '\0') {
/*
diff --git a/nametoaddr.c b/nametoaddr.c
index 5cfb51c4..4d632819 100644
--- a/nametoaddr.c
+++ b/nametoaddr.c
@@ -127,7 +127,6 @@
#include <netdb.h>
#endif /* _WIN32 */
-#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -653,9 +652,9 @@ pcap_nametollc(const char *s)
static inline u_char
xdtoi(u_char c)
{
- if (isdigit(c))
+ if (c >= '0' && c < '9')
return (u_char)(c - '0');
- else if (islower(c))
+ else if (c >= 'a' && c <= 'f')
return (u_char)(c - 'a' + 10);
else
return (u_char)(c - 'A' + 10);
@@ -727,7 +726,7 @@ pcap_ether_aton(const char *s)
if (*s == ':' || *s == '.' || *s == '-')
s += 1;
d = xdtoi(*s++);
- if (isxdigit((unsigned char)*s)) {
+ if (PCAP_ISXDIGIT(*s)) {
d <<= 4;
d |= xdtoi(*s++);
}
diff --git a/pcap-bpf.c b/pcap-bpf.c
index 6bf002a9..0029b8b9 100644
--- a/pcap-bpf.c
+++ b/pcap-bpf.c
@@ -115,7 +115,6 @@ static int bpf_load(char *errbuf);
#endif /* _AIX */
-#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <netdb.h>
@@ -2177,9 +2176,9 @@ pcap_activate_bpf(pcap_t *p)
* we try to select DLT_IEEE802_11.
*/
if (have_osinfo) {
- if (isdigit((unsigned)osinfo.release[0]) &&
+ if (PCAP_ISDIGIT((unsigned)osinfo.release[0]) &&
(osinfo.release[0] == '9' ||
- isdigit((unsigned)osinfo.release[1]))) {
+ PCAP_ISDIGIT((unsigned)osinfo.release[1]))) {
/*
* 10.5 (Darwin 9.x), or later.
*/
diff --git a/pcap-dag.c b/pcap-dag.c
index d4b0f029..7de2963c 100644
--- a/pcap-dag.c
+++ b/pcap-dag.c
@@ -19,7 +19,6 @@
#include "pcap-int.h"
-#include <ctype.h>
#include <netinet/in.h>
#include <sys/mman.h>
#include <sys/socket.h>
diff --git a/pcap-dlpi.c b/pcap-dlpi.c
index b32b98a7..948199a8 100644
--- a/pcap-dlpi.c
+++ b/pcap-dlpi.c
@@ -96,7 +96,6 @@
#include <net/if.h>
#endif
-#include <ctype.h>
#ifdef HAVE_HPUX9
#include <nlist.h>
#endif
@@ -1546,7 +1545,7 @@ get_release(char *buf, size_t bufsize, bpf_u_int32 *majorp,
return;
}
cp = buf;
- if (!isdigit((unsigned char)*cp))
+ if (!PCAP_ISDIGIT((unsigned char)*cp))
return;
*majorp = strtol(cp, &cp, 10);
if (*cp++ != '.')
diff --git a/pcap-dpdk.c b/pcap-dpdk.c
index 3a8158d7..6c2f21fc 100644
--- a/pcap-dpdk.c
+++ b/pcap-dpdk.c
@@ -79,7 +79,6 @@ env DPDK_CFG="--log-level=debug -l0 -dlibrte_pmd_e1000.so -dlibrte_pmd_ixgbe.so
#include <config.h>
#endif
-#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
diff --git a/pcap-int.h b/pcap-int.h
index 6fe535a3..bd3eeac7 100644
--- a/pcap-int.h
+++ b/pcap-int.h
@@ -97,6 +97,25 @@ extern "C" {
*/
#define MAXIMUM_SNAPLEN 262144
+/*
+ * Locale-independent macros for testing character types.
+ * These can be passed any integral value, without worrying about, for
+ * example, sign-extending char values, unlike the C macros.
+ *
+ * Note that PCAP_ISSPACE doesn't worry about form feeds or vertical
+ * tabs; it only matches space, tab, CR, and LF.
+ */
+#define PCAP_ISDIGIT(c) \
+ ((c) >= '0' && (c) <= '9')
+#define PCAP_ISXDIGIT(c) \
+ (((c) >= '0' && (c) <= '9') || \
+ ((c) >= 'A' && (c) <= 'F') || \
+ ((c) >= 'a' && (c) <= 'f'))
+#define PCAP_ISLWSP(c) \
+ ((c) == ' ' || (c) == '\t')
+#define PCAP_ISSPACE(c) \
+ ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
+
struct pcap_opt {
char *device;
int timeout; /* timeout for buffering */
diff --git a/pcap-linux.c b/pcap-linux.c
index f8b6d9d4..a28d189d 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -119,7 +119,6 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
@@ -2528,7 +2527,7 @@ add_linux_if(pcap_if_list_t *devlistp, const char *ifname, int fd, char *errbuf)
*/
p = ifname;
q = &name[0];
- while (*p != '\0' && isascii(*p) && !isspace(*p)) {
+ while (*p != '\0' && PCAP_ISSPACE(*p)) {
if (*p == ':') {
/*
* This could be the separator between a
@@ -2542,7 +2541,7 @@ add_linux_if(pcap_if_list_t *devlistp, const char *ifname, int fd, char *errbuf)
* next field.
*/
saveq = q;
- while (isascii(*p) && isdigit(*p))
+ while (PCAP_ISDIGIT(*p))
*q++ = *p++;
if (*p != ':') {
/*
@@ -2769,7 +2768,7 @@ scan_proc_net_dev(pcap_if_list_t *devlistp, char *errbuf)
/*
* Skip leading white space.
*/
- while (*p != '\0' && isascii(*p) && isspace(*p))
+ while (*p != '\0' && PCAP_ISSPACE(*p))
p++;
if (*p == '\0' || *p == '\n')
continue; /* blank line */
diff --git a/pcap-netmap.c b/pcap-netmap.c
index 44ac6b56..3613a756 100644
--- a/pcap-netmap.c
+++ b/pcap-netmap.c
@@ -29,7 +29,6 @@
#endif
#include <poll.h>
-#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
diff --git a/pcap-nit.c b/pcap-nit.c
index 348805d1..b73eaad7 100644
--- a/pcap-nit.c
+++ b/pcap-nit.c
@@ -43,7 +43,6 @@
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
-#include <ctype.h>
#include <errno.h>
#include <stdio.h>
diff --git a/pcap-pf.c b/pcap-pf.c
index db6a8cad..c50507b9 100644
--- a/pcap-pf.c
+++ b/pcap-pf.c
@@ -48,7 +48,6 @@ struct rtentry;
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
-#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
diff --git a/pcap-septel.c b/pcap-septel.c
index ee42e05f..c59dbc19 100644
--- a/pcap-septel.c
+++ b/pcap-septel.c
@@ -17,7 +17,6 @@
#include "pcap-int.h"
-#include <ctype.h>
#include <netinet/in.h>
#include <sys/mman.h>
#include <sys/socket.h>
diff --git a/pcap-snf.c b/pcap-snf.c
index dd28fa9a..6bf504ea 100644
--- a/pcap-snf.c
+++ b/pcap-snf.c
@@ -10,7 +10,6 @@
#include <string.h>
#include <errno.h>
-#include <ctype.h>
#ifndef _WIN32
#include <netinet/in.h>
#include <sys/mman.h>
diff --git a/pcap-snit.c b/pcap-snit.c
index 77cb07f9..6f063c9b 100644
--- a/pcap-snit.c
+++ b/pcap-snit.c
@@ -53,7 +53,6 @@
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
-#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
diff --git a/pcap-usb-linux.c b/pcap-usb-linux.c
index e6cb9d91..bbadded8 100644
--- a/pcap-usb-linux.c
+++ b/pcap-usb-linux.c
@@ -45,7 +45,6 @@
#include "strerror.h"
#endif
-#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
@@ -363,9 +362,9 @@ usb_findalldevs(pcap_if_list_t *devlistp, char *err_str)
len = strlen(name);
/* if this file name does not end with a number it's not of our interest */
- if ((len < 1) || !isdigit(name[--len]))
+ if ((len < 1) || !PCAP_ISDIGIT(name[--len]))
continue;
- while (isdigit(name[--len]));
+ while (PCAP_ISDIGIT(name[--len]));
if (sscanf(&name[len+1], "%d", &n) != 1)
continue;
diff --git a/pcap.c b/pcap.c
index 18a056c0..1cc8206c 100644
--- a/pcap.c
+++ b/pcap.c
@@ -53,7 +53,6 @@ struct rtentry; /* declarations in <net/if.h> */
#include <netinet/in.h>
#endif /* _WIN32 */
-#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -881,7 +880,7 @@ find_or_add_if(pcap_if_list_t *devlistp, const char *name,
* see if it looks like a loopback device.
*/
if (name[0] == 'l' && name[1] == 'o' &&
- (isdigit((unsigned char)(name[2])) || name[2] == '\0')
+ (PCAP_ISDIGIT(name[2]) || name[2] == '\0')
pcap_flags |= PCAP_IF_LOOPBACK;
#endif
#ifdef IFF_UP
diff --git a/portability.h b/portability.h
index 39e1583b..d606368d 100644
--- a/portability.h
+++ b/portability.h
@@ -83,8 +83,6 @@ extern "C" {
#endif
#ifdef _MSC_VER
- #define isascii __isascii
-
/*
* If <crtdbg.h> has been included, and _DEBUG is defined, and
* __STDC__ is zero, <crtdbg.h> will define strdup() to call