Module Name: src
Committed By: jakllsch
Date: Wed May 19 18:58:22 UTC 2010
Modified Files:
src/sys/net: if_ether.h if_ethersubr.c
Log Message:
Changes to ether_nonstatic_aton():
Be more leinent on input string format. Each nibble pair may optionally be
followed by any of ':', '-', '.' or ' '.
Make source string const and work on a temporary copy. The caller may not
expect their string to be destroyed.
To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/net/if_ether.h
cvs rdiff -u -r1.178 -r1.179 src/sys/net/if_ethersubr.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/if_ether.h
diff -u src/sys/net/if_ether.h:1.56 src/sys/net/if_ether.h:1.57
--- src/sys/net/if_ether.h:1.56 Wed Mar 18 15:14:31 2009
+++ src/sys/net/if_ether.h Wed May 19 18:58:22 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ether.h,v 1.56 2009/03/18 15:14:31 cegger Exp $ */
+/* $NetBSD: if_ether.h,v 1.57 2010/05/19 18:58:22 jakllsch Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@@ -310,7 +310,7 @@
uint32_t ether_crc32_le(const uint8_t *, size_t);
uint32_t ether_crc32_be(const uint8_t *, size_t);
-int ether_nonstatic_aton(u_char *, char *);
+int ether_nonstatic_aton(u_char *, const char *);
#else
/*
* Prototype ethers(3) functions.
Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.178 src/sys/net/if_ethersubr.c:1.179
--- src/sys/net/if_ethersubr.c:1.178 Wed May 5 18:12:24 2010
+++ src/sys/net/if_ethersubr.c Wed May 19 18:58:22 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ethersubr.c,v 1.178 2010/05/05 18:12:24 dyoung Exp $ */
+/* $NetBSD: if_ethersubr.c,v 1.179 2010/05/19 18:58:22 jakllsch Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.178 2010/05/05 18:12:24 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.179 2010/05/19 18:58:22 jakllsch Exp $");
#include "opt_inet.h"
#include "opt_atalk.h"
@@ -1224,38 +1224,47 @@
* ether_aton implementation, not using a static buffer.
*/
int
-ether_nonstatic_aton(u_char *dest, char *str)
+ether_nonstatic_aton(u_char *dest, const char *src)
{
- int i;
- char *cp = str;
- u_char val[6];
-
-#define set_value \
- if (*cp > '9' && *cp < 'a') \
- *cp -= 'A' - 10; \
- else if (*cp > '9') \
- *cp -= 'a' - 10; \
- else \
- *cp -= '0'
-
- for (i = 0; i < 6; i++, cp++) {
- if (!isxdigit(*cp))
- return (1);
- set_value;
- val[i] = *cp++;
- if (isxdigit(*cp)) {
- set_value;
- val[i] *= 16;
- val[i] += *cp++;
- }
- if (*cp == ':' || i == 5)
- continue;
- else
- return 1;
- }
- memcpy(dest, val, 6);
+ int i;
+ char str[3 * ETHER_ADDR_LEN + 2];
+ u_char val[ETHER_ADDR_LEN];
+ char *cp;
+
+#define set_value \
+ if (*cp > '9' && *cp < 'a') \
+ *cp -= 'A' - 10; \
+ else if (*cp > '9') \
+ *cp -= 'a' - 10; \
+ else \
+ *cp -= '0'
+
+ strlcpy(str, src, sizeof(str));
+
+ cp = str;
+
+ for (i = 0; i < ETHER_ADDR_LEN; i++) {
+ if (!isxdigit(*cp))
+ return 1;
+ set_value;
+ val[i] = *cp++;
+ if (isxdigit(*cp)) {
+ set_value;
+ val[i] <<= 4;
+ val[i] += *cp++;
+ }
+ if (*cp == ':' || *cp == '-' || *cp == '.' || *cp == ' ') {
+ cp++;
+ continue;
+ }
+ if (isxdigit(*cp) || i == (ETHER_ADDR_LEN - 1))
+ continue;
+ return 1;
+ }
+ memcpy(dest, val, ETHER_ADDR_LEN);
- return 0;
+ return 0;
+#undef set_value
}