aboutsummaryrefslogtreecommitdiff
path: root/pcap-int.h
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-08-31 17:54:51 -0700
committerGuy Harris <guy@alum.mit.edu>2019-08-31 17:54:51 -0700
commit5a418352f3a1ca4f049396d7892d6e74f4011197 (patch)
tree4e2cfcbd3b442002b2d5d7b4524191d977856ebd /pcap-int.h
parent5807299ed17700b838b99c93e644346c5e055914 (diff)
Don't use ctype.h macros.
Some of them are locale-dependent, and all of them run the risk of failing if you hand them a char with the 8th bit set. Define our own locale-independent macros that can be handed any integral value. Don't include <ctype.h>. This should address the issue in GitHub pull request #839, and should also catch any (highly unlikely) cases in which something other than Boring Old Space And Tab and, sometimes, CR and LF are treated as white space. (No, we don't want FF or VT treated as white space.)
Diffstat (limited to 'pcap-int.h')
-rw-r--r--pcap-int.h19
1 files changed, 19 insertions, 0 deletions
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 */