nameser.h \
netdissect.h \
netdissect-alloc.h \
+ netdissect-ctype.h \
netdissect-stdinc.h \
nfs.h \
nfsfh.h \
--- /dev/null
+/*
+ * Copyright (c) 1988-1997
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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 */
+
#include <stdio.h>
#include <winsock2.h>
#include <ws2tcpip.h>
-#include <ctype.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
* Includes and definitions for various flavors of UN*X.
*/
-#include <ctype.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/param.h>
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__))) || \
#include <stdio.h>
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
#include "nfsfh.h"
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
#endif
#include "netdissect-stdinc.h"
+
#include <stdio.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
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
(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';
(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) {
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)) {
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
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(".");
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(".");
}
#include "netdissect-stdinc.h"
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
/* 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 {
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "addrtoname.h"
#include "extract.h"
}
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;
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;
#include <smi.h>
#endif
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
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("\"");
#include <stdio.h>
#include <stdlib.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
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 */
* 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.
#include <string.h>
#include <stdlib.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
struct z_packet {
zb_string = z_buf;
while (*zb_string) {
- *zb_string = ND_TOLOWER((unsigned char)(*zb_string));
+ *zb_string = ND_ASCII_TOLOWER(*zb_string);
zb_string++;
}
#include <stdlib.h>
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "netdissect.h"
#include "extract.h"
#include "smb.h"
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 {
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 {
ND_TCHECK_LEN(buf, l);
buf += l;
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
ND_PRINT("%-*.*s", l, l, buf);
buf += l;
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
ND_PRINT("%-*.*s", (int)stringlen, (int)stringlen, buf);
buf += stringlen;
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
buf++;
}
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
break;
}
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
tstring = "NULL\n";
ND_PRINT("%s", tstring);
fmt++;
- while (isdigit((unsigned char)*fmt))
+ while (ND_ASCII_ISDIGIT(*fmt))
fmt++;
break;
}
#include <stddef.h>
#include <string.h>
+#include "netdissect-ctype.h"
+
#include "strtoaddr.h"
#ifndef NS_INADDRSZ
* 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;
/*
* Check for trailing characters.
*/
- if (c != '\0' && !isspace(c))
+ if (c != '\0' && c != ' ' && c != '\t')
return (0);
/*
* Find the number of parts specified.
#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"
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("^");
}
{
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 */
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);
}
/* no room for this character and terminating '\0' */
return (0);
}
- tbuf[toklen] = GET_U_1(pptr + idx);
+ tbuf[toklen] = c;
toklen++;
}
if (toklen == 0) {
/* 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;
}
{
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
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 */
* 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
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;
}