summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-09-01 16:11:32 -0700
committerGuy Harris <guy@alum.mit.edu>2019-09-01 16:11:32 -0700
commit9a6a6502413e657277e74ac1d0842ddca34cab50 (patch)
tree09d3a2d474389be1d655f92a19263b713dd8677e
parent50c1904960bec90e234100a7c1b081d771c48e9b (diff)
downloadtcpdump-9a6a6502413e657277e74ac1d0842ddca34cab50.tar.gz
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. Move our replacements to a new netdissect-ctype.h file, and, for the ones that check for particular character types, add _ASCII to the name, to indicate that only ASCII characters pass the check. Do the same for the ones that map between cases, to indicate that they only map ASCII letters. For isspace(), explicitly check for the characters we care about, to make it clearer what we're doing.
-rw-r--r--Makefile.in1
-rw-r--r--netdissect-ctype.h56
-rw-r--r--netdissect-stdinc.h2
-rw-r--r--netdissect.h29
-rw-r--r--parsenfsfh.c4
-rw-r--r--print-ascii.c11
-rw-r--r--print-esp.c2
-rw-r--r--print-isakmp.c6
-rw-r--r--print-pppoe.c4
-rw-r--r--print-radius.c6
-rw-r--r--print-snmp.c4
-rw-r--r--print-ssh.c12
-rw-r--r--print-zephyr.c4
-rw-r--r--smbutil.c18
-rw-r--r--strtoaddr.c10
-rw-r--r--util-print.c38
16 files changed, 130 insertions, 77 deletions
diff --git a/Makefile.in b/Makefile.in
index a7aa1764..be4043e6 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -284,6 +284,7 @@ HDR = \
nameser.h \
netdissect.h \
netdissect-alloc.h \
+ netdissect-ctype.h \
netdissect-stdinc.h \
nfs.h \
nfsfh.h \
diff --git a/netdissect-ctype.h b/netdissect-ctype.h
new file mode 100644
index 00000000..ae4a3ce0
--- /dev/null
+++ b/netdissect-ctype.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 1988-1997
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Copyright (c) 1998-2012 Michael Richardson <mcr@tcpdump.org>
+ * The TCPDUMP project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef netdissect_ctype_h
+#define netdissect_ctype_h
+
+/*
+ * Locale-independent macros for testing character properties and
+ * stripping the 8th bit from characters.
+ *
+ * Byte values outside the ASCII range are considered unprintable, so
+ * both ND_ASCII_ISPRINT() and ND_ASCII_ISGRAPH() return "false" for them.
+ *
+ * Assumed to be handed a value between 0 and 255, i.e. don't hand them
+ * a char, as those might be in the range -128 to 127.
+ */
+#define ND_ISASCII(c) (!((c) & 0x80)) /* value is an ASCII code point */
+#define ND_ASCII_ISPRINT(c) ((c) >= 0x20 && (c) <= 0x7E)
+#define ND_ASCII_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E)
+#define ND_ASCII_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
+#define ND_TOASCII(c) ((c) & 0x7F)
+
+/*
+ * Locale-independent macros for coverting to upper or lower case.
+ *
+ * Byte values outside the ASCII range are not converted. Byte values
+ * *in* the ASCII range are converted to byte values in the ASCII range;
+ * in particular, 'i' is upper-cased to 'I" and 'I' is lower-cased to 'i',
+ * even in Turkish locales.
+ */
+#define ND_ASCII_TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
+#define ND_ASCII_TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'A' : (c))
+
+#endif /* netdissect-ctype.h */
+
diff --git a/netdissect-stdinc.h b/netdissect-stdinc.h
index 567fb8ef..2c16be39 100644
--- a/netdissect-stdinc.h
+++ b/netdissect-stdinc.h
@@ -124,7 +124,6 @@
#include <stdio.h>
#include <winsock2.h>
#include <ws2tcpip.h>
-#include <ctype.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
@@ -222,7 +221,6 @@ typedef char* caddr_t;
* Includes and definitions for various flavors of UN*X.
*/
-#include <ctype.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/param.h>
diff --git a/netdissect.h b/netdissect.h
index 095cbfa1..64140162 100644
--- a/netdissect.h
+++ b/netdissect.h
@@ -395,35 +395,6 @@ extern int nd_printzp(netdissect_options *, const u_char *, u_int, const u_char
extern void txtproto_print(netdissect_options *, const u_char *, u_int,
const char **, u_int);
-/*
- * Locale-independent macros for testing character properties and
- * stripping the 8th bit from characters.
- *
- * Byte values outside the ASCII range are considered unprintable, so
- * both ND_ISPRINT() and ND_ISGRAPH() return "false" for them.
- *
- * Assumed to be handed a value between 0 and 255, i.e. don't hand them
- * a char, as those might be in the range -128 to 127.
- */
-#define ND_ISASCII(c) (!((c) & 0x80)) /* value is an ASCII code point */
-#define ND_ISPRINT(c) ((c) >= 0x20 && (c) <= 0x7E)
-#define ND_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E)
-#define ND_TOASCII(c) ((c) & 0x7F)
-
-/*
- * Locale-independent macros for coverting to upper or lower case.
- *
- * Byte values outside the ASCII range are not converted. Byte values
- * *in* the ASCII range are converted to byte values in the ASCII range;
- * in particular, 'i' is upper-cased to 'I" and 'I' is lower-cased to 'i',
- * even in Turkish locales.
- *
- * Assumed to be handed a value between 0 and 255, i.e. don't hand
- * them a char, as those might be in the range -128 to 127.
- */
-#define ND_TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
-#define ND_TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'A' : (c))
-
#if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \
(defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \
(defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \
diff --git a/parsenfsfh.c b/parsenfsfh.c
index b3f54900..cd943699 100644
--- a/parsenfsfh.c
+++ b/parsenfsfh.c
@@ -49,6 +49,8 @@
#include <stdio.h>
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
#include "nfsfh.h"
@@ -442,7 +444,7 @@ is_UCX(netdissect_options *ndo, const unsigned char *fhp, u_int len)
return(0);
for (i = 1; i < 14; i++) {
- if (ND_ISPRINT(GET_U_1(fhp + i))) {
+ if (ND_ASCII_ISPRINT(GET_U_1(fhp + i))) {
if (seen_null)
return(0);
else
diff --git a/print-ascii.c b/print-ascii.c
index 56efc84a..237cf636 100644
--- a/print-ascii.c
+++ b/print-ascii.c
@@ -43,8 +43,11 @@
#endif
#include "netdissect-stdinc.h"
+
#include <stdio.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
@@ -86,7 +89,7 @@ ascii_print(netdissect_options *ndo,
if (length > 1 && GET_U_1(cp) != '\n')
ND_PRINT(".");
} else {
- if (!ND_ISGRAPH(s) &&
+ if (!ND_ASCII_ISGRAPH(s) &&
(s != '\t' && s != ' ' && s != '\n'))
ND_PRINT(".");
else
@@ -120,8 +123,8 @@ hex_and_ascii_print_with_offset(netdissect_options *ndo, const char *ident,
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
" %02x%02x", s1, s2);
hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
- *(asp++) = (char)(ND_ISGRAPH(s1) ? s1 : '.');
- *(asp++) = (char)(ND_ISGRAPH(s2) ? s2 : '.');
+ *(asp++) = (char)(ND_ASCII_ISGRAPH(s1) ? s1 : '.');
+ *(asp++) = (char)(ND_ASCII_ISGRAPH(s2) ? s2 : '.');
i++;
if (i >= HEXDUMP_SHORTS_PER_LINE) {
*hsp = *asp = '\0';
@@ -139,7 +142,7 @@ hex_and_ascii_print_with_offset(netdissect_options *ndo, const char *ident,
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
" %02x", s1);
hsp += 3;
- *(asp++) = (char)(ND_ISGRAPH(s1) ? s1 : '.');
+ *(asp++) = (char)(ND_ASCII_ISGRAPH(s1) ? s1 : '.');
++i;
}
if (i > 0) {
diff --git a/print-esp.c b/print-esp.c
index 9d8906e5..4a00e0e4 100644
--- a/print-esp.c
+++ b/print-esp.c
@@ -631,7 +631,7 @@ static void esp_print_decode_onesecret(netdissect_options *ndo, char *line,
if (decode) {
/* skip any blank spaces */
- while (isspace((unsigned char)*decode))
+ while (*decode == ' ' || *decode == '\t' || *decode == '\r' || *decode == '\n')
decode++;
if(!espprint_decode_encalgo(ndo, decode, &sa1)) {
diff --git a/print-isakmp.c b/print-isakmp.c
index b7b05116..34b216df 100644
--- a/print-isakmp.c
+++ b/print-isakmp.c
@@ -47,6 +47,8 @@
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
@@ -2267,7 +2269,7 @@ ikev2_ID_print(netdissect_options *ndo, u_char tpay,
if(dumpascii) {
ND_TCHECK_LEN(typedata, idtype_len);
for(i=0; i<idtype_len; i++) {
- if(ND_ISPRINT(GET_U_1(typedata + i))) {
+ if(ND_ASCII_ISPRINT(GET_U_1(typedata + i))) {
ND_PRINT("%c", GET_U_1(typedata + i));
} else {
ND_PRINT(".");
@@ -2610,7 +2612,7 @@ ikev2_vid_print(netdissect_options *ndo, u_char tpay,
len = item_len - 4;
ND_TCHECK_LEN(vid, len);
for(i=0; i<len; i++) {
- if(ND_ISPRINT(GET_U_1(vid + i)))
+ if(ND_ASCII_ISPRINT(GET_U_1(vid + i)))
ND_PRINT("%c", GET_U_1(vid + i));
else ND_PRINT(".");
}
diff --git a/print-pppoe.c b/print-pppoe.c
index e3d6e222..28b80fc8 100644
--- a/print-pppoe.c
+++ b/print-pppoe.c
@@ -29,6 +29,8 @@
#include "netdissect-stdinc.h"
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
@@ -158,7 +160,7 @@ pppoe_print(netdissect_options *ndo, const u_char *bp, u_int length)
/* TODO print UTF-8 decoded text */
ND_TCHECK_LEN(p, tag_len);
for (v = p; v < p + tag_len && tag_str_len < MAXTAGPRINT-1; v++)
- if (ND_ISPRINT(GET_U_1(v))) {
+ if (ND_ASCII_ISPRINT(GET_U_1(v))) {
tag_str[tag_str_len++] = GET_U_1(v);
ascii_count++;
} else {
diff --git a/print-radius.c b/print-radius.c
index 5136eef1..ebecfbd0 100644
--- a/print-radius.c
+++ b/print-radius.c
@@ -90,6 +90,8 @@
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
@@ -674,7 +676,7 @@ print_attr_string(netdissect_options *ndo,
}
for (i=0; i < length && GET_U_1(data); i++, data++)
- ND_PRINT("%c", ND_ISPRINT(GET_U_1(data)) ? GET_U_1(data) : '.');
+ ND_PRINT("%c", ND_ASCII_ISPRINT(GET_U_1(data)) ? GET_U_1(data) : '.');
return;
@@ -734,7 +736,7 @@ print_vendor_attr(netdissect_options *ndo,
vendor_type,
vendor_length);
for (idx = 0; idx < vendor_length ; idx++, data++)
- ND_PRINT("%c", ND_ISPRINT(GET_U_1(data)) ? GET_U_1(data) : '.');
+ ND_PRINT("%c", ND_ASCII_ISPRINT(GET_U_1(data)) ? GET_U_1(data) : '.');
length-=vendor_length;
}
return;
diff --git a/print-snmp.c b/print-snmp.c
index 6058294b..03e5c3b4 100644
--- a/print-snmp.c
+++ b/print-snmp.c
@@ -71,6 +71,8 @@
#include <smi.h>
#endif
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
@@ -700,7 +702,7 @@ asn1_print_string(netdissect_options *ndo, struct be *elem)
p = elem->data.str;
ND_TCHECK_LEN(p, asnlen);
for (i = asnlen; printable && i != 0; p++, i--)
- printable = ND_ISPRINT(GET_U_1(p));
+ printable = ND_ASCII_ISPRINT(GET_U_1(p));
p = elem->data.str;
if (printable) {
ND_PRINT("\"");
diff --git a/print-ssh.c b/print-ssh.c
index bb983355..a6c66d74 100644
--- a/print-ssh.c
+++ b/print-ssh.c
@@ -22,6 +22,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
@@ -44,14 +46,17 @@ ssh_print_version(netdissect_options *ndo, const u_char *pptr, u_int len)
idx++;
while (idx < len) {
- if (GET_U_1(pptr + idx) == '\n') {
+ u_char c;
+
+ c = GET_U_1(pptr + idx);
+ if (c == '\n') {
/*
* LF without CR; end of line.
* Skip the LF and print the line, with the
* exception of the LF.
*/
goto print;
- } else if (GET_U_1(pptr + idx) == '\r') {
+ } else if (c == '\r') {
/* CR - any LF? */
if ((idx+1) >= len) {
/* not in this packet */
@@ -71,8 +76,7 @@ ssh_print_version(netdissect_options *ndo, const u_char *pptr, u_int len)
* if it were binary data and don't print it.
*/
goto trunc;
- } else if (!isascii(GET_U_1(pptr + idx)) ||
- !isprint(GET_U_1(pptr + idx)) ) {
+ } else if (!ND_ASCII_ISPRINT(c) ) {
/*
* Not a printable ASCII character; treat this
* as if it were binary data and don't print it.
diff --git a/print-zephyr.c b/print-zephyr.c
index 76351bd3..b0f8cd31 100644
--- a/print-zephyr.c
+++ b/print-zephyr.c
@@ -32,6 +32,8 @@
#include <string.h>
#include <stdlib.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
struct z_packet {
@@ -134,7 +136,7 @@ str_to_lower(const char *string)
zb_string = z_buf;
while (*zb_string) {
- *zb_string = ND_TOLOWER((unsigned char)(*zb_string));
+ *zb_string = ND_ASCII_TOLOWER(*zb_string);
zb_string++;
}
diff --git a/smbutil.c b/smbutil.c
index 63a36860..92c3f42a 100644
--- a/smbutil.c
+++ b/smbutil.c
@@ -16,6 +16,8 @@
#include <stdlib.h>
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
#include "smb.h"
@@ -418,7 +420,7 @@ unistr(netdissect_options *ndo, char (*buf)[MAX_UNISTR_SIZE+1],
break;
}
if (l < MAX_UNISTR_SIZE) {
- if (ND_ISPRINT(c)) {
+ if (ND_ASCII_ISPRINT(c)) {
/* It's a printable ASCII character */
(*buf)[l] = c;
} else {
@@ -450,7 +452,7 @@ unistr(netdissect_options *ndo, char (*buf)[MAX_UNISTR_SIZE+1],
break;
}
if (l < MAX_UNISTR_SIZE) {
- if (ND_ISPRINT(c)) {
+ if (ND_ASCII_ISPRINT(c)) {
/* It's a printable ASCII character */
(*buf)[l] = c;
} else {
@@ -526,7 +528,7 @@ smb_fdata1(netdissect_options *ndo,
ND_TCHECK_LEN(buf, l);
buf += l;
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
@@ -716,7 +718,7 @@ smb_fdata1(netdissect_options *ndo,
ND_PRINT("%-*.*s", l, l, buf);
buf += l;
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
@@ -730,7 +732,7 @@ smb_fdata1(netdissect_options *ndo,
ND_PRINT("%-*.*s", (int)stringlen, (int)stringlen, buf);
buf += stringlen;
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
@@ -756,7 +758,7 @@ smb_fdata1(netdissect_options *ndo,
buf++;
}
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
@@ -789,7 +791,7 @@ smb_fdata1(netdissect_options *ndo,
break;
}
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
@@ -838,7 +840,7 @@ smb_fdata1(netdissect_options *ndo,
tstring = "NULL\n";
ND_PRINT("%s", tstring);
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
diff --git a/strtoaddr.c b/strtoaddr.c
index e38a9d4e..b3b84972 100644
--- a/strtoaddr.c
+++ b/strtoaddr.c
@@ -23,6 +23,8 @@
#include <stddef.h>
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "strtoaddr.h"
#ifndef NS_INADDRSZ
@@ -69,18 +71,18 @@ strtoaddr(const char *src, void *dst)
* Values are specified as for C:
* 0x=hex, 0=octal, isdigit=decimal.
*/
- if (!isdigit(c))
+ if (!ND_ASCII_ISDIGIT(c))
return (0);
val = 0;
if (c == '0') {
c = *++src;
if (c == 'x' || c == 'X')
return (0);
- else if (isdigit(c) && c != '9')
+ else if (ND_ASCII_ISDIGIT(c) && c != '9')
return (0);
}
for (;;) {
- if (isdigit(c)) {
+ if (ND_ASCII_ISDIGIT(c)) {
digit = c - '0';
if (digit >= 10)
break;
@@ -107,7 +109,7 @@ strtoaddr(const char *src, void *dst)
/*
* Check for trailing characters.
*/
- if (c != '\0' && !isspace(c))
+ if (c != '\0' && c != ' ' && c != '\t')
return (0);
/*
* Find the number of parts specified.
diff --git a/util-print.c b/util-print.c
index c60cc93b..8806b475 100644
--- a/util-print.c
+++ b/util-print.c
@@ -46,12 +46,13 @@
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#include <ctype.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
#include "ascii_strcasecmp.h"
@@ -72,7 +73,7 @@ fn_print_char(netdissect_options *ndo, u_char c)
c = ND_TOASCII(c);
ND_PRINT("M-");
}
- if (!ND_ISPRINT(c)) {
+ if (!ND_ASCII_ISPRINT(c)) {
c ^= 0x40; /* DEL to ?, others to alpha */
ND_PRINT("^");
}
@@ -456,7 +457,7 @@ void nd_print_protocol_caps(netdissect_options *ndo)
{
const char *p;
for (p = ndo->ndo_protocol; *p != '\0'; p++)
- ND_PRINT("%c", ND_TOUPPER((u_char)*p));
+ ND_PRINT("%c", ND_ASCII_TOUPPER(*p));
}
/* Print the invalid string */
@@ -703,21 +704,23 @@ fetch_token(netdissect_options *ndo, const u_char *pptr, u_int idx, u_int len,
u_char *tbuf, size_t tbuflen)
{
size_t toklen = 0;
+ u_char c;
for (; idx < len; idx++) {
if (!ND_TTEST_1(pptr + idx)) {
/* ran past end of captured data */
return (0);
}
- if (!isascii(GET_U_1(pptr + idx))) {
+ c = GET_U_1(pptr + idx);
+ if (!ND_ISASCII(c)) {
/* not an ASCII character */
return (0);
}
- if (isspace(GET_U_1(pptr + idx))) {
+ if (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
/* end of token */
break;
}
- if (!isprint(GET_U_1(pptr + idx))) {
+ if (!ND_ASCII_ISPRINT(c)) {
/* not part of a command token or response code */
return (0);
}
@@ -725,7 +728,7 @@ fetch_token(netdissect_options *ndo, const u_char *pptr, u_int idx, u_int len,
/* no room for this character and terminating '\0' */
return (0);
}
- tbuf[toklen] = GET_U_1(pptr + idx);
+ tbuf[toklen] = c;
toklen++;
}
if (toklen == 0) {
@@ -743,15 +746,16 @@ fetch_token(netdissect_options *ndo, const u_char *pptr, u_int idx, u_int len,
/* ran past end of captured data */
break;
}
- if (GET_U_1(pptr + idx) == '\r' || GET_U_1(pptr + idx) == '\n') {
+ c = GET_U_1(pptr + idx);
+ if (c == '\r' || c == '\n') {
/* end of line */
break;
}
- if (!isascii(GET_U_1(pptr + idx)) || !isprint(GET_U_1(pptr + idx))) {
+ if (!ND_ASCII_ISPRINT(c)) {
/* not a printable ASCII character */
break;
}
- if (!isspace(GET_U_1(pptr + idx))) {
+ if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
/* beginning of next token */
break;
}
@@ -771,11 +775,13 @@ print_txt_line(netdissect_options *ndo, const char *prefix,
{
u_int startidx;
u_int linelen;
+ u_char c;
startidx = idx;
while (idx < len) {
ND_TCHECK_1(pptr + idx);
- if (GET_U_1(pptr + idx) == '\n') {
+ c = GET_U_1(pptr + idx);
+ if (c == '\n') {
/*
* LF without CR; end of line.
* Skip the LF and print the line, with the
@@ -784,7 +790,7 @@ print_txt_line(netdissect_options *ndo, const char *prefix,
linelen = idx - startidx;
idx++;
goto print;
- } else if (GET_U_1(pptr + idx) == '\r') {
+ } else if (c == '\r') {
/* CR - any LF? */
if ((idx+1) >= len) {
/* not in this packet */
@@ -808,9 +814,7 @@ print_txt_line(netdissect_options *ndo, const char *prefix,
* it.
*/
return (0);
- } else if (!isascii(GET_U_1(pptr + idx)) ||
- (!isprint(GET_U_1(pptr + idx)) &&
- GET_U_1(pptr + idx) != '\t')) {
+ } else if (!ND_ASCII_ISPRINT(c) && c != '\t') {
/*
* Not a printable ASCII character and not a tab;
* treat this as if it were binary data, and
@@ -884,8 +888,8 @@ txtproto_print(netdissect_options *ndo, const u_char *pptr, u_int len,
sizeof(token));
}
if (idx != 0) {
- if (isdigit(token[0]) && isdigit(token[1]) &&
- isdigit(token[2]) && token[3] == '\0') {
+ if (ND_ASCII_ISDIGIT(token[0]) && ND_ASCII_ISDIGIT(token[1]) &&
+ ND_ASCII_ISDIGIT(token[2]) && token[3] == '\0') {
/* Yes. */
print_this = 1;
}