diff options
Diffstat (limited to 'usr/src/lib/libc/port')
| -rw-r--r-- | usr/src/lib/libc/port/inet/inet_lnaof.c | 62 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/inet/inet_makeaddr.c | 67 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/inet/inet_network.c | 101 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/inet/inet_ntoa.c | 273 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/inet/inet_ntop.c | 181 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/inet/inet_pton.c | 220 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/llib-lc | 22 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/mapfile-vers | 37 |
8 files changed, 939 insertions, 24 deletions
diff --git a/usr/src/lib/libc/port/inet/inet_lnaof.c b/usr/src/lib/libc/port/inet/inet_lnaof.c new file mode 100644 index 0000000000..ff24f7fbaf --- /dev/null +++ b/usr/src/lib/libc/port/inet/inet_lnaof.c @@ -0,0 +1,62 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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] + * + * CDDL HEADER END + */ +/* + * Copyright 1997 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +/* + * University Copyright- Copyright (c) 1982, 1986, 1988 + * The Regents of the University of California + * All Rights Reserved + * + * University Acknowledgment- Portions of this document are derived from + * software developed by the University of California, Berkeley, and its + * contributors. + */ + +#include "lint.h" + +#include <sys/types.h> + +#include <netinet/in.h> + +/* + * Return the local network address portion of an + * internet address; handles class a/b/c network + * number formats. + */ +in_addr_t +inet_lnaof(struct in_addr in) +{ + uint32_t i = ntohl(in.s_addr); + + if (IN_CLASSA(i)) + return ((i)&IN_CLASSA_HOST); + else if (IN_CLASSB(i)) + return ((i)&IN_CLASSB_HOST); + else + return ((i)&IN_CLASSC_HOST); +} diff --git a/usr/src/lib/libc/port/inet/inet_makeaddr.c b/usr/src/lib/libc/port/inet/inet_makeaddr.c new file mode 100644 index 0000000000..017f426b0e --- /dev/null +++ b/usr/src/lib/libc/port/inet/inet_makeaddr.c @@ -0,0 +1,67 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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] + * + * CDDL HEADER END + */ +/* + * Copyright 2001 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +/* + * University Copyright- Copyright (c) 1982, 1986, 1988 + * The Regents of the University of California + * All Rights Reserved + * + * University Acknowledgment- Portions of this document are derived from + * software developed by the University of California, Berkeley, and its + * contributors. + */ + +#include "lint.h" + +#include <sys/types.h> + +#include <netinet/in.h> + +/* + * Formulate an Internet address from network + host. Used in + * building addresses stored in the ifnet structure. + */ +struct in_addr +inet_makeaddr(ipaddr_t net, ipaddr_t host) +{ + ipaddr_t addr; + struct in_addr inaddr; + + if (net < 128) + addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); + else if (net < 65536) + addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); + else if (net < 16777216L) + addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); + else + addr = net | host; + addr = htonl(addr); + inaddr.s_addr = addr; + return (inaddr); +} diff --git a/usr/src/lib/libc/port/inet/inet_network.c b/usr/src/lib/libc/port/inet/inet_network.c new file mode 100644 index 0000000000..8205a4795a --- /dev/null +++ b/usr/src/lib/libc/port/inet/inet_network.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (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] + * + * CDDL HEADER END + */ +/* + * Copyright 2001 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +/* + * University Copyright- Copyright (c) 1982, 1986, 1988 + * The Regents of the University of California + * All Rights Reserved + * + * University Acknowledgment- Portions of this document are derived from + * software developed by the University of California, Berkeley, and its + * contributors. + */ + +#include "lint.h" + +#include <sys/types.h> + +#include <netinet/in.h> + +#include <ctype.h> + +/* + * Internet network address interpretation routine. + * The library routines call this routine to interpret + * network numbers. + */ +in_addr_t +inet_network(const char *cp) +{ + in_addr_t val; + int base; + ptrdiff_t n; + char c; + in_addr_t parts[4], *pp = parts; + int i; + +again: + val = 0; base = 10; + if (*cp == '0') { + if (*++cp == 'x' || *cp == 'X') + base = 16, cp++; + else + base = 8; + } + while ((c = *cp) != NULL) { + if (isdigit(c)) { + if ((c - '0') >= base) + break; + val = (val * base) + (c - '0'); + cp++; + continue; + } + if (base == 16 && isxdigit(c)) { + val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); + cp++; + continue; + } + break; + } + if (pp >= parts + 4 || val > 0xff) + return ((in_addr_t)-1); + *pp++ = val; + if (*cp == '.') { + cp++; + goto again; + } + if (*cp != '\0' && !isspace(*cp)) + return ((in_addr_t)-1); + n = pp - parts; + for (val = 0, i = 0; i < n; i++) { + val <<= 8; + val |= parts[i]; + } + return (val); +} diff --git a/usr/src/lib/libc/port/inet/inet_ntoa.c b/usr/src/lib/libc/port/inet/inet_ntoa.c new file mode 100644 index 0000000000..8cc18cdc47 --- /dev/null +++ b/usr/src/lib/libc/port/inet/inet_ntoa.c @@ -0,0 +1,273 @@ +/* + * CDDL HEADER START + * + * 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] + * + * CDDL HEADER END + */ + +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ +/* + * Portions of this source code were derived from Berkeley + * 4.3 BSD under license from the Regents of the University of + * California. + */ + +/* + * Copyright (c) 1983, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * Portions Copyright (c) 1996-1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * Convert network-format internet address + * to base 256 d.d.d.d representation. + * + * Reentrant interface + */ + +#include "lint.h" +#include "thr_uberdata.h" + +#include <sys/types.h> + +#include <netinet/in.h> + +#include <ctype.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> + +char * +inet_ntoa_r(struct in_addr in, char b[]) +{ + char *p; + + p = (char *)∈ +#define UC(b) (((int)b)&0xff) + (void) sprintf(b, "%d.%d.%d.%d", + UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); + return (b); +} + +char * +inet_ntoa(struct in_addr in) +{ + return (inet_ntoa_r(in, curthread->ul_ntoabuf)); +} + +/* + * Check whether "cp" is a valid ascii representation + * of an Internet address and convert to a binary address. + * Returns 1 if the address is valid, 0 if not. + * This replaces inet_addr, the return value from which + * cannot distinguish between failure and a local broadcast address. + */ +int +inet_aton(const char *cp, struct in_addr *addr) +{ + uint32_t val; + int base, n; + char c; + unsigned int parts[4]; + unsigned int *pp = parts; + + c = *cp; + for (;;) { + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, isdigit=decimal. + */ + if (!isdigit(c)) + return (0); + val = 0; base = 10; + if (c == '0') { + c = *++cp; + if (c == 'x' || c == 'X') + base = 16, c = *++cp; + else + base = 8; + } + for (;;) { + if (isascii(c) && isdigit(c)) { + val = (val * base) + (c - '0'); + c = *++cp; + } else if (base == 16 && isascii(c) && isxdigit(c)) { + val = (val << 4) | + (c + 10 - (islower(c) ? 'a' : 'A')); + c = *++cp; + } else + break; + } + if (c == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16 bits) + * a.b (with b treated as 24 bits) + */ + if (pp >= parts + 3) + return (0); + *pp++ = val; + c = *++cp; + } else + break; + } + /* + * Check for trailing characters. + */ + if (c != '\0' && (!isascii(c) || !isspace(c))) + return (0); + /* + * Concoct the address according to + * the number of parts specified. + */ + n = pp - parts + 1; + switch (n) { + + case 0: + return (0); /* initial nondigit */ + + case 1: /* a -- 32 bits */ + break; + + case 2: /* a.b -- 8.24 bits */ + if ((val > 0xffffff) || (parts[0] > 0xff)) + return (0); + val |= parts[0] << 24; + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || + (parts[2] > 0xff)) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + if (addr) + addr->s_addr = htonl(val); + return (1); +} + +/* + * Internet address interpretation routine. + * All the network library routines call this + * routine to interpret entries in the data bases + * which are expected to be an address. + * The value returned is in network order. + */ +in_addr_t +inet_addr(const char *cp) +{ + struct in_addr val; + + if (inet_aton(cp, &val)) + return (val.s_addr); + return (INADDR_NONE); +} + +/* + * Return the network number from an internet + * address; handles class a/b/c network #'s. + */ +in_addr_t +inet_netof(struct in_addr in) +{ + uint32_t i = ntohl(in.s_addr); + + if (IN_CLASSA(i)) + return ((i & IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); + if (IN_CLASSB(i)) + return ((i & IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); + return ((i & IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); +} diff --git a/usr/src/lib/libc/port/inet/inet_ntop.c b/usr/src/lib/libc/port/inet/inet_ntop.c new file mode 100644 index 0000000000..ef9cd8ea4b --- /dev/null +++ b/usr/src/lib/libc/port/inet/inet_ntop.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include "lint.h" + +#include <sys/socket.h> + +#include <arpa/inet.h> +#include <netinet/in.h> + +#include <ctype.h> +#include <errno.h> +#include <netdb.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +static const char *inet_ntop4(const uchar_t *, char *, socklen_t); +static const char *inet_ntop6(const uchar_t *, char *, socklen_t); + +/* + * char * + * inet_ntop(af, src, dst, size) + * convert a network format address to presentation format. + * return: + * pointer to presentation format address (`dst'), or NULL (see errno). + */ +const char * +inet_ntop(int af, const void *src, char *dst, socklen_t size) +{ + switch (af) { + case AF_INET: + return (inet_ntop4(src, dst, size)); + case AF_INET6: + return (inet_ntop6(src, dst, size)); + default: + errno = EAFNOSUPPORT; + return (NULL); + } + /* NOTREACHED */ +} + +/* + * const char * + * inet_ntop4(src, dst, size) + * format an IPv4 address, more or less like inet_ntoa() + * return: + * `dst' (as a const) + * notes: + * (1) uses no statics + * (2) takes a uchar_t* not an in_addr as input + */ + +static const char * +inet_ntop4(const uchar_t *src, char *dst, socklen_t size) +{ + static const char fmt[] = "%u.%u.%u.%u"; + char tmp[sizeof ("255.255.255.255")]; + + if (sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) { + errno = ENOSPC; + return (NULL); + } + (void) strcpy(dst, tmp); + return (dst); +} + +/* + * const char * + * inet_ntop6(src, dst, size) + * convert IPv6 binary address into presentation (printable) format + */ +#define INADDRSZ 4 +#define IN6ADDRSZ 16 +#define INT16SZ 2 +static const char * +inet_ntop6(const uchar_t *src, char *dst, socklen_t size) +{ + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof ("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *tp; + struct { int base, len; } best, cur; + uint_t words[IN6ADDRSZ / INT16SZ]; + int i; + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + (void) memset(words, '\0', sizeof (words)); + for (i = 0; i < IN6ADDRSZ; i++) + words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); + best.base = -1; + cur.base = -1; + for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { + if (words[i] == 0) { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } else { + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && + i < (best.base + best.len)) { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { + if (!inet_ntop4(src+12, tp, sizeof (tmp) - (tp - tmp))) + return (NULL); + tp += strlen(tp); + break; + } + tp += sprintf(tp, "%x", words[i]); + } + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) + *tp++ = ':'; + *tp++ = '\0'; + + /* + * Check for overflow, copy, and we're done. + */ + if ((int)(tp - tmp) > size) { + errno = ENOSPC; + return (NULL); + } + (void) strcpy(dst, tmp); + return (dst); +} diff --git a/usr/src/lib/libc/port/inet/inet_pton.c b/usr/src/lib/libc/port/inet/inet_pton.c new file mode 100644 index 0000000000..41497a6f19 --- /dev/null +++ b/usr/src/lib/libc/port/inet/inet_pton.c @@ -0,0 +1,220 @@ +/* + * Copyright (c) 1996 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include "lint.h" + +#include <sys/socket.h> + +#include <arpa/inet.h> +#include <netinet/in.h> + +#include <ctype.h> +#include <errno.h> +#include <netdb.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +static int inet_pton4(const char *src, uchar_t *dst); +static int inet_pton6(const char *src, uchar_t *dst); + +/* + * int + * inet_pton(af, src, dst) + * convert from presentation format (which usually means ASCII printable) + * to network format (which is usually some kind of binary format). + * return: + * 1 if the address was valid for the specified address family + * 0 if the address wasn't valid (`dst' is untouched in this case) + * -1 if some other error occurred (`dst' is untouched in this case, too) + * author: + * Paul Vixie, 1996. Taken from on297-gate:dns stuff + */ +int +inet_pton(int af, const char *src, void *dst) +{ + switch (af) { + case AF_INET: + return (inet_pton4(src, dst)); + case AF_INET6: + return (inet_pton6(src, dst)); + default: + errno = EAFNOSUPPORT; + return (-1); + } + /* NOTREACHED */ +} + +/* + * int + * inet_pton4(src, dst) + * like inet_aton() but without all the hexadecimal and shorthand. + * return: + * 1 if `src' is a valid dotted quad, else 0. + * notice: + * does not touch `dst' unless it's returning 1. + * + */ +#define INADDRSZ 4 +#define IN6ADDRSZ 16 +#define INT16SZ 2 + +static int +inet_pton4(const char *src, uchar_t *dst) +{ + static const char digits[] = "0123456789"; + int saw_digit, octets, ch; + uchar_t tmp[INADDRSZ], *tp; + + saw_digit = 0; + octets = 0; + *(tp = tmp) = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + if ((pch = strchr(digits, ch)) != NULL) { + uint_t new = *tp * 10 + (pch - digits); + + if (new > 255) + return (0); + *tp = new; + if (!saw_digit) { + if (++octets > 4) + return (0); + saw_digit = 1; + } + } else if (ch == '.' && saw_digit) { + if (octets == 4) + return (0); + *++tp = 0; + saw_digit = 0; + } else + return (0); + } + if (octets < 4) + return (0); + + (void) memcpy(dst, tmp, INADDRSZ); + return (1); +} + + +/* + * int + * inet_pton6(src, dst) + * convert presentation level address to network order binary form. + * return: + * 1 if `src' is a valid [RFC1884 2.2] address, else 0. + * notice: + * (1) does not touch `dst' unless it's returning 1. + * (2) :: in a full address is silently ignored. + * credit: + * inspired by Mark Andrews. + * + */ +static int +inet_pton6(const char *src, uchar_t *dst) +{ + static const char xdigits_l[] = "0123456789abcdef"; + static const char xdigits_u[] = "0123456789ABCDEF"; + uchar_t tmp[IN6ADDRSZ], *tp, *endp, *colonp; + const char *xdigits, *curtok; + int ch, saw_xdigit; + uint_t val; + + (void) memset((tp = tmp), '\0', IN6ADDRSZ); + endp = tp + IN6ADDRSZ; + colonp = NULL; + /* Leading :: requires some special handling. */ + if (*src == ':') + if (*++src != ':') + return (0); + curtok = src; + saw_xdigit = 0; + val = 0; + while ((ch = *src++) != '\0') { + const char *pch; + + if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) + pch = strchr((xdigits = xdigits_u), ch); + if (pch != NULL) { + val <<= 4; + val |= (pch - xdigits); + if (val > 0xffff) + return (0); + saw_xdigit = 1; + continue; + } + if (ch == ':') { + curtok = src; + if (!saw_xdigit) { + if (colonp) + return (0); + colonp = tp; + continue; + } else if (*src == '\0') { + return (0); + } + if (tp + INT16SZ > endp) + return (0); + *tp++ = (uchar_t)(val >> 8) & 0xff; + *tp++ = (uchar_t)val & 0xff; + saw_xdigit = 0; + val = 0; + continue; + } + if (ch == '.' && ((tp + INADDRSZ) <= endp) && + inet_pton4(curtok, tp) > 0) { + tp += INADDRSZ; + saw_xdigit = 0; + break; /* '\0' was seen by inet_pton4(). */ + } + return (0); + } + if (saw_xdigit) { + if (tp + INT16SZ > endp) + return (0); + *tp++ = (uchar_t)(val >> 8) & 0xff; + *tp++ = (uchar_t)val & 0xff; + } + if (colonp != NULL) { + /* + * Since some memmove()'s erroneously fail to handle + * overlapping regions, we'll do the shift by hand. + */ + const int n = tp - colonp; + int i; + + if (tp == endp) + return (0); + for (i = 1; i <= n; i++) { + endp[- i] = colonp[n - i]; + colonp[n - i] = 0; + } + tp = endp; + } + if (tp != endp) + return (0); + (void) memcpy(dst, tmp, IN6ADDRSZ); + return (1); +} diff --git a/usr/src/lib/libc/port/llib-lc b/usr/src/lib/libc/port/llib-lc index a63267fc54..b7521a2f86 100644 --- a/usr/src/lib/libc/port/llib-lc +++ b/usr/src/lib/libc/port/llib-lc @@ -21,7 +21,7 @@ /* * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2017 Nexenta Systems, Inc. + * Copyright 2018 Nexenta Systems, Inc. * Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2013 Gary Mills * Copyright 2014 Garrett D'Amore <garrett@damore.org> @@ -171,6 +171,8 @@ #include <stack_unwind.h> #endif #include <xlocale.h> +#include <netinet/in.h> +#include <arpa/inet.h> /* * This really comes from the crt*.s startup modules. @@ -1429,7 +1431,6 @@ int pset_assign_forced(psetid_t pset, processorid_t cpu, psetid_t *opset); int pset_info(psetid_t pset, int *type, u_int *numcpus, processorid_t *cpulist); int pset_bind(psetid_t pset, idtype_t idtype, id_t id, psetid_t *opset); int pset_bind_lwp(psetid_t pset, id_t id, pid_t, psetid_t *opset); - /* rctlsys.c */ int getrctl(const char *name, rctlblk_t *old_rblk, rctlblk_t *new_rblk, @@ -1441,7 +1442,6 @@ int setprojrctl(const char *name, rctlblk_t *new_rblk, size_t size, int flags); int rctlctl(const char *, rctlblk_t *, int); size_t rctllist(char *, size_t); - /* semsys.c */ int semctl(int semid, int semnum, int cmd, ...); int semget(key_t key, int nsems, int semflg); @@ -1532,7 +1532,7 @@ size_t wcsxfrm(wchar_t *_RESTRICT_KYWD s1, const wchar_t *_RESTRICT_KYWD s2, int wcscoll(const wchar_t *s1, const wchar_t *s2); /* wcsftime.c */ -#if !defined(__amd64) /* XX64 - fix me */ +#if !defined(__amd64) /* XX64 - fix me */ size_t wcsftime(wchar_t *wcs, size_t maxsize, const char *format, const struct tm *timeptr); #endif /* __amd64 */ @@ -1631,7 +1631,7 @@ long double wcstold(const wchar_t *_RESTRICT_KYWD cp, double wstod(const wchar_t *cp, wchar_t **ptr); /* wstok.c */ -#if !defined(__amd64) /* XX64 - fix me */ +#if !defined(__amd64) /* XX64 - fix me */ wchar_t *wcstok(wchar_t *string, const wchar_t *sepset); wchar_t *wstok(wchar_t *string, const wchar_t *sepset); #endif /* __amd64 */ @@ -1848,3 +1848,15 @@ extern size_t u8_textprep_str(char *, size_t *, char *, size_t *, int, size_t, /* private locale interfaces */ wint_t __nextwctype(wint_t, wctype_t); int __iswrune(wint_t); + +/* inet_ntop.c */ +const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); + +/* inet_pton.c */ +int inet_pton(int af, const char *src, void *dst); + +/* inet_ntoa.c */ +char *inet_ntoa_r(struct in_addr in, char b[]); +char *inet_ntoa(struct in_addr in); +in_addr_t inet_addr(const char *cp); +in_addr_t inet_netof(struct in_addr in); diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index 905de27667..705ae9902a 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -21,7 +21,7 @@ # # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. -# Copyright 2017 Nexenta Systems, Inc. +# Copyright 2018 Nexenta Systems, Inc. # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2016 Joyent, Inc. # Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. @@ -52,21 +52,6 @@ $mapfile_version 2 # items and for the members of the malloc() family. # -# -# README README README README README README: how to update this file -# 1) each version of Solaris/OpenSolaris gets a version number. -# (Actually since Solaris is actually a series of OpenSolaris releases -# we'll just use OpenSolaris for this exercise.) -# OpenSolaris 2008.11 gets 1.23 -# OpenSolaris 2009.04 gets 1.24 -# etc. -# 2) each project integration uses a unique version number. -# PSARC/2008/123 gets 1.24.1 -# PSARC/2008/456 gets 1.24.2 -# etc. -# - - # Mnemonic conditional input identifiers: # # - amd64, i386, sparc32, sparcv9: Correspond to ISA subdirectories used to @@ -92,6 +77,20 @@ $if _x86 && _ELF64 $add amd64 $endif +SYMBOL_VERSION ILLUMOS_0.25 { # inet_* moved from libnsl/libsocket + protected: + inet_addr; + inet_aton; + inet_lnaof; + inet_makeaddr; + inet_netof; + inet_network; + inet_ntoa; + inet_ntoa_r; + inet_ntop; + inet_pton; +} ILLUMOS_0.24; + SYMBOL_VERSION ILLUMOS_0.24 { # openbsd compat protected: freezero; @@ -1021,7 +1020,7 @@ $if i386 # Note: atomic_add_64_nv is also defined above. Here, we add the # NODYNSORT attribute to it. On this platform, it is an aliases for # atomic_add_64. If that is changed, this line should be removed. - atomic_add_64_nv { FLAGS = NODYNSORT }; + atomic_add_64_nv { FLAGS = NODYNSORT }; $endif $if amd64 @@ -2778,7 +2777,7 @@ $endif $if amd64 } SYSVABI_1.3; -SYMBOL_VERSION SYSVABI_1.3 { +SYMBOL_VERSION SYSVABI_1.3 { $endif global: $if !_sparc @@ -2919,7 +2918,7 @@ $endif attr_to_data_type; attr_to_name; attr_to_option; - attr_to_xattr_view; + attr_to_xattr_view; _autofssys; _bufsync; _cladm; |
