diff options
-rw-r--r-- | usr/src/lib/libsocket/common/mapfile-vers | 6 | ||||
-rw-r--r-- | usr/src/lib/libsocket/inet/ether_addr.c | 53 | ||||
-rw-r--r-- | usr/src/man/man3socket/Makefile | 4 | ||||
-rw-r--r-- | usr/src/man/man3socket/ethers.3socket | 31 | ||||
-rw-r--r-- | usr/src/pkg/manifests/system-library.man3socket.inc | 2 | ||||
-rw-r--r-- | usr/src/uts/common/sys/ethernet.h | 3 |
6 files changed, 75 insertions, 24 deletions
diff --git a/usr/src/lib/libsocket/common/mapfile-vers b/usr/src/lib/libsocket/common/mapfile-vers index 2f7777f395..471774b462 100644 --- a/usr/src/lib/libsocket/common/mapfile-vers +++ b/usr/src/lib/libsocket/common/mapfile-vers @@ -39,6 +39,12 @@ $mapfile_version 2 +SYMBOL_VERSION ILLUMOS_0.2 { # reentrant ethers(3SOCKET) + global: + ether_aton_r; + ether_ntoa_r; +} ILLUMOS_0.1; + SYMBOL_VERSION ILLUMOS_0.1 { # Illumos additions global: accept4; 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)); +} diff --git a/usr/src/man/man3socket/Makefile b/usr/src/man/man3socket/Makefile index c4bbd116c7..5174020548 100644 --- a/usr/src/man/man3socket/Makefile +++ b/usr/src/man/man3socket/Makefile @@ -63,9 +63,11 @@ MANLINKS= accept4.3socket \ endprotoent.3socket \ endservent.3socket \ ether_aton.3socket \ + ether_aton_r.3socket \ ether_hostton.3socket \ ether_line.3socket \ ether_ntoa.3socket \ + ether_ntoa_r.3socket \ ether_ntohost.3socket \ freeaddrinfo.3socket \ freehostent.3socket \ @@ -155,9 +157,11 @@ ntohll.3socket := LINKSRC = byteorder.3socket ntohs.3socket := LINKSRC = byteorder.3socket ether_aton.3socket := LINKSRC = ethers.3socket +ether_aton_r.3socket := LINKSRC = ethers.3socket ether_hostton.3socket := LINKSRC = ethers.3socket ether_line.3socket := LINKSRC = ethers.3socket ether_ntoa.3socket := LINKSRC = ethers.3socket +ether_ntoa_r.3socket := LINKSRC = ethers.3socket ether_ntohost.3socket := LINKSRC = ethers.3socket freeaddrinfo.3socket := LINKSRC = getaddrinfo.3socket diff --git a/usr/src/man/man3socket/ethers.3socket b/usr/src/man/man3socket/ethers.3socket index 94cec9c957..77a5e330a6 100644 --- a/usr/src/man/man3socket/ethers.3socket +++ b/usr/src/man/man3socket/ethers.3socket @@ -1,12 +1,13 @@ '\" te .\" Copyright 1989 AT&T. .\" Copyright (C) 2004, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright (C) 2014, Joyent, Inc. All Rights Reserved. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH ETHERS 3SOCKET "Apr 5, 2004" +.TH ETHERS 3SOCKET "Aug 9, 2014" .SH NAME -ethers, ether_ntoa, ether_aton, ether_ntohost, ether_hostton, ether_line \- +ethers, ether_ntoa, ether_ntoa_r, ether_aton, ether_aton_r, ether_ntohost, ether_hostton, ether_line \- Ethernet address mapping operations .SH SYNOPSIS .LP @@ -20,11 +21,21 @@ Ethernet address mapping operations .LP .nf +\fBchar *\fR\fBether_ntoa_r\fR(\fBconst struct ether_addr *\fR\fIe\fR, \fBchar *\fR\fIs\fR); +.fi + +.LP +.nf \fBstruct ether_addr *\fR\fBether_aton\fR(\fBconst char *\fR\fIs\fR); .fi .LP .nf +\fBstruct ether_addr *\fR\fBether_aton_r\fR(\fBconst char *\fR\fIs\fR, \fBstruct ether_addr *\fR\fIe\fR); +.fi + +.LP +.nf \fBint\fR \fBether_ntohost\fR(\fBchar *\fR\fIhostname\fR, \fBconst struct ether_addr *\fR\fIe\fR); .fi @@ -39,7 +50,6 @@ Ethernet address mapping operations .fi .SH DESCRIPTION -.sp .LP These routines are useful for mapping 48 bit Ethernet numbers to their ASCII representations or their corresponding host names, and vice versa. @@ -55,6 +65,18 @@ representation back to a 48 bit Ethernet number; the function returns \fINULL\fR if the string cannot be scanned successfully. .sp .LP +The functions \fBether_ntoa()\fR and \fBether_aton()\fR return values in +per-thread buffers, one for each function. A second call to one of these +functions will overwrite the previous value. The functions +\fBether_ntoa_r()\fR and \fBether_aton_r()\fR behave identically to +their non-reentrant versions; however, instead of using a per-thread +buffer, they use caller supplied buffers. It is the callers +responsibility to ensure that the character buffer passed to +\fBether_ntoa_r()\fR is at least \fBETHERADDRSTRL\fR bytes large -- the +minimum size to hold the ASCII representation of a 48 bit Ethernet +number and a null terminator. +.sp +.LP The function \fBether_ntohost()\fR maps an Ethernet number (pointed to by \fIe\fR) to its associated hostname. The string pointed to by hostname must be long enough to hold the hostname and a \fINULL\fR character. The function @@ -75,7 +97,6 @@ to by hostname must be long enough to hold the hostname and a \fINULL\fR character. The function returns zero upon success and non-zero upon failure. The format of the scanned line is described by \fBethers\fR(4). .SH FILES -.sp .ne 2 .na \fB\fB/etc/ethers\fR\fR @@ -94,7 +115,6 @@ configuration file for the name service switch .RE .SH ATTRIBUTES -.sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -110,6 +130,5 @@ MT-Level MT-Safe .TE .SH SEE ALSO -.sp .LP \fBethers\fR(4), \fBnsswitch.conf\fR(4), \fBattributes\fR(5) diff --git a/usr/src/pkg/manifests/system-library.man3socket.inc b/usr/src/pkg/manifests/system-library.man3socket.inc index b3f8ca66d9..6b1ea6641b 100644 --- a/usr/src/pkg/manifests/system-library.man3socket.inc +++ b/usr/src/pkg/manifests/system-library.man3socket.inc @@ -61,9 +61,11 @@ link path=usr/share/man/man3socket/endprotoent.3socket \ link path=usr/share/man/man3socket/endservent.3socket \ target=getservbyname.3socket link path=usr/share/man/man3socket/ether_aton.3socket target=ethers.3socket +link path=usr/share/man/man3socket/ether_aton_r.3socket target=ethers.3socket link path=usr/share/man/man3socket/ether_hostton.3socket target=ethers.3socket link path=usr/share/man/man3socket/ether_line.3socket target=ethers.3socket link path=usr/share/man/man3socket/ether_ntoa.3socket target=ethers.3socket +link path=usr/share/man/man3socket/ether_ntoa_r.3socket target=ethers.3socket link path=usr/share/man/man3socket/ether_ntohost.3socket target=ethers.3socket link path=usr/share/man/man3socket/freeaddrinfo.3socket \ target=getaddrinfo.3socket diff --git a/usr/src/uts/common/sys/ethernet.h b/usr/src/uts/common/sys/ethernet.h index 6c9aeef4af..5b9de2f2bf 100644 --- a/usr/src/uts/common/sys/ethernet.h +++ b/usr/src/uts/common/sys/ethernet.h @@ -38,6 +38,7 @@ extern "C" { #define ETHERADDRL (6) /* ethernet address length in octets */ #define ETHERFCSL (4) /* ethernet FCS length in octets */ +#define ETHERADDRSTRL (18) /* char size of ETHERADDRL with null */ /* * Ethernet address - 6 octets @@ -144,7 +145,9 @@ extern char *ether_sprintf(struct ether_addr *); extern int ether_aton(char *, uchar_t *); #else /* _KERNEL */ extern char *ether_ntoa(const struct ether_addr *); +extern char *ether_ntoa_r(const struct ether_addr *, char *); extern struct ether_addr *ether_aton(const char *); +extern struct ether_addr *ether_aton_r(const char *, struct ether_addr *); extern int ether_ntohost(char *, const struct ether_addr *); extern int ether_hostton(const char *, struct ether_addr *); extern int ether_line(const char *, struct ether_addr *, char *); |