Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Changes to ether_nonstatic_aton():
details: https://anonhg.NetBSD.org/src/rev/b0d4ceec58e4
branches: trunk
changeset: 755006:b0d4ceec58e4
user: jakllsch <jakllsch%NetBSD.org@localhost>
date: Wed May 19 18:58:22 2010 +0000
description:
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.
diffstat:
sys/net/if_ether.h | 4 +-
sys/net/if_ethersubr.c | 69 ++++++++++++++++++++++++++++---------------------
2 files changed, 41 insertions(+), 32 deletions(-)
diffs (112 lines):
diff -r 9b4288eb16ec -r b0d4ceec58e4 sys/net/if_ether.h
--- a/sys/net/if_ether.h Wed May 19 18:01:26 2010 +0000
+++ b/sys/net/if_ether.h Wed May 19 18:58:22 2010 +0000
@@ -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.
diff -r 9b4288eb16ec -r b0d4ceec58e4 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c Wed May 19 18:01:26 2010 +0000
+++ b/sys/net/if_ethersubr.c Wed May 19 18:58:22 2010 +0000
@@ -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];
+ 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'
+#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 < 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);
+ 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
}
Home |
Main Index |
Thread Index |
Old Index