]> The Tcpdump Group git mirrors - libpcap/blobdiff - etherent.c
Update config.{guess,sub}, timestamps 2023-01-01,2023-01-21
[libpcap] / etherent.c
index 5930eae28e4a3618d1db5fd51638f36f8ca0a4c4..69da9a540ad8d088b304b8432fc55c3d86b9012e 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <pcap-types.h>
 
-#include <ctype.h>
 #include <memory.h>
 #include <stdio.h>
 #include <string.h>
@@ -45,14 +44,18 @@ static inline int skip_line(FILE *);
 static inline u_char
 xdtoi(u_char c)
 {
-       if (isdigit(c))
+       if (c >= '0' && c <= '9')
                return (u_char)(c - '0');
-       else if (islower(c))
+       else if (c >= 'a' && c <= 'f')
                return (u_char)(c - 'a' + 10);
        else
                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(FILE *f)
 {
@@ -60,7 +63,7 @@ skip_space(FILE *f)
 
        do {
                c = getc(f);
-       } while (isspace(c) && c != '\n');
+       } while (c == ' ' || c == '\t' || c == '\r');
 
        return c;
 }
@@ -97,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);
@@ -106,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);
@@ -126,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);
@@ -152,11 +155,12 @@ pcap_next_etherent(FILE *fp)
                /* 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) && --namesize != 0);
+               } while (c != ' ' && c != '\t' && c != '\r' && c != '\n'
+                   && --namesize != 0);
                *bp = '\0';
 
                /* Eat trailing junk */