]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Don't use <ctype.h> macros.
authorGuy Harris <[email protected]>
Sun, 1 Sep 2019 23:11:32 +0000 (16:11 -0700)
committerGuy Harris <[email protected]>
Sun, 1 Sep 2019 23:11:32 +0000 (16:11 -0700)
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.

16 files changed:
Makefile.in
netdissect-ctype.h [new file with mode: 0644]
netdissect-stdinc.h
netdissect.h
parsenfsfh.c
print-ascii.c
print-esp.c
print-isakmp.c
print-pppoe.c
print-radius.c
print-snmp.c
print-ssh.c
print-zephyr.c
smbutil.c
strtoaddr.c
util-print.c

index a7aa17645d0cd277b650f6610a75972c25f03c67..be4043e6e2820f8c2f06343fca8caafdfede34ce 100644 (file)
@@ -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 (file)
index 0000000..ae4a3ce
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 1988-1997
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Copyright (c) 1998-2012  Michael Richardson <[email protected]>
+ *      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 */
+
index 567fb8ef31a3e81f0209a9e5d5efb36108c0a54e..2c16be39e141620a14c1055d12d210fe5f7e2c65 100644 (file)
 #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>
index 095cbfa1f2ed67a5c04f40861d79ef8b4e2675ce..64140162818adb23a7d99a1d5680f717a914a434 100644 (file)
@@ -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__))) || \
index b3f54900cc0527424fa86da47512a3f1bdd14c46..cd9436992d7762156439b99578cc85e663cd1e66 100644 (file)
@@ -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
index 56efc84af18c22873d946ae8e5162c0b9d6be3c3..237cf636caa21bc9f33b9c81948f860bbef19a38 100644 (file)
 #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) {
index 9d8906e5a87340c29c1635c2323f4b15b1c25c0f..4a00e0e41d95e38953595bbe6cdd0a89f0fdb6d0 100644 (file)
@@ -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)) {
index b7b05116d08ce304936349e6def529ce4869cff1..34b216dff3849faf641248188caa7283c4abccd6 100644 (file)
@@ -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(".");
        }
index e3d6e22287b2672b7cd4d863f9407a70d98c18ab..28b80fc831fad29635dba8b893ea186f75bc3176 100644 (file)
@@ -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 {
index 5136eef1504b5d024f6dbd548f7d1d9a2c6a312f..ebecfbd0a05cf47ecb2a56495de8dbc6a5645d34 100644 (file)
@@ -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;
index 6058294b59759138f1fe0075eedb082f956d13c2..03e5c3b415ab63770c6883f61b32734c4edaf650 100644 (file)
@@ -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("\"");
index bb983355a29228842a90e435b2873b027d4bcb3b..a6c66d74507a74512f71c235e9add3a985c85a9c 100644 (file)
@@ -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.
index 76351bd3b68ec19de639b10d5498a3ce91f68c99..b0f8cd31388a4480dfc64d30ccf0d679bc04185f 100644 (file)
@@ -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++;
     }
 
index 63a36860ded0e011a0dcfdc701e0b7a7dc435a52..92c3f42aeeea1ca77d451ec8baf99e030f83aee8 100644 (file)
--- 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;
          }
index e38a9d4ebd719c322878a147c334a3e520029e19..b3b84972efce2aeb463a7cf7bdb17409f87b7292 100644 (file)
@@ -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.
index c60cc93b263165609256473d947fa539ee42fcd8..8806b47599c0c2723cbbbcfaead54ce262074cda 100644 (file)
 #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;
                                }