diff options
author | Guy Harris <guy@alum.mit.edu> | 2019-08-31 17:54:51 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-08-31 17:54:51 -0700 |
commit | 5a418352f3a1ca4f049396d7892d6e74f4011197 (patch) | |
tree | 4e2cfcbd3b442002b2d5d7b4524191d977856ebd /pcap-int.h | |
parent | 5807299ed17700b838b99c93e644346c5e055914 (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.h | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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 */ |