X-Git-Url: https://git.tcpdump.org/libpcap/blobdiff_plain/4f96b10e6795b8837ca90ed8ef67cfd82009cdd9..09b51d326c38ea8e10ce4da09c09d50e08c5aeb8:/etherent.c diff --git a/etherent.c b/etherent.c index 0f0ef0ae..69da9a54 100644 --- a/etherent.c +++ b/etherent.c @@ -23,21 +23,8 @@ #include #endif -#ifdef _WIN32 -#include -#else /* _WIN32 */ -#if HAVE_INTTYPES_H -#include -#elif HAVE_STDINT_H -#include -#endif -#ifdef HAVE_SYS_BITYPES_H -#include -#endif -#include -#endif /* _WIN32 */ +#include -#include #include #include #include @@ -50,39 +37,39 @@ #include "os-proto.h" #endif -static inline int xdtoi(int); static inline int skip_space(FILE *); static inline int skip_line(FILE *); /* Hex digit to integer. */ -static inline int -xdtoi(c) - register int c; +static inline u_char +xdtoi(u_char c) { - if (isdigit(c)) - return c - '0'; - else if (islower(c)) - return c - 'a' + 10; + if (c >= '0' && c <= '9') + return (u_char)(c - '0'); + else if (c >= 'a' && c <= 'f') + return (u_char)(c - 'a' + 10); else - return c - 'A' + 10; + return (u_char)(c - 'A' + 10); } +/* + * Skip linear white space (space and tab) and any CRs before LF. + * Stop when we hit a non-white-space character or an end-of-line LF. + */ static inline int -skip_space(f) - FILE *f; +skip_space(FILE *f) { int c; do { c = getc(f); - } while (isspace(c) && c != '\n'); + } while (c == ' ' || c == '\t' || c == '\r'); return c; } static inline int -skip_line(f) - FILE *f; +skip_line(FILE *f) { int c; @@ -96,8 +83,10 @@ skip_line(f) struct pcap_etherent * pcap_next_etherent(FILE *fp) { - register int c, d, i; + register int c, i; + u_char d; char *bp; + size_t namesize; static struct pcap_etherent e; memset((char *)&e, 0, sizeof(e)); @@ -111,7 +100,7 @@ pcap_next_etherent(FILE *fp) /* If this is a comment, or first thing on line cannot be Ethernet address, skip the line. */ - if (!isxdigit(c)) { + if (!PCAP_ISXDIGIT(c)) { c = skip_line(fp); if (c == EOF) return (NULL); @@ -120,13 +109,13 @@ pcap_next_etherent(FILE *fp) /* must be the start of an address */ for (i = 0; i < 6; i += 1) { - d = xdtoi(c); + d = xdtoi((u_char)c); c = getc(fp); if (c == EOF) return (NULL); - if (isxdigit(c)) { + if (PCAP_ISXDIGIT(c)) { d <<= 4; - d |= xdtoi(c); + d |= xdtoi((u_char)c); c = getc(fp); if (c == EOF) return (NULL); @@ -140,7 +129,7 @@ pcap_next_etherent(FILE *fp) } /* Must be whitespace */ - if (!isspace(c)) { + if (c != ' ' && c != '\t' && c != '\r' && c != '\n') { c = skip_line(fp); if (c == EOF) return (NULL); @@ -163,14 +152,15 @@ pcap_next_etherent(FILE *fp) /* pick up name */ bp = e.name; - /* Use 'd' to prevent buffer overflow. */ - d = sizeof(e.name) - 1; + /* Use 'namesize' to prevent buffer overflow. */ + namesize = sizeof(e.name) - 1; do { - *bp++ = c; + *bp++ = (u_char)c; c = getc(fp); if (c == EOF) return (NULL); - } while (!isspace(c) && --d > 0); + } while (c != ' ' && c != '\t' && c != '\r' && c != '\n' + && --namesize != 0); *bp = '\0'; /* Eat trailing junk */