extern char *copy_argv(netdissect_options *, char **);
#endif
+/*
+ * Locale-independent macros for testing character properties and
+ * stripping the 8th bit from characters. 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)
+
extern void safeputchar(int);
extern void safeputs(const char *, int);
int seen_null = 0;
for (i = 1; i < 14; i++) {
- if (isprint(fhp[i])) {
+ if (ND_ISPRINT(fhp[i])) {
if (seen_null)
return(0);
else
while (length > 0) {
s = *cp++;
length--;
- if (!isgraph(s) &&
+ if (!ND_ISGRAPH(s) &&
(s != '\t' && s != ' ' && s != '\n' && s != '\r'))
putchar('.');
else
(void)snprintf(hsp, sizeof(hexstuff) - (hsp - hexstuff),
" %02x%02x", s1, s2);
hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
- *(asp++) = (isgraph(s1) ? s1 : '.');
- *(asp++) = (isgraph(s2) ? s2 : '.');
+ *(asp++) = (ND_ISGRAPH(s1) ? s1 : '.');
+ *(asp++) = (ND_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++) = (isgraph(s1) ? s1 : '.');
+ *(asp++) = (ND_ISGRAPH(s1) ? s1 : '.');
++i;
}
if (i > 0) {
if(dumpascii) {
ND_TCHECK2(*typedata, idtype_len);
for(i=0; i<idtype_len; i++) {
- if(isprint(typedata[i])) {
+ if(ND_ISPRINT(typedata[i])) {
ND_PRINT((ndo, "%c", typedata[i]));
} else {
ND_PRINT((ndo, "."));
len = ntohs(e.len) - 4;
ND_TCHECK2(*vid, len);
for(i=0; i<len; i++) {
- if(isprint(vid[i])) ND_PRINT((ndo, "%c", vid[i]));
+ if(ND_ISPRINT(vid[i])) ND_PRINT((ndo, "%c", vid[i]));
else ND_PRINT((ndo, "."));
}
if (2 < ndo->ndo_vflag && 4 < len) {
flag = 0;
break;
}
- if (!isascii(c)) {
- c = toascii(c);
+ if (!ND_ISASCII(c)) {
+ c = ND_TOASCII(c);
putchar('M');
putchar('-');
}
- if (!isprint(c)) {
+ if (!ND_ISPRINT(c)) {
c ^= 0x40; /* DEL to ?, others to alpha */
putchar('^');
}
u_int i = 0;
printf("\n\t Simple Text Authentication data: ");
for (; i < RIP_AUTHLEN; p++, i++)
- putchar (isprint(*p) ? *p : '.');
+ putchar (ND_ISPRINT(*p) ? *p : '.');
} else if (auth_type == 3) {
printf("\n\t Auth header:");
printf(" Packet Len %u,", EXTRACT_16BITS((u_int8_t *)ni + 4));
const u_char *p = elem->data.str;
TCHECK2(*p, asnlen);
for (i = asnlen; printable && i-- > 0; p++)
- printable = isprint(*p) || isspace(*p);
+ printable = ND_ISPRINT(*p);
p = elem->data.str;
if (printable) {
putchar('"');
}
}
-/* convert a UCS2 string into iso-8859-1 string */
+/* convert a UCS-2 string into an ASCII string */
#define MAX_UNISTR_SIZE 1000
static const char *
unistr(const u_char *s, u_int32_t *len, int use_unicode)
TCHECK(s[0]);
if (l >= MAX_UNISTR_SIZE)
break;
- if (isprint(s[0]))
+ if (ND_ISPRINT(s[0]))
buf[l] = s[0];
else {
if (s[0] == 0)
TCHECK2(s[0], 2);
if (l >= MAX_UNISTR_SIZE)
break;
- if (s[1] == 0 && isprint(s[0])) {
+ if (s[1] == 0 && ND_ISPRINT(s[0])) {
/* It's a printable ASCII character */
buf[l] = s[0];
} else {
#endif
#if !defined(__MINGW32__) && !defined(__WATCOMC__)
-#undef toascii
-#define isascii __isascii
-#define toascii __toascii
#define stat _stat
#define open _open
#define fstat _fstat
#define INET6_ADDRSTRLEN 46
#endif
-#ifndef toascii
-#define toascii(c) ((c) & 0x7f)
-#endif
-
#ifndef caddr_t
typedef char* caddr_t;
#endif /* caddr_t */
ret = 0;
break;
}
- if (!isascii(c)) {
- c = toascii(c);
+ if (!ND_ISASCII(c)) {
+ c = ND_TOASCII(c);
putchar('M');
putchar('-');
}
- if (!isprint(c)) {
+ if (!ND_ISPRINT(c)) {
c ^= 0x40; /* DEL to ?, others to alpha */
putchar('^');
}
while (n > 0 && (ep == NULL || s < ep)) {
n--;
c = *s++;
- if (!isascii(c)) {
- c = toascii(c);
+ if (!ND_ISASCII(c)) {
+ c = ND_TOASCII(c);
putchar('M');
putchar('-');
}
- if (!isprint(c)) {
+ if (!ND_ISPRINT(c)) {
c ^= 0x40; /* DEL to ?, others to alpha */
putchar('^');
}
ret = 0;
break;
}
- if (!isascii(c)) {
- c = toascii(c);
+ if (!ND_ISASCII(c)) {
+ c = ND_TOASCII(c);
putchar('M');
putchar('-');
}
- if (!isprint(c)) {
+ if (!ND_ISPRINT(c)) {
c ^= 0x40; /* DEL to ?, others to alpha */
putchar('^');
}
unsigned char ch;
ch = (unsigned char)(c & 0xff);
- if (ch < 0x80 && isprint(ch))
+ if (ch < 0x80 && ND_ISPRINT(ch))
printf("%c", ch);
else
printf("\\0x%02x", ch);