summaryrefslogtreecommitdiff
path: root/usr/src/lib/libsocket/inet/ether_addr.c
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@joyent.com>2015-02-18 19:39:35 -0800
committerRobert Mustacchi <rm@joyent.com>2015-02-20 17:10:02 -0800
commitff3aea39f71c371be25b08deb9efed41f1c95983 (patch)
tree673248b3ee0b0ae34a5fc8ae85ea2a5d5cdefaab /usr/src/lib/libsocket/inet/ether_addr.c
parentbfce16ba853698e8a82133cf3ddb3ff143d14289 (diff)
downloadillumos-joyent-ff3aea39f71c371be25b08deb9efed41f1c95983.tar.gz
5639 want reentrant ether_aton_r and ether_ntoa_r
Reviewed by: Garrett D'Amore <garrett@damore.org> Reviewed by: Richard Lowe <richlowe@richlowe.net> Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com> Approved by: Dan McDonald <danmcd@omniti.com>
Diffstat (limited to 'usr/src/lib/libsocket/inet/ether_addr.c')
-rw-r--r--usr/src/lib/libsocket/inet/ether_addr.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/usr/src/lib/libsocket/inet/ether_addr.c b/usr/src/lib/libsocket/inet/ether_addr.c
index 37105bb302..523e7b472d 100644
--- a/usr/src/lib/libsocket/inet/ether_addr.c
+++ b/usr/src/lib/libsocket/inet/ether_addr.c
@@ -22,6 +22,7 @@
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ * Copyright (c) 2014, Joyent, Inc. All rights reserved.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
@@ -37,8 +38,6 @@
* contributors.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* All routines necessary to deal the "ethers" database. The sources
* contain mappings between 48 bit ethernet addresses and corresponding
@@ -258,38 +257,42 @@ ea_buf(void)
}
/*
- * Converts a 48 bit ethernet number to its string representation.
+ * Converts a 48 bit ethernet number to its string representation using a user
+ * defined buffer.
+ */
+char *
+ether_ntoa_r(const struct ether_addr *e, char *buf)
+{
+ (void) sprintf(buf, "%x:%x:%x:%x:%x:%x",
+ e->ether_addr_octet[0], e->ether_addr_octet[1],
+ e->ether_addr_octet[2], e->ether_addr_octet[3],
+ e->ether_addr_octet[4], e->ether_addr_octet[5]);
+ return (buf);
+}
+
+/*
+ * Converts a 48 bit ethernet number to its string representation using a
+ * per-thread buffer.
*/
char *
ether_ntoa(const struct ether_addr *e)
{
eabuf_t *eabuf;
- char *s;
if ((eabuf = ea_buf()) == NULL)
return (NULL);
- s = eabuf->ea_string;
- (void) sprintf(s, "%x:%x:%x:%x:%x:%x",
- e->ether_addr_octet[0], e->ether_addr_octet[1],
- e->ether_addr_octet[2], e->ether_addr_octet[3],
- e->ether_addr_octet[4], e->ether_addr_octet[5]);
- return (s);
+ return (ether_ntoa_r(e, eabuf->ea_string));
}
/*
- * Converts an ethernet address representation back into its 48 bits.
+ * Converts an ethernet address representation back into its 48 bits using a
+ * user defined buffer.
*/
struct ether_addr *
-ether_aton(const char *s)
+ether_aton_r(const char *s, struct ether_addr *e)
{
- eabuf_t *eabuf;
- struct ether_addr *e;
int i;
uint_t t[6];
-
- if ((eabuf = ea_buf()) == NULL)
- return (NULL);
- e = &eabuf->ea_addr;
i = sscanf(s, " %x:%x:%x:%x:%x:%x",
&t[0], &t[1], &t[2], &t[3], &t[4], &t[5]);
if (i != 6)
@@ -298,3 +301,17 @@ ether_aton(const char *s)
e->ether_addr_octet[i] = (uchar_t)t[i];
return (e);
}
+
+/*
+ * Converts an ethernet address representation back into its 48 bits using a
+ * per-thread buffer.
+ */
+struct ether_addr *
+ether_aton(const char *s)
+{
+ eabuf_t *eabuf;
+
+ if ((eabuf = ea_buf()) == NULL)
+ return (NULL);
+ return (ether_aton_r(s, &eabuf->ea_addr));
+}