From eb8dd9dca1228af0cd132f515509051ecfabf6f6 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Mon, 14 Apr 2025 17:32:06 +0000 Subject: This commit was manufactured by cvs2git to create tag 'tb_20250414'. --- src/lib/libc/net/Makefile.inc | 31 --- src/lib/libc/net/base64.c | 307 ------------------------ src/lib/libc/net/ether_aton.3 | 114 --------- src/lib/libc/net/ethers.c | 183 -------------- src/lib/libc/net/freeaddrinfo.c | 50 ---- src/lib/libc/net/gai_strerror.3 | 95 -------- src/lib/libc/net/gai_strerror.c | 79 ------ src/lib/libc/net/getaddrinfo.3 | 477 ------------------------------------- src/lib/libc/net/gethostbyname.3 | 271 --------------------- src/lib/libc/net/getifaddrs.3 | 157 ------------ src/lib/libc/net/getifaddrs.c | 298 ----------------------- src/lib/libc/net/getnameinfo.3 | 264 -------------------- src/lib/libc/net/getnetent.3 | 147 ------------ src/lib/libc/net/getnetent.c | 49 ---- src/lib/libc/net/getpeereid.3 | 121 ---------- src/lib/libc/net/getpeereid.c | 36 --- src/lib/libc/net/getproto.c | 60 ----- src/lib/libc/net/getprotoent.3 | 213 ----------------- src/lib/libc/net/getprotoent.c | 169 ------------- src/lib/libc/net/getprotoname.c | 69 ------ src/lib/libc/net/getrrsetbyname.3 | 164 ------------- src/lib/libc/net/getservbyname.c | 72 ------ src/lib/libc/net/getservbyport.c | 65 ----- src/lib/libc/net/getservent.3 | 220 ----------------- src/lib/libc/net/getservent.c | 171 ------------- src/lib/libc/net/herror.c | 106 --------- src/lib/libc/net/htobe64.3 | 164 ------------- src/lib/libc/net/htonl.3 | 102 -------- src/lib/libc/net/htonl.c | 15 -- src/lib/libc/net/htons.c | 15 -- src/lib/libc/net/if_indextoname.3 | 143 ----------- src/lib/libc/net/if_indextoname.c | 78 ------ src/lib/libc/net/if_nameindex.c | 145 ----------- src/lib/libc/net/if_nametoindex.c | 77 ------ src/lib/libc/net/inet6_opt_init.3 | 328 ------------------------- src/lib/libc/net/inet6_rth_space.3 | 220 ----------------- src/lib/libc/net/inet_addr.3 | 195 --------------- src/lib/libc/net/inet_addr.c | 175 -------------- src/lib/libc/net/inet_lnaof.3 | 89 ------- src/lib/libc/net/inet_lnaof.c | 50 ---- src/lib/libc/net/inet_makeaddr.c | 53 ----- src/lib/libc/net/inet_net_ntop.3 | 195 --------------- src/lib/libc/net/inet_net_ntop.c | 160 ------------- src/lib/libc/net/inet_net_pton.c | 246 ------------------- src/lib/libc/net/inet_neta.c | 80 ------- src/lib/libc/net/inet_netof.c | 49 ---- src/lib/libc/net/inet_network.c | 85 ------- src/lib/libc/net/inet_ntoa.c | 51 ---- src/lib/libc/net/inet_ntop.3 | 213 ----------------- src/lib/libc/net/inet_ntop.c | 205 ---------------- src/lib/libc/net/inet_pton.c | 213 ----------------- src/lib/libc/net/ip6opt.c | 285 ---------------------- src/lib/libc/net/link_ntoa.3 | 78 ------ src/lib/libc/net/linkaddr.c | 85 ------- src/lib/libc/net/ntohl.c | 15 -- src/lib/libc/net/ntohs.c | 15 -- src/lib/libc/net/rcmd.3 | 232 ------------------ src/lib/libc/net/rcmd.c | 296 ----------------------- src/lib/libc/net/rcmdsh.3 | 95 -------- src/lib/libc/net/rcmdsh.c | 194 --------------- src/lib/libc/net/recv.c | 41 ---- src/lib/libc/net/res_comp.c | 466 ------------------------------------ src/lib/libc/net/res_data.c | 104 -------- src/lib/libc/net/res_debug_syms.c | 192 --------------- src/lib/libc/net/res_init.3 | 441 ---------------------------------- src/lib/libc/net/res_random.c | 281 ---------------------- src/lib/libc/net/rresvport.c | 107 --------- src/lib/libc/net/rthdr.c | 198 --------------- src/lib/libc/net/ruserok.c | 392 ------------------------------ src/lib/libc/net/send.c | 41 ---- src/lib/libc/net/sockatmark.3 | 122 ---------- src/lib/libc/net/sockatmark.c | 40 ---- src/lib/libc/net/vars6.c | 42 ---- 73 files changed, 11096 deletions(-) delete mode 100644 src/lib/libc/net/Makefile.inc delete mode 100644 src/lib/libc/net/base64.c delete mode 100644 src/lib/libc/net/ether_aton.3 delete mode 100644 src/lib/libc/net/ethers.c delete mode 100644 src/lib/libc/net/freeaddrinfo.c delete mode 100644 src/lib/libc/net/gai_strerror.3 delete mode 100644 src/lib/libc/net/gai_strerror.c delete mode 100644 src/lib/libc/net/getaddrinfo.3 delete mode 100644 src/lib/libc/net/gethostbyname.3 delete mode 100644 src/lib/libc/net/getifaddrs.3 delete mode 100644 src/lib/libc/net/getifaddrs.c delete mode 100644 src/lib/libc/net/getnameinfo.3 delete mode 100644 src/lib/libc/net/getnetent.3 delete mode 100644 src/lib/libc/net/getnetent.c delete mode 100644 src/lib/libc/net/getpeereid.3 delete mode 100644 src/lib/libc/net/getpeereid.c delete mode 100644 src/lib/libc/net/getproto.c delete mode 100644 src/lib/libc/net/getprotoent.3 delete mode 100644 src/lib/libc/net/getprotoent.c delete mode 100644 src/lib/libc/net/getprotoname.c delete mode 100644 src/lib/libc/net/getrrsetbyname.3 delete mode 100644 src/lib/libc/net/getservbyname.c delete mode 100644 src/lib/libc/net/getservbyport.c delete mode 100644 src/lib/libc/net/getservent.3 delete mode 100644 src/lib/libc/net/getservent.c delete mode 100644 src/lib/libc/net/herror.c delete mode 100644 src/lib/libc/net/htobe64.3 delete mode 100644 src/lib/libc/net/htonl.3 delete mode 100644 src/lib/libc/net/htonl.c delete mode 100644 src/lib/libc/net/htons.c delete mode 100644 src/lib/libc/net/if_indextoname.3 delete mode 100644 src/lib/libc/net/if_indextoname.c delete mode 100644 src/lib/libc/net/if_nameindex.c delete mode 100644 src/lib/libc/net/if_nametoindex.c delete mode 100644 src/lib/libc/net/inet6_opt_init.3 delete mode 100644 src/lib/libc/net/inet6_rth_space.3 delete mode 100644 src/lib/libc/net/inet_addr.3 delete mode 100644 src/lib/libc/net/inet_addr.c delete mode 100644 src/lib/libc/net/inet_lnaof.3 delete mode 100644 src/lib/libc/net/inet_lnaof.c delete mode 100644 src/lib/libc/net/inet_makeaddr.c delete mode 100644 src/lib/libc/net/inet_net_ntop.3 delete mode 100644 src/lib/libc/net/inet_net_ntop.c delete mode 100644 src/lib/libc/net/inet_net_pton.c delete mode 100644 src/lib/libc/net/inet_neta.c delete mode 100644 src/lib/libc/net/inet_netof.c delete mode 100644 src/lib/libc/net/inet_network.c delete mode 100644 src/lib/libc/net/inet_ntoa.c delete mode 100644 src/lib/libc/net/inet_ntop.3 delete mode 100644 src/lib/libc/net/inet_ntop.c delete mode 100644 src/lib/libc/net/inet_pton.c delete mode 100644 src/lib/libc/net/ip6opt.c delete mode 100644 src/lib/libc/net/link_ntoa.3 delete mode 100644 src/lib/libc/net/linkaddr.c delete mode 100644 src/lib/libc/net/ntohl.c delete mode 100644 src/lib/libc/net/ntohs.c delete mode 100644 src/lib/libc/net/rcmd.3 delete mode 100644 src/lib/libc/net/rcmd.c delete mode 100644 src/lib/libc/net/rcmdsh.3 delete mode 100644 src/lib/libc/net/rcmdsh.c delete mode 100644 src/lib/libc/net/recv.c delete mode 100644 src/lib/libc/net/res_comp.c delete mode 100644 src/lib/libc/net/res_data.c delete mode 100644 src/lib/libc/net/res_debug_syms.c delete mode 100644 src/lib/libc/net/res_init.3 delete mode 100644 src/lib/libc/net/res_random.c delete mode 100644 src/lib/libc/net/rresvport.c delete mode 100644 src/lib/libc/net/rthdr.c delete mode 100644 src/lib/libc/net/ruserok.c delete mode 100644 src/lib/libc/net/send.c delete mode 100644 src/lib/libc/net/sockatmark.3 delete mode 100644 src/lib/libc/net/sockatmark.c delete mode 100644 src/lib/libc/net/vars6.c (limited to 'src/lib/libc/net') diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc deleted file mode 100644 index db2c75dad6..0000000000 --- a/src/lib/libc/net/Makefile.inc +++ /dev/null @@ -1,31 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.61 2024/04/15 14:30:48 naddy Exp $ - -# net sources -.PATH: ${LIBCSRCDIR}/net - -CFLAGS+=-DRESOLVSORT - -SRCS+= base64.c ethers.c freeaddrinfo.c \ - gai_strerror.c getaddrinfo.c gethostnamadr.c \ - getifaddrs.c getnameinfo.c getnetent.c \ - getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \ - getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \ - herror.c htonl.c htons.c \ - if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ - inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ - inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ - linkaddr.c ntohl.c ntohs.c rcmd.c rcmdsh.c ruserok.c \ - rresvport.c recv.c res_comp.c res_data.c \ - res_debug.c res_debug_syms.c res_init.c res_mkquery.c res_query.c \ - res_random.c res_send.c \ - send.c sethostent.c sockatmark.c - -# IPv6 -SRCS+= ip6opt.c rthdr.c vars6.c - -MAN+= htobe64.3 ether_aton.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ - getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ - getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ - inet_addr.3 inet_lnaof.3 inet_net_ntop.3 inet_ntop.3 \ - inet6_opt_init.3 inet6_rth_space.3 link_ntoa.3 \ - rcmd.3 rcmdsh.3 res_init.3 sockatmark.3 diff --git a/src/lib/libc/net/base64.c b/src/lib/libc/net/base64.c deleted file mode 100644 index f36c11a21c..0000000000 --- a/src/lib/libc/net/base64.c +++ /dev/null @@ -1,307 +0,0 @@ -/* $OpenBSD: base64.c,v 1.15 2021/10/25 14:41:09 jca Exp $ */ - -/* - * 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. - */ - -/* - * Portions Copyright (c) 1995 by International Business Machines, Inc. - * - * International Business Machines, Inc. (hereinafter called IBM) grants - * permission under its copyrights to use, copy, modify, and distribute this - * Software with or without fee, provided that the above copyright notice and - * all paragraphs of this notice appear in all copies, and that the name of IBM - * not be used in connection with the marketing of any product incorporating - * the Software or modifications thereof, without specific, written prior - * permission. - * - * To the extent it has a right to do so, IBM grants an immunity from suit - * under its patents, if any, for the use, sale or manufacture of products to - * the extent that such products are used for performing Domain Name System - * dynamic updates in TCP/IP networks by means of the Software. No immunity is - * granted for any product per se or for any other function of any product. - * - * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, - * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN - * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -#include -#include -#include -#include - -#include -#include - -#include -#include - -static const char Base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const char Pad64 = '='; - -/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) - The following encoding technique is taken from RFC 1521 by Borenstein - and Freed. It is reproduced here in a slightly edited form for - convenience. - - A 65-character subset of US-ASCII is used, enabling 6 bits to be - represented per printable character. (The extra 65th character, "=", - is used to signify a special processing function.) - - The encoding process represents 24-bit groups of input bits as output - strings of 4 encoded characters. Proceeding from left to right, a - 24-bit input group is formed by concatenating 3 8-bit input groups. - These 24 bits are then treated as 4 concatenated 6-bit groups, each - of which is translated into a single digit in the base64 alphabet. - - Each 6-bit group is used as an index into an array of 64 printable - characters. The character referenced by the index is placed in the - output string. - - Table 1: The Base64 Alphabet - - Value Encoding Value Encoding Value Encoding Value Encoding - 0 A 17 R 34 i 51 z - 1 B 18 S 35 j 52 0 - 2 C 19 T 36 k 53 1 - 3 D 20 U 37 l 54 2 - 4 E 21 V 38 m 55 3 - 5 F 22 W 39 n 56 4 - 6 G 23 X 40 o 57 5 - 7 H 24 Y 41 p 58 6 - 8 I 25 Z 42 q 59 7 - 9 J 26 a 43 r 60 8 - 10 K 27 b 44 s 61 9 - 11 L 28 c 45 t 62 + - 12 M 29 d 46 u 63 / - 13 N 30 e 47 v - 14 O 31 f 48 w (pad) = - 15 P 32 g 49 x - 16 Q 33 h 50 y - - Special processing is performed if fewer than 24 bits are available - at the end of the data being encoded. A full encoding quantum is - always completed at the end of a quantity. When fewer than 24 input - bits are available in an input group, zero bits are added (on the - right) to form an integral number of 6-bit groups. Padding at the - end of the data is performed using the '=' character. - - Since all base64 input is an integral number of octets, only the - ------------------------------------------------- - following cases can arise: - - (1) the final quantum of encoding input is an integral - multiple of 24 bits; here, the final unit of encoded - output will be an integral multiple of 4 characters - with no "=" padding, - (2) the final quantum of encoding input is exactly 8 bits; - here, the final unit of encoded output will be two - characters followed by two "=" padding characters, or - (3) the final quantum of encoding input is exactly 16 bits; - here, the final unit of encoded output will be three - characters followed by one "=" padding character. - */ - -int -b64_ntop(unsigned char const *src, size_t srclength, char *target, - size_t targsize) -{ - size_t datalength = 0; - unsigned char input[3]; - unsigned char output[4]; - int i; - - while (2 < srclength) { - input[0] = *src++; - input[1] = *src++; - input[2] = *src++; - srclength -= 3; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - output[3] = input[2] & 0x3f; - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - target[datalength++] = Base64[output[2]]; - target[datalength++] = Base64[output[3]]; - } - - /* Now we worry about padding. */ - if (0 != srclength) { - /* Get what's left. */ - input[0] = input[1] = input[2] = '\0'; - for (i = 0; i < srclength; i++) - input[i] = *src++; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - if (srclength == 1) - target[datalength++] = Pad64; - else - target[datalength++] = Base64[output[2]]; - target[datalength++] = Pad64; - } - if (datalength >= targsize) - return (-1); - target[datalength] = '\0'; /* Returned value doesn't count \0. */ - return (datalength); -} - -/* skips all whitespace anywhere. - converts characters, four at a time, starting at (or after) - src from base - 64 numbers into three 8 bit bytes in the target area. - it returns the number of data bytes stored at the target, or -1 on error. - */ - -int -b64_pton(char const *src, unsigned char *target, size_t targsize) -{ - int tarindex, state, ch; - unsigned char nextbyte; - char *pos; - - state = 0; - tarindex = 0; - - while ((ch = (unsigned char)*src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ - continue; - - if (ch == Pad64) - break; - - pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ - return (-1); - - switch (state) { - case 0: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] = (pos - Base64) << 2; - } - state = 1; - break; - case 1: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - nextbyte = ((pos - Base64) & 0x0f) << 4; - if (tarindex + 1 < targsize) - target[tarindex+1] = nextbyte; - else if (nextbyte) - return (-1); - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - nextbyte = ((pos - Base64) & 0x03) << 6; - if (tarindex + 1 < targsize) - target[tarindex+1] = nextbyte; - else if (nextbyte) - return (-1); - } - tarindex++; - state = 3; - break; - case 3: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64); - } - tarindex++; - state = 0; - break; - } - } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == Pad64) { /* We got a pad char. */ - ch = (unsigned char)*src++; /* Skip it, get next. */ - switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return (-1); - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for (; ch != '\0'; ch = (unsigned char)*src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return (-1); - ch = (unsigned char)*src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - for (; ch != '\0'; ch = (unsigned char)*src++) - if (!isspace(ch)) - return (-1); - - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (target && tarindex < targsize && - target[tarindex] != 0) - return (-1); - } - } else { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state != 0) - return (-1); - } - - return (tarindex); -} diff --git a/src/lib/libc/net/ether_aton.3 b/src/lib/libc/net/ether_aton.3 deleted file mode 100644 index 98562dc44c..0000000000 --- a/src/lib/libc/net/ether_aton.3 +++ /dev/null @@ -1,114 +0,0 @@ -.\" $OpenBSD: ether_aton.3,v 1.3 2022/09/11 06:38:10 jmc Exp $ -.\" -.\" Written by roland@frob.com. Public domain. -.\" -.Dd $Mdocdate: September 11 2022 $ -.Dt ETHER_ATON 3 -.Os -.Sh NAME -.Nm ether_aton , -.Nm ether_ntoa , -.Nm ether_ntohost , -.Nm ether_hostton , -.Nm ether_line -.Nd get ethers entry -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In net/if.h -.In netinet/in.h -.In netinet/if_ether.h -.Ft char * -.Fn ether_ntoa "struct ether_addr *e" -.Ft struct ether_addr * -.Fn ether_aton "const char *s" -.Ft int -.Fn ether_ntohost "char *hostname" "struct ether_addr *e" -.Ft int -.Fn ether_hostton "const char *hostname" "struct ether_addr *e" -.Ft int -.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname" -.Sh DESCRIPTION -Ethernet addresses are represented by the -following structure: -.Bd -literal -offset indent -struct ether_addr { - u_int8_t ether_addr_octet[ETHER_ADDR_LEN]; -}; -.Ed -.Pp -The -.Fn ether_ntoa -function converts this structure into an -.Tn ASCII -string of the form -.Dq xx:xx:xx:xx:xx:xx , -consisting of 6 hexadecimal numbers separated -by colons. -It returns a pointer to a static buffer that is reused for each call. -The -.Fn ether_aton -function converts an -.Tn ASCII -string of the same form and to a structure -containing the 6 octets of the address. -It returns a pointer to a static structure that is reused for each call. -.Fn ether_aton -will return NULL if the string does not represent a valid address. -.Pp -The -.Fn ether_ntohost -and -.Fn ether_hostton -functions interrogate the database mapping host names to Ethernet -addresses, -.Pa /etc/ethers . -The -.Fn ether_ntohost -function looks up the given Ethernet address and writes the associated -host name into the character buffer passed. -This buffer should be -.Dv MAXHOSTNAMELEN -characters in size. -The -.Fn ether_hostton -function looks up the given host name and writes the associated -Ethernet address into the structure passed. -Both functions return -zero if they find the requested host name or address, and \-1 if not. -.Pp -Each call reads -.Pa /etc/ethers -from the beginning. -.Pp -The -.Fn ether_line -function parses a line from the -.Pa /etc/ethers -file and fills in the passed -.Vt struct ether_addr -and character buffer with the Ethernet address and host name on the line. -It returns zero if the line was successfully parsed and \-1 if not. -The character buffer should be -.Dv MAXHOSTNAMELEN -characters in size. -.Sh FILES -.Bl -tag -width /etc/ethers -compact -.It Pa /etc/ethers -.El -.Sh SEE ALSO -.Xr ethers 5 -.Sh HISTORY -The -.Fn ether_ntoa , -.Fn ether_aton , -.Fn ether_ntohost , -.Fn ether_hostton , -and -.Fn ether_line -functions were adopted from SunOS and appeared in -.Nx 0.9b . -.Sh BUGS -The data space used by these functions is static; if future use -requires the data, it should be copied before any subsequent calls to -these functions overwrite it. diff --git a/src/lib/libc/net/ethers.c b/src/lib/libc/net/ethers.c deleted file mode 100644 index d62be1ca71..0000000000 --- a/src/lib/libc/net/ethers.c +++ /dev/null @@ -1,183 +0,0 @@ -/* $OpenBSD: ethers.c,v 1.27 2019/01/25 00:19:25 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. - */ - -/* - * ethers(3) a la Sun. - * Originally Written by Roland McGrath 10/14/93. - * Substantially modified by Todd C. Miller - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef _PATH_ETHERS -#define _PATH_ETHERS "/etc/ethers" -#endif - -static char * _ether_aton(const char *, struct ether_addr *); - -char * -ether_ntoa(struct ether_addr *e) -{ - static char a[] = "xx:xx:xx:xx:xx:xx"; - - (void)snprintf(a, sizeof a, "%02x:%02x:%02x:%02x:%02x:%02x", - 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 (a); -} - -static char * -_ether_aton(const char *s, struct ether_addr *e) -{ - int i; - long l; - char *pp; - - while (isspace((unsigned char)*s)) - s++; - - /* expect 6 hex octets separated by ':' or space/NUL if last octet */ - for (i = 0; i < 6; i++) { - l = strtol(s, &pp, 16); - if (pp == s || l > 0xFF || l < 0) - return (NULL); - if (!(*pp == ':' || - (i == 5 && (isspace((unsigned char)*pp) || - *pp == '\0')))) - return (NULL); - e->ether_addr_octet[i] = (u_char)l; - s = pp + 1; - } - - /* return character after the octets ala strtol(3) */ - return (pp); -} - -struct ether_addr * -ether_aton(const char *s) -{ - static struct ether_addr n; - - return (_ether_aton(s, &n) ? &n : NULL); -} - -int -ether_ntohost(char *hostname, struct ether_addr *e) -{ - FILE *f; - char buf[BUFSIZ+1], *p; - size_t len; - struct ether_addr try; - - f = fopen(_PATH_ETHERS, "re"); - if (f == NULL) - return (-1); - while ((p = fgetln(f, &len)) != NULL) { - if (p[len-1] == '\n') - len--; - if (len > sizeof(buf) - 2) - continue; - (void)memcpy(buf, p, len); - buf[len] = '\n'; /* code assumes newlines later on */ - buf[len+1] = '\0'; - /* A + in the file meant try YP, ignore it. */ - if (!strncmp(buf, "+\n", sizeof(buf))) - continue; - if (ether_line(buf, &try, hostname) == 0 && - memcmp(&try, e, sizeof(try)) == 0) { - (void)fclose(f); - return (0); - } - } - (void)fclose(f); - errno = ENOENT; - return (-1); -} - -int -ether_hostton(const char *hostname, struct ether_addr *e) -{ - FILE *f; - char buf[BUFSIZ+1], *p; - char try[HOST_NAME_MAX+1]; - size_t len; - - f = fopen(_PATH_ETHERS, "re"); - if (f==NULL) - return (-1); - - while ((p = fgetln(f, &len)) != NULL) { - if (p[len-1] == '\n') - len--; - if (len > sizeof(buf) - 2) - continue; - memcpy(buf, p, len); - buf[len] = '\n'; /* code assumes newlines later on */ - buf[len+1] = '\0'; - /* A + in the file meant try YP, ignore it. */ - if (!strncmp(buf, "+\n", sizeof(buf))) - continue; - if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) { - (void)fclose(f); - return (0); - } - } - (void)fclose(f); - errno = ENOENT; - return (-1); -} - -int -ether_line(const char *line, struct ether_addr *e, char *hostname) -{ - char *p; - size_t n; - - /* Parse "xx:xx:xx:xx:xx:xx" */ - if ((p = _ether_aton(line, e)) == NULL || (*p != ' ' && *p != '\t')) - goto bad; - - /* Now get the hostname */ - while (isspace((unsigned char)*p)) - p++; - if (*p == '\0') - goto bad; - n = strcspn(p, " \t\n"); - if (n >= HOST_NAME_MAX+1) - goto bad; - strlcpy(hostname, p, n + 1); - return (0); - -bad: - errno = EINVAL; - return (-1); -} -DEF_WEAK(ether_line); diff --git a/src/lib/libc/net/freeaddrinfo.c b/src/lib/libc/net/freeaddrinfo.c deleted file mode 100644 index 154f70cd75..0000000000 --- a/src/lib/libc/net/freeaddrinfo.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: freeaddrinfo.c,v 1.9 2016/09/21 04:38:56 guenther Exp $ */ - -/* - * Copyright (c) 1996, 1997, 1998, 1999, Craig Metz, 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 Craig Metz and - * by other contributors. - * 4. Neither the name of the author nor the names of 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. - */ - -#include -#include - -void -freeaddrinfo(struct addrinfo *ai) -{ - struct addrinfo *p; - - do { - p = ai; - ai = ai->ai_next; - free(p->ai_canonname); - free(p); - } while (ai); -} -DEF_WEAK(freeaddrinfo); diff --git a/src/lib/libc/net/gai_strerror.3 b/src/lib/libc/net/gai_strerror.3 deleted file mode 100644 index d271f492c5..0000000000 --- a/src/lib/libc/net/gai_strerror.3 +++ /dev/null @@ -1,95 +0,0 @@ -.\" $OpenBSD: gai_strerror.3,v 1.10 2017/05/03 01:58:33 deraadt Exp $ -.\" $KAME: gai_strerror.3,v 1.1 2005/01/05 03:04:47 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 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 ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC 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. -.\" -.Dd $Mdocdate: May 3 2017 $ -.Dt GAI_STRERROR 3 -.Os -.Sh NAME -.Nm gai_strerror -.Nd get error message string from EAI_xxx error code -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In netdb.h -.Ft "const char *" -.Fn gai_strerror "int ecode" -.Sh DESCRIPTION -The -.Fn gai_strerror -function returns an error message string corresponding to the error code -returned by -.Xr getaddrinfo 3 -or -.Xr getnameinfo 3 . -.Pp -The following error codes and their meaning are defined in -.In netdb.h : -.Pp -.Bl -tag -width "EAI_ADDRFAMILYXX" -offset indent -compact -.It Dv EAI_ADDRFAMILY -address family for -.Fa name -not supported -.It Dv EAI_AGAIN -temporary failure in name resolution -.It Dv EAI_BADFLAGS -invalid value for -.Fa ai_flags -.It Dv EAI_BADHINTS -invalid value for -.Fa hints -.It Dv EAI_FAIL -non-recoverable failure in name resolution -.It Dv EAI_FAMILY -.Fa ai_family -not supported -.It Dv EAI_MEMORY -memory allocation failure -.It Dv EAI_NODATA -no address associated with -.Fa name -.It Dv EAI_NONAME -.Fa name -or -.Fa service -not provided, or not known -.It Dv EAI_OVERFLOW -argument buffer overflow -.It Dv EAI_PROTOCOL -resolved protocol is unknown -.It Dv EAI_SERVICE -.Fa service -not supported for -.Fa ai_socktype -.It Dv EAI_SOCKTYPE -.Fa ai_socktype -not supported -.It Dv EAI_SYSTEM -system error (returned in -.Va errno ) -.El -.Sh RETURN VALUES -.Fn gai_strerror -returns a pointer to the error message string corresponding to -.Fa ecode . -If -.Fa ecode -is out of range, an implementation-specific error message string is returned. -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr getnameinfo 3 diff --git a/src/lib/libc/net/gai_strerror.c b/src/lib/libc/net/gai_strerror.c deleted file mode 100644 index 1e9b585029..0000000000 --- a/src/lib/libc/net/gai_strerror.c +++ /dev/null @@ -1,79 +0,0 @@ -/* $OpenBSD: gai_strerror.c,v 1.8 2015/09/14 07:38:38 guenther Exp $ */ - -/* - * Copyright (c) 1997-1999, Craig Metz, 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 Craig Metz and - * by other contributors. - * 4. Neither the name of the author nor the names of 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. - */ - -/* gai_strerror() v1.38 */ - -#include -#include -#include - -const char * -gai_strerror(int errnum) -{ - switch (errnum) { - case 0: - return "no error"; - case EAI_BADFLAGS: - return "invalid value for ai_flags"; - case EAI_NONAME: - return "name or service is not known"; - case EAI_AGAIN: - return "temporary failure in name resolution"; - case EAI_FAIL: - return "non-recoverable failure in name resolution"; - case EAI_NODATA: - return "no address associated with name"; - case EAI_FAMILY: - return "ai_family not supported"; - case EAI_SOCKTYPE: - return "ai_socktype not supported"; - case EAI_SERVICE: - return "service not supported for ai_socktype"; - case EAI_ADDRFAMILY: - return "address family for name not supported"; - case EAI_MEMORY: - return "memory allocation failure"; - case EAI_SYSTEM: - return "system error"; - case EAI_BADHINTS: - return "invalid value for hints"; - case EAI_PROTOCOL: - return "resolved protocol is unknown"; - case EAI_OVERFLOW: - return "argument buffer overflow"; - default: - return "unknown/invalid error"; - } -} -DEF_WEAK(gai_strerror); diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 deleted file mode 100644 index 780c7a409f..0000000000 --- a/src/lib/libc/net/getaddrinfo.3 +++ /dev/null @@ -1,477 +0,0 @@ -.\" $OpenBSD: getaddrinfo.3,v 1.61 2022/09/11 06:38:10 jmc Exp $ -.\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 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 ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC 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. -.\" -.Dd $Mdocdate: September 11 2022 $ -.Dt GETADDRINFO 3 -.Os -.Sh NAME -.Nm getaddrinfo , -.Nm freeaddrinfo -.Nd host and service name to socket address structure -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In netdb.h -.Ft int -.Fn getaddrinfo "const char *hostname" "const char *servname" \ - "const struct addrinfo *hints" "struct addrinfo **res" -.Ft void -.Fn freeaddrinfo "struct addrinfo *ai" -.Sh DESCRIPTION -The -.Fn getaddrinfo -function is used to get a list of -.Tn IP -addresses and port numbers for host -.Fa hostname -and service -.Fa servname . -It is a replacement for and provides more flexibility than the -.Xr gethostbyname 3 -and -.Xr getservbyname 3 -functions. -.Pp -The -.Fa hostname -and -.Fa servname -arguments are either pointers to NUL-terminated strings or the null pointer. -An acceptable value for -.Fa hostname -is either a valid host name or a numeric host address string consisting -of a dotted decimal IPv4 address or an IPv6 address. -The -.Fa servname -is either a decimal port number or a service name listed in -.Xr services 5 . -At least one of -.Fa hostname -and -.Fa servname -must be non-null. -.Pp -.Fa hints -is an optional pointer to a -.Vt struct addrinfo , -as defined by -.In netdb.h : -.Bd -literal -struct addrinfo { - int ai_flags; /* input flags */ - int ai_family; /* address family for socket */ - int ai_socktype; /* socket type */ - int ai_protocol; /* protocol for socket */ - socklen_t ai_addrlen; /* length of socket-address */ - struct sockaddr *ai_addr; /* socket-address for socket */ - char *ai_canonname; /* canonical name for service location */ - struct addrinfo *ai_next; /* pointer to next in list */ -}; -.Ed -.Pp -This structure can be used to provide hints concerning the type of socket -that the caller supports or wishes to use. -The caller can supply the following structure elements in -.Fa hints : -.Bl -tag -width "ai_socktypeXX" -.It Fa ai_family -The address family that should be used. -When -.Fa ai_family -is set to -.Dv AF_UNSPEC , -it means the caller will accept any address family supported by the -operating system. -.It Fa ai_socktype -Denotes the type of socket that is wanted: -.Dv SOCK_STREAM , -.Dv SOCK_DGRAM , -or -.Dv SOCK_RAW . -When -.Fa ai_socktype -is zero, the caller will accept any socket type. -.It Fa ai_protocol -Indicates which transport protocol is desired, -.Dv IPPROTO_UDP -or -.Dv IPPROTO_TCP . -If -.Fa ai_protocol -is zero, the caller will accept any protocol. -.It Fa ai_flags -.Fa ai_flags -is formed by -.Tn OR Ns 'ing -the following values: -.Bl -tag -width "AI_CANONNAMEXX" -.It Dv AI_ADDRCONFIG -If the -.Dv AI_ADDRCONFIG -bit is set, IPv4 addresses will be returned only if an IPv4 address is -configured on an interface, and IPv6 addresses will be returned only if an IPv6 -address is configured on an interface. -Addresses on a loopback interface and link-local IPv6 addresses are not -considered valid as configured addresses. -This bit is only considered when determining whether a DNS query should -be performed or not. -.It Dv AI_CANONNAME -If the -.Dv AI_CANONNAME -bit is set, a successful call to -.Fn getaddrinfo -will return a NUL-terminated string containing the canonical name -of the specified host name in the -.Fa ai_canonname -element of the first -.Vt addrinfo -structure returned. -.It Dv AI_FQDN -If the -.Dv AI_FQDN -bit is set, a successful call to -.Fn getaddrinfo -will return a NUL-terminated string containing the fully qualified domain name -of the specified host name in the -.Fa ai_canonname -element of the first -.Vt addrinfo -structure returned. -.Pp -This is different from the -.Dv AI_CANONNAME -bit flag that returns the canonical name registered in DNS, -which may be different from the fully qualified domain name -that the host name resolved to. -Only one of the -.Dv AI_FQDN -and -.Dv AI_CANONNAME -bits can be set. -.It Dv AI_NUMERICHOST -If the -.Dv AI_NUMERICHOST -bit is set, it indicates that -.Fa hostname -should be treated as a numeric string defining an IPv4 or IPv6 address -and no name resolution should be attempted. -.It Dv AI_NUMERICSERV -If the -.Dv AI_NUMERICSERV -bit is set, it indicates that -.Fa servname -should be treated as a numeric port string -and no service name resolution should be attempted. -.It Dv AI_PASSIVE -If the -.Dv AI_PASSIVE -bit is set, it indicates that the returned socket address structure -is intended for use in a call to -.Xr bind 2 . -In this case, if the -.Fa hostname -argument is the null pointer, then the IP address portion of the -socket address structure will be set to -.Dv INADDR_ANY -for an IPv4 address or -.Dv IN6ADDR_ANY_INIT -for an IPv6 address. -.Pp -If the -.Dv AI_PASSIVE -bit is not set, the returned socket address structure will be ready -for use in a call to -.Xr connect 2 -for a connection-oriented protocol or -.Xr connect 2 , -.Xr sendto 2 , -or -.Xr sendmsg 2 -if a connectionless protocol was chosen. -The -.Tn IP -address portion of the socket address structure will be set to the -loopback address if -.Fa hostname -is the null pointer and -.Dv AI_PASSIVE -is not set. -.El -.El -.Pp -All other elements of the -.Vt addrinfo -structure passed via -.Fa hints -must be zero or the null pointer. -.Pp -If -.Fa hints -is the null pointer, -.Fn getaddrinfo -behaves as if the caller provided a -.Vt struct addrinfo -with -.Fa ai_family -set to -.Dv AF_UNSPEC , -.Fa ai_flags -set to -.Dv AI_ADDRCONFIG , -and all other elements set to zero or -.Dv NULL . -.Pp -After a successful call to -.Fn getaddrinfo , -.Fa *res -is a pointer to a linked list of one or more -.Vt addrinfo -structures. -The list can be traversed by following the -.Fa ai_next -pointer in each -.Vt addrinfo -structure until a null pointer is encountered. -The three members -.Fa ai_family , -.Fa ai_socktype , -and -.Fa ai_protocol -in each returned -.Vt addrinfo -structure are suitable for a call to -.Xr socket 2 . -For each -.Vt addrinfo -structure in the list, the -.Fa ai_addr -member points to a filled-in socket address structure of length -.Fa ai_addrlen . -.Pp -This implementation of -.Fn getaddrinfo -allows numeric IPv6 address notation with scope identifier, -as documented in RFC 4007. -By appending the percent character and scope identifier to addresses, -one can fill the -.Li sin6_scope_id -field for addresses. -This would make management of scoped addresses easier -and allows cut-and-paste input of scoped addresses. -.Pp -At this moment the code supports only link-local addresses with the format. -The scope identifier is hardcoded to the name of the hardware interface -associated -with the link -.Po -such as -.Li ne0 -.Pc . -An example is -.Dq Li fe80::1%ne0 , -which means -.Do -.Li fe80::1 -on the link associated with the -.Li ne0 -interface -.Dc . -.Pp -The current implementation assumes a one-to-one relationship between -the interface and link, which is not necessarily true from the specification. -.Pp -All of the information returned by -.Fn getaddrinfo -is dynamically allocated: the -.Vt addrinfo -structures themselves as well as the socket address structures and -the canonical host name strings included in the -.Vt addrinfo -structures. -.Pp -Memory allocated for the dynamically allocated structures created by -a successful call to -.Fn getaddrinfo -is released by the -.Fn freeaddrinfo -function. -The -.Fa ai -pointer should be an -.Vt addrinfo -structure created by a call to -.Fn getaddrinfo . -.Sh RETURN VALUES -.Fn getaddrinfo -returns zero on success or one of the error codes listed in -.Xr gai_strerror 3 -if an error occurs. -If an error occurs, no memory is allocated by -.Fn getaddrinfo , -therefore it is not necessary to release the -.Vt addrinfo -structure(s). -.Sh EXAMPLES -The following code tries to connect to -.Dq Li www.kame.net -service -.Dq Li www -via a stream socket. -It loops through all the addresses available, regardless of address family. -If the destination resolves to an IPv4 address, it will use an -.Dv AF_INET -socket. -Similarly, if it resolves to IPv6, an -.Dv AF_INET6 -socket is used. -Observe that there is no hardcoded reference to a particular address family. -The code works even if -.Fn getaddrinfo -returns addresses that are not IPv4/v6. -.Bd -literal -offset indent -struct addrinfo hints, *res, *res0; -int error; -int save_errno; -int s; -const char *cause = NULL; - -memset(&hints, 0, sizeof(hints)); -hints.ai_family = AF_UNSPEC; -hints.ai_socktype = SOCK_STREAM; -error = getaddrinfo("www.kame.net", "www", &hints, &res0); -if (error) - errx(1, "%s", gai_strerror(error)); -s = -1; -for (res = res0; res; res = res->ai_next) { - s = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (s == -1) { - cause = "socket"; - continue; - } - - if (connect(s, res->ai_addr, res->ai_addrlen) == -1) { - cause = "connect"; - save_errno = errno; - close(s); - errno = save_errno; - s = -1; - continue; - } - - break; /* okay we got one */ -} -if (s == -1) - err(1, "%s", cause); -freeaddrinfo(res0); -.Ed -.Pp -The following example tries to open a wildcard listening socket onto service -.Dq Li www , -for all the address families available. -.Bd -literal -offset indent -struct addrinfo hints, *res, *res0; -int error; -int save_errno; -int s[MAXSOCK]; -int nsock; -const char *cause = NULL; - -memset(&hints, 0, sizeof(hints)); -hints.ai_family = AF_UNSPEC; -hints.ai_socktype = SOCK_STREAM; -hints.ai_flags = AI_PASSIVE; -error = getaddrinfo(NULL, "www", &hints, &res0); -if (error) - errx(1, "%s", gai_strerror(error)); -nsock = 0; -for (res = res0; res && nsock < MAXSOCK; res = res->ai_next) { - s[nsock] = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (s[nsock] == -1) { - cause = "socket"; - continue; - } - - if (bind(s[nsock], res->ai_addr, res->ai_addrlen) == -1) { - cause = "bind"; - save_errno = errno; - close(s[nsock]); - errno = save_errno; - continue; - } - (void) listen(s[nsock], 5); - - nsock++; -} -if (nsock == 0) - err(1, "%s", cause); -freeaddrinfo(res0); -.Ed -.Sh SEE ALSO -.Xr bind 2 , -.Xr connect 2 , -.Xr send 2 , -.Xr socket 2 , -.Xr gai_strerror 3 , -.Xr gethostbyname 3 , -.Xr getnameinfo 3 , -.Xr getservbyname 3 , -.Xr res_init 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr services 5 , -.Xr hostname 7 -.Rs -.%A Craig Metz -.%B Proceedings of the Freenix Track: 2000 USENIX Annual Technical Conference -.%D June 2000 -.%T Protocol Independence Using the Sockets API -.Re -.Sh STANDARDS -The -.Fn getaddrinfo -function is defined by the -.St -p1003.1g-2000 -draft specification and documented in RFC 3493. -.Pp -The -.Dv AI_FQDN -flag bit first appeared in Windows 7. -.Pp -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%D February 2003 -.%R RFC 3493 -.%T Basic Socket Interface Extensions for IPv6 -.Re -.Pp -.Rs -.%A S. Deering -.%A B. Haberman -.%A T. Jinmei -.%A E. Nordmark -.%A B. Zill -.%D March 2005 -.%R RFC 4007 -.%T IPv6 Scoped Address Architecture -.Re diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3 deleted file mode 100644 index 06170c3c1a..0000000000 --- a/src/lib/libc/net/gethostbyname.3 +++ /dev/null @@ -1,271 +0,0 @@ -.\" $OpenBSD: gethostbyname.3,v 1.34 2019/08/30 20:20:50 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1987, 1991, 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. 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. -.\" -.Dd $Mdocdate: August 30 2019 $ -.Dt GETHOSTBYNAME 3 -.Os -.Sh NAME -.Nm gethostbyname , -.Nm gethostbyname2 , -.Nm gethostbyaddr , -.Nm gethostent , -.Nm sethostent , -.Nm endhostent , -.Nm hstrerror , -.Nm herror -.Nd get network host entry -.Sh SYNOPSIS -.In netdb.h -.Vt extern int h_errno ; -.Ft struct hostent * -.Fn gethostbyname "const char *name" -.Ft struct hostent * -.Fn gethostent void -.Ft void -.Fn sethostent "int stayopen" -.Ft void -.Fn endhostent void -.Ft void -.Fn herror "const char *string" -.Ft const char * -.Fn hstrerror "int err" -.In sys/socket.h -.In netdb.h -.Ft struct hostent * -.Fn gethostbyname2 "const char *name" "int af" -.Ft struct hostent * -.Fn gethostbyaddr "const void *addr" "socklen_t len" "int af" -.Sh DESCRIPTION -The -.Fn gethostbyname , -.Fn gethostbyname2 , -and -.Fn gethostbyaddr -functions each return a pointer to an object with the following structure -describing an Internet host referenced by -.Fa name -or -.Fa addr , -respectively. -This structure contains either information obtained from a name server, -broken-out fields from a line in -.Pa /etc/hosts , -or database entries supplied by the -.Xr yp 8 -system. -.Xr resolv.conf 5 -describes how the particular database is chosen. -.Bd -literal -offset indent -struct hostent { - char *h_name; /* official name of host */ - char **h_aliases; /* alias list */ - int h_addrtype; /* host address type */ - int h_length; /* length of address */ - char **h_addr_list; /* list of returned addresses */ -}; -#define h_addr h_addr_list[0] /* address, for backward compat */ -.Ed -.Pp -The members of this structure are: -.Bl -tag -width h_addr_list -.It Fa h_name -Official name of the host. -.It Fa h_aliases -A -.Dv NULL Ns -terminated -array of alternate names for the host. -.It Fa h_addrtype -The type of address being returned. -.It Fa h_length -The length, in bytes, of the address. -.It Fa h_addr_list -A -.Dv NULL Ns -terminated -array of network addresses for the host. -Host addresses are returned in network byte order. -.It Fa h_addr -The first address in -.Fa h_addr_list ; -this is for backward compatibility. -.El -.Pp -The function -.Fn gethostbyname -will search for the named host in the current domain and its parents -using the search lookup semantics detailed in -.Xr resolv.conf 5 -and -.Xr hostname 7 . -.Pp -.Fn gethostbyname2 -is similar to -.Fn gethostbyname -except that it supports an -.Fa af -of -.Dv AF_INET6 -in addition to -.Dv AF_INET . -.Pp -The -.Fn gethostbyaddr -function will search for the specified address of length -.Fa len -in the address family -.Fa af . -The only address family supported is -.Dv AF_INET . -.Pp -The -.Fn sethostent , -.Fn gethostent , -and -.Fn endhostent -functions are deprecated and no longer have any effect. -They could be used in the past for queries over a persistent TCP -connection or to iterate entries in the -.Xr hosts 5 -file. -.Pp -The -.Fn herror -function prints an error message describing the failure. -If its argument -.Fa string -is not -.Dv NULL , -it is prepended to the message string and separated from it by a colon -.Pq Ql \&: -and a space. -The error message is printed with a trailing newline. -The contents of the error message is the same as that returned by -.Fn hstrerror -with argument -.Va h_errno . -.Sh ENVIRONMENT -.Bl -tag -width RES_OPTIONS -.It Ev RES_OPTIONS -A list of options to override the resolver's internal defaults. -See -.Xr resolv.conf 5 -for more information. -.El -.Sh FILES -.Bl -tag -width /etc/resolv.conf -compact -.It Pa /etc/hosts -.It Pa /etc/resolv.conf -.El -.Sh DIAGNOSTICS -Error return status from -.Fn gethostbyname , -.Fn gethostbyname2 , -and -.Fn gethostbyaddr -is indicated by return of a -.Dv NULL -pointer. -The external integer -.Va h_errno -may then be checked to see whether this is a temporary failure -or an invalid or unknown host. -.Pp -The variable -.Va h_errno -can have the following values: -.Bl -tag -width HOST_NOT_FOUND -.It Dv HOST_NOT_FOUND -No such host is known. -.It Dv TRY_AGAIN -This is usually a temporary error -and means that the local server did not receive -a response from an authoritative server. -A retry at some later time may succeed. -.It Dv NO_RECOVERY -Some unexpected server failure was encountered. -This is a non-recoverable error. -.It Dv NO_DATA -The requested name is valid but does not have an IP address; -this is not a temporary error. -This means that the name is known to the name server but there is no address -associated with this name. -Another type of request to the name server using this domain name -will result in an answer; -for example, a mail-forwarder may be registered for this domain. -.It Dv NETDB_INTERNAL -An internal error occurred. -This may occur when an address family other than -.Dv AF_INET -or -.Dv AF_INET6 -is specified or when a resource is unable to be allocated. -It is always set by -.Fn gethostent . -.It Dv NETDB_SUCCESS -The function completed successfully. -.El -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr getnameinfo 3 , -.Xr res_init 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr hostname 7 -.Sh HISTORY -The -.Fn endhostent , -.Fn gethostbyaddr , -.Fn gethostbyname , -.Fn gethostent , -and -.Fn sethostent -functions appeared in -.Bx 4.1c . -The function -.Fn herror -was added in -.Bx 4.3 Tahoe , -.Fn hstrerror -in -.Bx 4.4 , -and -.Fn gethostbyname2 -in -.Ox 2.1 . -.Sh BUGS -These functions use static data storage; -if the data is needed for future use, it should be -copied before any subsequent calls overwrite it. -.Pp -Only the Internet -address formats are currently understood. -.Pp -YP does not support any address families other than -.Dv AF_INET -and uses -the traditional database format. diff --git a/src/lib/libc/net/getifaddrs.3 b/src/lib/libc/net/getifaddrs.3 deleted file mode 100644 index 8ea08fa3da..0000000000 --- a/src/lib/libc/net/getifaddrs.3 +++ /dev/null @@ -1,157 +0,0 @@ -.\" $OpenBSD: getifaddrs.3,v 1.23 2022/03/29 18:15:52 naddy Exp $ -.\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp -.\" -.\" Copyright (c) 1995, 1999 -.\" Berkeley Software Design, Inc. 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. -.\" -.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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. -.Dd $Mdocdate: March 29 2022 $ -.Dt GETIFADDRS 3 -.Os -.Sh NAME -.Nm getifaddrs , -.Nm freeifaddrs -.Nd get interface addresses -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In ifaddrs.h -.Ft int -.Fn getifaddrs "struct ifaddrs **ifap" -.Ft void -.Fn freeifaddrs "struct ifaddrs *ifap" -.Sh DESCRIPTION -The -.Fn getifaddrs -function stores a reference to a linked list of the network interfaces -on the local machine in the memory referenced by -.Fa ifap . -The list consists of -.Vt ifaddrs -structures, as defined in the include file -.In ifaddrs.h . -The -.Vt ifaddrs -structure contains at least the following entries: -.Bd -literal - struct ifaddrs *ifa_next; /* Pointer to next struct */ - char *ifa_name; /* Interface name */ - u_int ifa_flags; /* Interface flags */ - struct sockaddr *ifa_addr; /* Interface address */ - struct sockaddr *ifa_netmask; /* Interface netmask */ - struct sockaddr *ifa_broadaddr; /* Interface broadcast address */ - struct sockaddr *ifa_dstaddr; /* P2P interface destination */ - void *ifa_data; /* Address specific data */ -.Ed -.Bl -tag -width ifa_broadaddr -.It Fa ifa_next -Contains a pointer to the next structure on the list. -This field is set to -.Dv NULL -in the last structure on the list. -.It Fa ifa_name -Contains the interface name. -.It Fa ifa_flags -Contains the interface flags, as set by -.Xr ifconfig 8 . -.It Fa ifa_addr -References either the address of the interface or the link level -address of the interface, if one exists, otherwise it is -.Dv NULL . -(The -.Fa sa_family -field of the -.Fa ifa_addr -field should be consulted to determine the format of the -.Fa ifa_addr -address.) -.It Fa ifa_netmask -References the netmask associated with -.Fa ifa_addr , -if one is set, otherwise it is -.Dv NULL . -.It Fa ifa_broadaddr -This field, which should only be referenced for non-P2P interfaces, -references the broadcast address associated with -.Fa ifa_addr , -if one exists, otherwise it is -.Dv NULL . -.It Fa ifa_dstaddr -This field, which should only be referenced for P2P interfaces, -references the destination address on a P2P interface, -if one exists, otherwise it is -.Dv NULL . -.It Fa ifa_data -References address family specific data. -For -.Dv AF_LINK -addresses it contains a pointer to the -.Vt struct if_data -(as defined in include file -.In net/if.h ) -which contains various interface attributes and statistics. -For all other address families, -.Fa ifa_data -is -.Dv NULL . -.El -.Pp -The data returned by -.Fn getifaddrs -is dynamically allocated and should be freed using -.Fn freeifaddrs -when no longer needed. -.Sh RETURN VALUES -.Rv -std -.Sh ERRORS -The -.Fn getifaddrs -function may fail and set -.Va errno -for any of the errors specified for the library routines -.Xr ioctl 2 , -.Xr socket 2 , -.Xr malloc 3 , -or -.Xr sysctl 2 . -.Sh SEE ALSO -.Xr ioctl 2 , -.Xr socket 2 , -.Xr sysctl 2 , -.Xr netintro 4 , -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn getifaddrs -function first appeared in BSDI -.Bsx . -The function has been available on -.Ox -since -.Ox 2.7 . -.Sh BUGS -If both -.In net/if.h -and -.In ifaddrs.h -are being included, -.In net/if.h -.Em must -be included before -.In ifaddrs.h . diff --git a/src/lib/libc/net/getifaddrs.c b/src/lib/libc/net/getifaddrs.c deleted file mode 100644 index 069ee9afab..0000000000 --- a/src/lib/libc/net/getifaddrs.c +++ /dev/null @@ -1,298 +0,0 @@ -/* $OpenBSD: getifaddrs.c,v 1.14 2021/11/29 03:20:37 deraadt Exp $ */ - -/* - * Copyright (c) 1995, 1999 - * Berkeley Software Design, Inc. 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. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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. - * - * BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp - */ - -#include /* ALIGN ALIGNBYTES */ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#define SALIGN (sizeof(long) - 1) -#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1)) - -int -getifaddrs(struct ifaddrs **pif) -{ - int icnt = 1; - int dcnt = 0; - int ncnt = 0; - int mib[6]; - size_t needed; - char *buf = NULL, *bufp; - char *next; - struct ifaddrs *cif = 0; - char *p, *p0; - struct rt_msghdr *rtm; - struct if_msghdr *ifm; - struct ifa_msghdr *ifam; - struct sockaddr_dl *dl; - struct sockaddr *sa; - u_short index = 0; - size_t len, alen, dlen; - struct ifaddrs *ifa, *ift; - int i; - char *data; - char *names; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; /* protocol */ - mib[3] = 0; /* wildcard address family */ - mib[4] = NET_RT_IFLIST; - mib[5] = 0; /* no flags */ - while (1) { - if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1) { - free(buf); - return (-1); - } - if (needed == 0) - break; - if ((bufp = realloc(buf, needed)) == NULL) { - free(buf); - return (-1); - } - buf = bufp; - if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1) { - if (errno == ENOMEM) - continue; - free(buf); - return (-1); - } - break; - } - - for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; - if (rtm->rtm_version != RTM_VERSION) - continue; - switch (rtm->rtm_type) { - case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - index = ifm->ifm_index; - ++icnt; - dl = (struct sockaddr_dl *)(next + - rtm->rtm_hdrlen); - dcnt += SA_RLEN((struct sockaddr *)dl) + - ALIGNBYTES; - dcnt += sizeof(ifm->ifm_data); - ncnt += dl->sdl_nlen + 1; - } else - index = 0; - break; - - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (index && ifam->ifam_index != index) - abort(); /* XXX abort illegal in library */ - -#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD) - if (index == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) - break; - p = next + rtm->rtm_hdrlen; - ++icnt; - /* Scan to look for length of address */ - alen = 0; - for (p0 = p, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_IFA) { - alen = len; - break; - } - p += len; - } - for (p = p0, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_NETMASK && sa->sa_len == 0) - dcnt += alen; - else - dcnt += len; - p += len; - } - break; - } - } - - if (icnt + dcnt + ncnt == 1) { - *pif = NULL; - free(buf); - return (0); - } - data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt); - if (data == NULL) { - free(buf); - return(-1); - } - - ifa = (struct ifaddrs *)data; - data += sizeof(struct ifaddrs) * icnt; - names = data + dcnt; - - memset(ifa, 0, sizeof(struct ifaddrs) * icnt); - ift = ifa; - - index = 0; - for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; - if (rtm->rtm_version != RTM_VERSION) - continue; - switch (rtm->rtm_type) { - case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - index = ifm->ifm_index; - dl = (struct sockaddr_dl *)(next + - rtm->rtm_hdrlen); - - cif = ift; - ift->ifa_name = names; - ift->ifa_flags = (int)ifm->ifm_flags; - memcpy(names, dl->sdl_data, dl->sdl_nlen); - names[dl->sdl_nlen] = 0; - names += dl->sdl_nlen + 1; - - ift->ifa_addr = (struct sockaddr *)data; - memcpy(data, dl, - ((struct sockaddr *)dl)->sa_len); - data += SA_RLEN((struct sockaddr *)dl); - - /* ifm_data needs to be aligned */ - ift->ifa_data = data = (void *)ALIGN(data); - dlen = rtm->rtm_hdrlen - - offsetof(struct if_msghdr, ifm_data); - if (dlen > sizeof(ifm->ifm_data)) - dlen = sizeof(ifm->ifm_data); - memcpy(data, &ifm->ifm_data, dlen); - data += sizeof(ifm->ifm_data); - - ift = (ift->ifa_next = ift + 1); - } else - index = 0; - break; - - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (index && ifam->ifam_index != index) - abort(); /* XXX abort illegal in library */ - - if (index == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) - break; - ift->ifa_name = cif->ifa_name; - ift->ifa_flags = cif->ifa_flags; - ift->ifa_data = NULL; - p = next + rtm->rtm_hdrlen; - /* Scan to look for length of address */ - alen = 0; - for (p0 = p, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_IFA) { - alen = len; - break; - } - p += len; - } - for (p = p0, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - switch (i) { - case RTAX_IFA: - ift->ifa_addr = (struct sockaddr *)data; - memcpy(data, p, len); - data += len; - break; - - case RTAX_NETMASK: - ift->ifa_netmask = - (struct sockaddr *)data; - if (sa->sa_len == 0) { - memset(data, 0, alen); - data += alen; - break; - } - memcpy(data, p, len); - data += len; - break; - - case RTAX_BRD: - ift->ifa_broadaddr = - (struct sockaddr *)data; - memcpy(data, p, len); - data += len; - break; - } - p += len; - } - - - ift = (ift->ifa_next = ift + 1); - break; - } - } - - free(buf); - if (--ift >= ifa) { - ift->ifa_next = NULL; - *pif = ifa; - } else { - *pif = NULL; - free(ifa); - } - return (0); -} -DEF_WEAK(getifaddrs); - -void -freeifaddrs(struct ifaddrs *ifp) -{ - free(ifp); -} -DEF_WEAK(freeifaddrs); diff --git a/src/lib/libc/net/getnameinfo.3 b/src/lib/libc/net/getnameinfo.3 deleted file mode 100644 index 4e97b5d07b..0000000000 --- a/src/lib/libc/net/getnameinfo.3 +++ /dev/null @@ -1,264 +0,0 @@ -.\" $OpenBSD: getnameinfo.3,v 1.49 2022/09/11 06:38:10 jmc Exp $ -.\" $KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 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 ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC 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. -.\" -.Dd $Mdocdate: September 11 2022 $ -.Dt GETNAMEINFO 3 -.Os -.Sh NAME -.Nm getnameinfo -.Nd socket address structure to hostname and service name -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In netdb.h -.Ft int -.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" \ - "size_t hostlen" "char *serv" "size_t servlen" "int flags" -.Sh DESCRIPTION -The -.Fn getnameinfo -function is used to convert a -.Vt sockaddr -structure to a pair of host name and service strings. -It is a replacement for and provides more flexibility than the -.Xr gethostbyaddr 3 -and -.Xr getservbyport 3 -functions and is the converse of the -.Xr getaddrinfo 3 -function. -.Pp -The -.Vt sockaddr -structure -.Fa sa -should point to either a -.Vt sockaddr_in -or -.Vt sockaddr_in6 -structure (for IPv4 or IPv6 respectively) that is -.Fa salen -bytes long. -.Pp -The host and service names associated with -.Fa sa -are stored in -.Fa host -and -.Fa serv -which have length parameters -.Fa hostlen -and -.Fa servlen . -The maximum value for -.Fa hostlen -is -.Dv NI_MAXHOST -and -the maximum value for -.Fa servlen -is -.Dv NI_MAXSERV , -as defined by -.In netdb.h . -If a length parameter is zero, no string will be stored. -Otherwise, enough space must be provided to store the -host name or service string plus a byte for the NUL terminator. -.Pp -The -.Fa flags -argument is formed by -.Tn OR Ns 'ing -the following values: -.Bl -tag -width "NI_NUMERICHOSTXX" -.It Dv NI_NOFQDN -A fully qualified domain name is not required for local hosts. -The local part of the fully qualified domain name is returned instead. -.It Dv NI_NUMERICHOST -Return the address in numeric form, as if calling -.Xr inet_ntop 3 , -instead of a host name. -.It Dv NI_NAMEREQD -A name is required. -If the host name cannot be found in DNS and this flag is set, -a non-zero error code is returned. -If the host name is not found and the flag is not set, the -address is returned in numeric form. -.It NI_NUMERICSERV -The service name is returned as a digit string representing the port number. -.It NI_DGRAM -Specifies that the service being looked up is a datagram -service, and causes -.Xr getservbyport 3 -to be called with a second argument of -.Dq udp -instead of its default of -.Dq tcp . -This is required for the few ports (512\-514) that have different services -for -.Tn UDP -and -.Tn TCP . -.El -.Pp -This implementation allows numeric IPv6 address notation with scope identifier, -as documented in RFC 4007. -IPv6 link-local address will appear as a string like -.Dq Li fe80::1%ne0 . -Refer to -.Xr getaddrinfo 3 -for more information. -.Sh RETURN VALUES -.Fn getnameinfo -returns zero on success or one of the error codes listed in -.Xr gai_strerror 3 -if an error occurs. -.Sh EXAMPLES -The following code tries to get a numeric host name, and service name, -for a given socket address. -Observe that there is no hardcoded reference to a particular address family. -.Bd -literal -offset indent -struct sockaddr *sa; /* input */ -char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; - -if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, - sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) - errx(1, "could not get numeric hostname"); -printf("host=%s, serv=%s\en", hbuf, sbuf); -.Ed -.Pp -The following version checks if the socket address has a reverse address mapping: -.Bd -literal -offset indent -struct sockaddr *sa; /* input */ -char hbuf[NI_MAXHOST]; - -if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, - NI_NAMEREQD)) - errx(1, "could not resolve hostname"); -printf("host=%s\en", hbuf); -.Ed -.Sh SEE ALSO -.Xr gai_strerror 3 , -.Xr getaddrinfo 3 , -.Xr gethostbyaddr 3 , -.Xr getservbyport 3 , -.Xr inet_ntop 3 , -.Xr res_init 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr services 5 , -.Xr hostname 7 -.Rs -.%A Craig Metz -.%T Protocol Independence Using the Sockets API -.%B Proceedings of the Freenix Track: 2000 USENIX Annual Technical Conference -.%D June 2000 -.Re -.Sh STANDARDS -The -.Fn getnameinfo -function is defined by the -.St -p1003.1g-2000 -draft specification and documented in RFC 3493. -.Pp -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%D February 2003 -.%R RFC 3493 -.%T Basic Socket Interface Extensions for IPv6 -.Re -.Pp -.Rs -.%A S. Deering -.%A B. Haberman -.%A T. Jinmei -.%A E. Nordmark -.%A B. Zill -.%D March 2005 -.%R RFC 4007 -.%T IPv6 Scoped Address Architecture -.Re -.Sh CAVEATS -.Fn getnameinfo -can return both numeric and FQDN forms of the address specified in -.Fa sa . -There is no return value that indicates whether the string returned in -.Fa host -is a result of binary to numeric-text translation (like -.Xr inet_ntop 3 ) , -or is the result of a DNS reverse lookup. -Because of this, malicious parties could set up a PTR record as follows: -.Bd -literal -offset indent -1.0.0.127.in-addr.arpa. IN PTR 10.1.1.1 -.Ed -.Pp -and trick the caller of -.Fn getnameinfo -into believing that -.Fa sa -is -.Li 10.1.1.1 -when it is actually -.Li 127.0.0.1 . -.Pp -To prevent such attacks, the use of -.Dv NI_NAMEREQD -is recommended when the result of -.Fn getnameinfo -is used -for access control purposes: -.Bd -literal -offset indent -struct sockaddr *sa; -char addr[NI_MAXHOST]; -struct addrinfo hints, *res; -int error; - -error = getnameinfo(sa, sa->sa_len, addr, sizeof(addr), - NULL, 0, NI_NAMEREQD); -if (error == 0) { - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_DGRAM; /*dummy*/ - hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(addr, "0", &hints, &res) == 0) { - /* malicious PTR record */ - freeaddrinfo(res); - printf("bogus PTR record\en"); - return -1; - } - /* addr is FQDN as a result of PTR lookup */ -} else { - /* addr is numeric string */ - error = getnameinfo(sa, sa->sa_len, addr, sizeof(addr), - NULL, 0, NI_NUMERICHOST); -} -.Ed -.Sh BUGS -The implementation of -.Fn getnameinfo -is not thread-safe. -.Pp -.Ox -intentionally uses a different -.Dv NI_MAXHOST -value from what -.Tn "RFC 2553" -suggests, to avoid buffer length handling mistakes. diff --git a/src/lib/libc/net/getnetent.3 b/src/lib/libc/net/getnetent.3 deleted file mode 100644 index da2c4ef4a3..0000000000 --- a/src/lib/libc/net/getnetent.3 +++ /dev/null @@ -1,147 +0,0 @@ -.\" $OpenBSD: getnetent.3,v 1.19 2019/08/30 20:20:51 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 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. 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. -.\" -.Dd $Mdocdate: August 30 2019 $ -.Dt GETNETENT 3 -.Os -.Sh NAME -.Nm getnetent , -.Nm getnetbyaddr , -.Nm getnetbyname , -.Nm setnetent , -.Nm endnetent -.Nd get network entry -.Sh SYNOPSIS -.In netdb.h -.Ft struct netent * -.Fn getnetent "void" -.Ft struct netent * -.Fn getnetbyname "const char *name" -.Ft struct netent * -.Fn getnetbyaddr "in_addr_t net" "int type" -.Ft void -.Fn setnetent "int stayopen" -.Ft void -.Fn endnetent "void" -.Sh DESCRIPTION -The -.Fn getnetbyname -and -.Fn getnetbyaddr -functions return a pointer to an object with the following structure: -.Bd -literal -offset indent -struct netent { - char *n_name; /* official name of net */ - char **n_aliases; /* alias list */ - int n_addrtype; /* net number type */ - in_addr_t n_net; /* net number */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width n_addrtype -.It Fa n_name -The official name of the network. -.It Fa n_aliases -A null-terminated list of alternate names for the network. -.It Fa n_addrtype -The type of the network number returned; it is always -.Dv AF_INET . -.It Fa n_net -The network number. -Network numbers are returned in machine byte order. -.El -.Pp -On -.Ox , -these legacy functions perform a lookup in a similar fashion as -.Xr gethostbyname 3 -and -.Xr gethostbyaddr 3 , -respectively. -On other systems, they may use a separate network database file, -.Pa /etc/networks . -.Pp -In contrast to -.Xr gethostbyaddr 3 , -the -.Fa net -argument is expected in machine byte order. -.Pp -The -.Fn setnetent , -.Fn getnetent , -and -.Fn endnetent -functions are deprecated and no longer have any effect. -They could be used in the past to iterate over entries in the former file -.Pa /etc/networks . -.Sh RETURN VALUES -The -.Fn getnetbyaddr -and -.Fn getnetbyname -functions return -.Dv NULL -if the requested entry is not found. -.Pp -The -.Fn getnetent -function always returns -.Dv NULL . -.Sh FILES -.Bl -tag -width /etc/hosts -compact -.It Pa /etc/hosts -The local host and network name database. -.El -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr gethostbyname 3 , -.Xr getnameinfo 3 , -.Xr res_init 3 , -.Xr hosts 5 -.Sh STANDARDS -These functions conform to -.St -p1003.1-2008 . -.Sh HISTORY -The -.Fn getnetent , -.Fn getnetbyaddr , -.Fn getnetbyname , -.Fn setnetent , -and -.Fn endnetent -functions appeared in -.Bx 4.2 . -.Sh BUGS -The data space used by these functions is static; if future use -requires the data, it should be copied before any subsequent calls -to these functions overwrite it. -Only Internet network numbers are currently understood. -Expecting network numbers to fit in no more than 32 bits is naive. diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c deleted file mode 100644 index b93e442fa9..0000000000 --- a/src/lib/libc/net/getnetent.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: getnetent.c,v 1.18 2018/04/28 15:05:40 schwarze Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include - -void -setnetent(int f) -{ -} - -void -endnetent(void) -{ -} - -struct netent * -getnetent(void) -{ - h_errno = NETDB_INTERNAL; - return NULL; -} diff --git a/src/lib/libc/net/getpeereid.3 b/src/lib/libc/net/getpeereid.3 deleted file mode 100644 index 4475bbd77d..0000000000 --- a/src/lib/libc/net/getpeereid.3 +++ /dev/null @@ -1,121 +0,0 @@ -.\" $OpenBSD: getpeereid.3,v 1.4 2022/09/11 06:38:10 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 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. 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. -.Dd $Mdocdate: September 11 2022 $ -.Dt GETPEEREID 3 -.Os -.Sh NAME -.Nm getpeereid -.Nd get effective user and group identification of locally-connected peer -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.Ft int -.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid" -.Sh DESCRIPTION -.Fn getpeereid -returns the effective user ID and group ID of the peer connected to -a -.Ux Ns -domain -socket (see -.Xr unix 4 ) . -The argument -.Fa s -must be of type -.Dv SOCK_STREAM -or -.Dv SOCK_SEQPACKET . -.Pp -One common use is for -.Ux Ns -domain -servers to determine the credentials of clients that have connected to it. -.Pp -.Fn getpeereid -takes three parameters: -.Bl -bullet -.It -.Fa s -contains the file descriptor of the socket whose peer credentials -should be looked up. -.It -.Fa euid -points to a -.Vt uid_t -variable into which the effective user ID for the connected peer will -be stored. -.It -.Fa egid -points to a -.Vt gid_t -variable into which the effective group ID for the connected peer will -be stored. -.El -.Sh RETURN VALUES -If the call succeeds, a 0 is returned and -.Fa euid -and -.Fa egid -are set to the effective user ID and group ID of the connected peer. -Otherwise, -.Va errno -is set and a value of \-1 is returned. -.Sh ERRORS -On failure, -.Va errno -is set to one of the following: -.Bl -tag -width Er -.It Bq Er EBADF -The argument -.Fa s -is not a valid descriptor. -.It Bq Er ENOTSOCK -The argument -.Fa s -is a file, not a socket. -.It Bq Er EOPNOTSUPP -The socket is not in the -.Ux Ns -domain . -.It Bq Er ENOTCONN -The socket is not connected. -.It Bq Er ENOBUFS -Insufficient resources were available in the system -to perform the operation. -.El -.Sh SEE ALSO -.Xr accept 2 , -.Xr bind 2 , -.Xr getpeername 2 , -.Xr getsockname 2 , -.Xr getsockopt 2 , -.Xr socket 2 , -.Xr unix 4 -.Sh HISTORY -The -.Fn getpeereid -function call appeared in -.Ox 3.0 . diff --git a/src/lib/libc/net/getpeereid.c b/src/lib/libc/net/getpeereid.c deleted file mode 100644 index 208e541f17..0000000000 --- a/src/lib/libc/net/getpeereid.c +++ /dev/null @@ -1,36 +0,0 @@ -/* $OpenBSD: getpeereid.c,v 1.1 2010/07/01 19:15:30 deraadt Exp $ */ - -/* - * Copyright (c) 2010 Theo de Raadt - * - * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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. - */ - -#include -#include - -int -getpeereid(int s, uid_t *euid, gid_t *egid) -{ - struct sockpeercred creds; - socklen_t credslen = sizeof(creds); - int error; - - error = getsockopt(s, SOL_SOCKET, SO_PEERCRED, - &creds, &credslen); - if (error) - return (error); - *euid = creds.uid; - *egid = creds.gid; - return (0); -} diff --git a/src/lib/libc/net/getproto.c b/src/lib/libc/net/getproto.c deleted file mode 100644 index 8e080679d0..0000000000 --- a/src/lib/libc/net/getproto.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: getproto.c,v 1.8 2015/09/14 07:38:38 guenther Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include - -int -getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd) -{ - int error; - - setprotoent_r(pd->stayopen, pd); - while ((error = getprotoent_r(pe, pd)) == 0) - if (pe->p_proto == num) - break; - if (!pd->stayopen && pd->fp != NULL) { - (void)fclose(pd->fp); - pd->fp = NULL; - } - return (error); -} -DEF_WEAK(getprotobynumber_r); - -struct protoent * -getprotobynumber(int num) -{ - extern struct protoent_data _protoent_data; - static struct protoent proto; - - if (getprotobynumber_r(num, &proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} diff --git a/src/lib/libc/net/getprotoent.3 b/src/lib/libc/net/getprotoent.3 deleted file mode 100644 index cc2c69836a..0000000000 --- a/src/lib/libc/net/getprotoent.3 +++ /dev/null @@ -1,213 +0,0 @@ -.\" $OpenBSD: getprotoent.3,v 1.18 2013/06/05 03:39:23 tedu Exp $ -.\" -.\" Copyright (c) 1983, 1991, 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. 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. -.\" -.Dd $Mdocdate: June 5 2013 $ -.Dt GETPROTOENT 3 -.Os -.Sh NAME -.Nm getprotoent , -.Nm getprotoent_r , -.Nm getprotobynumber , -.Nm getprotobynumber_r , -.Nm getprotobyname , -.Nm getprotobyname_r , -.Nm setprotoent , -.Nm setprotoent_r , -.Nm endprotoent , -.Nm endprotoent_r -.Nd get protocol entry -.Sh SYNOPSIS -.In netdb.h -.Ft struct protoent * -.Fn getprotoent "void" -.Ft int -.Fn getprotoent_r "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft struct protoent * -.Fn getprotobyname "const char *name" -.Ft int -.Fn getprotobyname_r "const char *name" "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft struct protoent * -.Fn getprotobynumber "int proto" -.Ft int -.Fn getprotobynumber_r "int proto" "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft void -.Fn setprotoent "int stayopen" -.Ft void -.Fn setprotoent_r "int stayopen" "struct protoent_data *protoent_data" -.Ft void -.Fn endprotoent "void" -.Ft void -.Fn endprotoent_r "struct protoent_data *protoent_data" -.Sh DESCRIPTION -The -.Fn getprotoent , -.Fn getprotobyname , -and -.Fn getprotobynumber -functions each return a pointer to an object with the following structure -containing the broken-out fields of a line in the network protocol database, -.Pa /etc/protocols . -.Bd -literal -offset indent -.Pp -struct protoent { - char *p_name; /* official name of protocol */ - char **p_aliases; /* alias list */ - int p_proto; /* protocol number */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width p_aliases -.It Fa p_name -The official name of the protocol. -.It Fa p_aliases -A null-terminated list of alternate names for the protocol. -.It Fa p_proto -The protocol number. -.El -.Pp -The -.Fn getprotoent -function reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setprotoent -function opens and rewinds the file. -If the -.Fa stayopen -flag is non-zero, -the protocol database will not be closed after each call to -.Fn getprotobyname -or -.Fn getprotobynumber . -.Pp -The -.Fn endprotoent -function closes the file. -.Pp -The -.Fn getprotobyname -and -.Fn getprotobynumber -functions sequentially search from the beginning of the file until a -matching protocol name or protocol number is found, or until -.Dv EOF -is encountered. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions are reentrant versions of the above functions that take a -pointer to a -.Vt protoent_data -structure which is used to store state information. -The structure must be zero-filled before it is used -and should be considered opaque for the sake of portability. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -and -.Fn getprotobyname_r -functions -also take a pointer to a -.Vt protoent -structure which is used to store the results of the database lookup. -.Sh RETURN VALUES -The -.Fn getprotoent , -.Fn getprotobyport , -and -.Fn getprotobyname -functions return a pointer to a -.Vt protoent -structure on success or a null pointer if end-of-file -is reached or an error occurs. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -and -.Fn getprotobyname_r -functions return 0 on success or \-1 if end-of-file -is reached or an error occurs. -.Sh FILES -.Bl -tag -width /etc/protocols -compact -.It Pa /etc/protocols -.El -.Sh SEE ALSO -.Xr protocols 5 -.Sh STANDARDS -The -.Fn getprotoent , -.Fn getprotobynumber , -.Fn getprotobyname , -.Fn setprotoent , -and -.Fn endprotoent -functions conform to -.St -p1003.1-2004 . -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions are not currently standardized. -This implementation follows the API used by HP, IBM, and Digital. -.Sh HISTORY -The -.Fn getprotoent , -.Fn getprotobynumber , -.Fn getprotobyname , -.Fn setprotoent , -and -.Fn endprotoent -functions appeared in -.Bx 4.2 . -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions appeared in -.Ox 3.7 . -.Sh BUGS -The non-reentrant functions use a static data space; if the data is needed -for future use, it should be copied before any subsequent calls overwrite it. -Only the Internet protocols are currently understood. diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c deleted file mode 100644 index a218863d07..0000000000 --- a/src/lib/libc/net/getprotoent.c +++ /dev/null @@ -1,169 +0,0 @@ -/* $OpenBSD: getprotoent.c,v 1.13 2015/09/14 07:38:38 guenther Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -void -setprotoent_r(int f, struct protoent_data *pd) -{ - if (pd->fp == NULL) - pd->fp = fopen(_PATH_PROTOCOLS, "re" ); - else - rewind(pd->fp); - pd->stayopen |= f; -} -DEF_WEAK(setprotoent_r); - -void -endprotoent_r(struct protoent_data *pd) -{ - if (pd->fp) { - fclose(pd->fp); - pd->fp = NULL; - } - free(pd->aliases); - pd->aliases = NULL; - pd->maxaliases = 0; - free(pd->line); - pd->line = NULL; - pd->stayopen = 0; -} -DEF_WEAK(endprotoent_r); - -int -getprotoent_r(struct protoent *pe, struct protoent_data *pd) -{ - char *p, *cp, **q, *endp; - size_t len; - long l; - int serrno; - - if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "re" )) == NULL) - return (-1); -again: - if ((p = fgetln(pd->fp, &len)) == NULL) - return (-1); - if (len == 0 || *p == '#' || *p == '\n') - goto again; - if (p[len-1] == '\n') - len--; - if ((cp = memchr(p, '#', len)) != NULL) - len = cp - p; - cp = realloc(pd->line, len + 1); - if (cp == NULL) - return (-1); - pd->line = pe->p_name = memcpy(cp, p, len); - cp[len] = '\0'; - cp = strpbrk(cp, " \t"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - l = strtol(cp, &endp, 10); - if (endp == cp || *endp != '\0' || l < 0 || l >= INT_MAX) - goto again; - pe->p_proto = l; - if (pd->aliases == NULL) { - pd->maxaliases = 5; - pd->aliases = calloc(pd->maxaliases, sizeof(char *)); - if (pd->aliases == NULL) { - serrno = errno; - endprotoent_r(pd); - errno = serrno; - return (-1); - } - } - q = pe->p_aliases = pd->aliases; - if (p != NULL) { - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q == &pe->p_aliases[pd->maxaliases - 1]) { - p = reallocarray(pe->p_aliases, - pd->maxaliases, 2 * sizeof(char *)); - if (p == NULL) { - serrno = errno; - endprotoent_r(pd); - errno = serrno; - return (-1); - } - pd->maxaliases *= 2; - q = (char **)p + (q - pe->p_aliases); - pe->p_aliases = pd->aliases = (char **)p; - } - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - } - *q = NULL; - return (0); -} -DEF_WEAK(getprotoent_r); - -struct protoent_data _protoent_data; /* shared with getproto{,name}.c */ - -void -setprotoent(int f) -{ - setprotoent_r(f, &_protoent_data); -} - -void -endprotoent(void) -{ - endprotoent_r(&_protoent_data); -} - -struct protoent * -getprotoent(void) -{ - static struct protoent proto; - - if (getprotoent_r(&proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} diff --git a/src/lib/libc/net/getprotoname.c b/src/lib/libc/net/getprotoname.c deleted file mode 100644 index f6ed4c49b1..0000000000 --- a/src/lib/libc/net/getprotoname.c +++ /dev/null @@ -1,69 +0,0 @@ -/* $OpenBSD: getprotoname.c,v 1.8 2015/09/14 07:38:38 guenther Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include -#include - -int -getprotobyname_r(const char *name, struct protoent *pe, - struct protoent_data *pd) -{ - char **cp; - int error; - - setprotoent_r(pd->stayopen, pd); - while ((error = getprotoent_r(pe, pd)) == 0) { - if (strcmp(pe->p_name, name) == 0) - break; - for (cp = pe->p_aliases; *cp != 0; cp++) - if (strcmp(*cp, name) == 0) - goto found; - } -found: - if (!pd->stayopen && pd->fp != NULL) { - fclose(pd->fp); - pd->fp = NULL; - } - return (error); -} -DEF_WEAK(getprotobyname_r); - -struct protoent * -getprotobyname(const char *name) -{ - extern struct protoent_data _protoent_data; - static struct protoent proto; - - if (getprotobyname_r(name, &proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} -DEF_WEAK(getprotobyname); diff --git a/src/lib/libc/net/getrrsetbyname.3 b/src/lib/libc/net/getrrsetbyname.3 deleted file mode 100644 index 314f31665c..0000000000 --- a/src/lib/libc/net/getrrsetbyname.3 +++ /dev/null @@ -1,164 +0,0 @@ -.\" $OpenBSD: getrrsetbyname.3,v 1.22 2022/09/11 06:38:10 jmc Exp $ -.\" -.\" Copyright (C) 2000, 2001 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. -.\" -.Dd $Mdocdate: September 11 2022 $ -.Dt GETRRSETBYNAME 3 -.Os -.Sh NAME -.Nm freerrset , -.Nm getrrsetbyname -.Nd retrieve DNS records -.Sh SYNOPSIS -.In netdb.h -.Ft int -.Fn getrrsetbyname "const char *hostname" "unsigned int rdclass" \ -"unsigned int rdtype" "unsigned int flags" "struct rrsetinfo **res" -.Ft void -.Fn freerrset "struct rrsetinfo *rrset" -.Sh DESCRIPTION -.Fn getrrsetbyname -gets a set of resource records associated with a -.Fa hostname , -.Fa rdclass , -and -.Fa rdtype . -.Fa hostname -is a pointer to a NUL-terminated string. -The -.Fa flags -field is currently unused and must be zero. -.Pp -After a successful call to -.Fn getrrsetbyname , -.Fa *res -is a pointer to an -.Vt rrsetinfo -structure, containing a list of one or more -.Vt rdatainfo -structures containing resource records and potentially another list of -.Vt rdatainfo -structures containing SIG resource records associated with those records. -The members -.Li rri_rdclass -and -.Li rri_rdtype -are copied from the parameters. -.Li rri_ttl -and -.Li rri_name -are properties of the obtained rrset. -The resource records contained in -.Li rri_rdatas -and -.Li rri_sigs -are in uncompressed DNS wire format. -Properties of the rdataset are represented in the -.Li rri_flags -bitfield. -If the -.Dv RRSET_VALIDATED -bit is set, the data has been DNSSEC -validated and the signatures verified. -.Pp -The following structures are used: -.Bd -literal -offset indent -struct rdatainfo { - unsigned int rdi_length; /* length of data */ - unsigned char *rdi_data; /* record data */ -}; - -struct rrsetinfo { - unsigned int rri_flags; /* RRSET_VALIDATED ... */ - unsigned int rri_rdclass; /* class number */ - unsigned int rri_rdtype; /* RR type number */ - unsigned int rri_ttl; /* time to live */ - unsigned int rri_nrdatas; /* size of rdatas array */ - unsigned int rri_nsigs; /* size of sigs array */ - char *rri_name; /* canonical name */ - struct rdatainfo *rri_rdatas; /* individual records */ - struct rdatainfo *rri_sigs; /* individual signatures */ -}; -.Ed -.Pp -All of the information returned by -.Fn getrrsetbyname -is dynamically allocated: the -.Vt rrsetinfo -and -.Vt rdatainfo -structures, -and the canonical host name strings pointed to by the -.Vt rrsetinfo -structure. -Memory allocated for the dynamically allocated structures created by -a successful call to -.Fn getrrsetbyname -is released by -.Fn freerrset . -.Li rrset -is a pointer to a -.Vt struct rrsetinfo -created by a call to -.Fn getrrsetbyname . -.\" .Pp -.\" If the EDNS0 option is activated in -.\" .Xr resolv.conf 5 , -.\" .Fn getrrsetbyname -.\" will request DNSSEC authentication using the EDNS0 DNSSEC OK (DO) bit. -.Sh RETURN VALUES -.Fn getrrsetbyname -returns zero on success, and one of the following error -codes if an error occurred: -.Bl -tag -width ERRSET_NOMEMORY -.It Bq Er ERRSET_NONAME -The name does not exist. -.It Bq Er ERRSET_NODATA -The name exists, but does not have data of the desired type. -.It Bq Er ERRSET_NOMEMORY -Memory could not be allocated. -.It Bq Er ERRSET_INVAL -A parameter is invalid. -.It Bq Er ERRSET_FAIL -Other failure. -.El -.Sh SEE ALSO -.Xr res_init 3 , -.Xr resolv.conf 5 -.Sh HISTORY -.Fn getrrsetbyname -first appeared in -.Ox 3.0 . -The API first appeared in ISC BIND version 9. -.Sh AUTHORS -.An Jakob Schlyter Aq Mt jakob@openbsd.org -.Sh CAVEATS -The -.Dv RRSET_VALIDATED -flag in -.Li rri_flags -is set if the AD (authenticated data) bit in the DNS answer is -set. -This flag -.Em should not -be trusted unless the transport between the nameserver and the resolver -is secure (e.g. IPsec, trusted network, loopback communication). -.Sh BUGS -The data in -.Li *rdi_data -should be returned in uncompressed wire format. -Currently, the data is in compressed format and the caller can't -uncompress since it doesn't have the full message. diff --git a/src/lib/libc/net/getservbyname.c b/src/lib/libc/net/getservbyname.c deleted file mode 100644 index 80c7e62a41..0000000000 --- a/src/lib/libc/net/getservbyname.c +++ /dev/null @@ -1,72 +0,0 @@ -/* $OpenBSD: getservbyname.c,v 1.11 2015/09/14 07:38:38 guenther Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include -#include - -int -getservbyname_r(const char *name, const char *proto, struct servent *se, - struct servent_data *sd) -{ - char **cp; - int error; - - setservent_r(sd->stayopen, sd); - while ((error = getservent_r(se, sd)) == 0) { - if (strcmp(name, se->s_name) == 0) - goto gotname; - for (cp = se->s_aliases; *cp; cp++) - if (strcmp(name, *cp) == 0) - goto gotname; - continue; -gotname: - if (proto == 0 || strcmp(se->s_proto, proto) == 0) - break; - } - if (!sd->stayopen && sd->fp != NULL) { - fclose(sd->fp); - sd->fp = NULL; - } - return (error); -} -DEF_WEAK(getservbyname_r); - -struct servent * -getservbyname(const char *name, const char *proto) -{ - extern struct servent_data _servent_data; - static struct servent serv; - - if (getservbyname_r(name, proto, &serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} -DEF_WEAK(getservbyname); diff --git a/src/lib/libc/net/getservbyport.c b/src/lib/libc/net/getservbyport.c deleted file mode 100644 index 3584fbea3a..0000000000 --- a/src/lib/libc/net/getservbyport.c +++ /dev/null @@ -1,65 +0,0 @@ -/* $OpenBSD: getservbyport.c,v 1.8 2015/09/14 07:38:38 guenther Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include -#include - -int -getservbyport_r(int port, const char *proto, struct servent *se, - struct servent_data *sd) -{ - int error; - - setservent_r(sd->stayopen, sd); - while ((error = getservent_r(se, sd)) == 0) { - if (se->s_port != port) - continue; - if (proto == 0 || strcmp(se->s_proto, proto) == 0) - break; - } - if (!sd->stayopen && sd->fp != NULL) { - fclose(sd->fp); - sd->fp = NULL; - } - return (error); -} -DEF_WEAK(getservbyport_r); - -struct servent * -getservbyport(int port, const char *proto) -{ - extern struct servent_data _servent_data; - static struct servent serv; - - if (getservbyport_r(port, proto, &serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} diff --git a/src/lib/libc/net/getservent.3 b/src/lib/libc/net/getservent.3 deleted file mode 100644 index 29dd3eb5f4..0000000000 --- a/src/lib/libc/net/getservent.3 +++ /dev/null @@ -1,220 +0,0 @@ -.\" $OpenBSD: getservent.3,v 1.21 2013/06/05 03:39:23 tedu Exp $ -.\" -.\" Copyright (c) 1983, 1991, 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. 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. -.\" -.Dd $Mdocdate: June 5 2013 $ -.Dt GETSERVENT 3 -.Os -.Sh NAME -.Nm getservent , -.Nm getservent_r , -.Nm getservbyport , -.Nm getservbyport_r , -.Nm getservbyname , -.Nm getservbyname_r , -.Nm setservent , -.Nm setservent_r , -.Nm endservent , -.Nm endservent_r -.Nd get service entry -.Sh SYNOPSIS -.In netdb.h -.Ft struct servent * -.Fn getservent "void" -.Ft int -.Fn getservent_r "struct servent *servent" "struct servent_data *servent_data" -.Ft struct servent * -.Fn getservbyname "const char *name" "const char *proto" -.Ft int -.Fn getservbyname_r "const char *name" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" -.Ft struct servent * -.Fn getservbyport "int port" "const char *proto" -.Ft int -.Fn getservbyport_r "int port" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" -.Ft void -.Fn setservent "int stayopen" -.Ft void -.Fn setservent_r "int stayopen" "struct servent_data *servent_data" -.Ft void -.Fn endservent "void" -.Ft void -.Fn endservent_r "struct servent_data *servent_data" -.Sh DESCRIPTION -The -.Fn getservent , -.Fn getservbyname , -and -.Fn getservbyport -functions each return a pointer to an object with the following structure -containing the broken-out fields of a line in the network services database, -.Pa /etc/services . -.Bd -literal -offset indent -struct servent { - char *s_name; /* official name of service */ - char **s_aliases; /* alias list */ - int s_port; /* port service resides at */ - char *s_proto; /* protocol to use */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width s_aliases -.It Fa s_name -The official name of the service. -.It Fa s_aliases -A null-terminated list of alternate names for the service. -.It Fa s_port -The port number at which the service resides. -Port numbers are returned in network byte order. -.It Fa s_proto -The name of the protocol to use when contacting the service. -.El -.Pp -The -.Fn getservent -function reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setservent -function opens and rewinds the file. -If the -.Fa stayopen -flag is non-zero, -the services database will not be closed after each call to -.Fn getservbyname -or -.Fn getservbyport . -.Pp -The -.Fn endservent -function closes the file. -.Pp -The -.Fn getservbyname -and -.Fn getservbyport -functions sequentially search from the beginning of the file until a -matching protocol name or port number (specified in network byte order) -is found, or until -.Dv EOF -is encountered. -If a protocol name is also supplied (non-null), -searches must also match the protocol. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions are reentrant versions of the above functions that take a -pointer to a -.Fa servent_data -structure which is used to store state information. -The structure must be zero-filled before it is used -and should be considered opaque for the sake of portability. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -and -.Fn getservbyname_r -functions -also take a pointer to a -.Fa servent -structure which is used to store the results of the database lookup. -.Sh RETURN VALUES -The -.Fn getservent , -.Fn getservbyport , -and -.Fn getservbyname -functions return a pointer to a -.Fa servent -structure on success or a null pointer if end-of-file -is reached or an error occurs. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -and -.Fn getservbyname_r -functions return 0 on success or \-1 if end-of-file -is reached or an error occurs. -.Sh FILES -.Bl -tag -width /etc/services -compact -.It Pa /etc/services -.El -.Sh SEE ALSO -.Xr getprotoent 3 , -.Xr services 5 -.Sh STANDARDS -The -.Fn getservent , -.Fn getservbynumber , -.Fn getservbyname , -.Fn setservent , -and -.Fn endservent -functions conform to -.St -p1003.1-2004 . -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions are not currently standardized. -This implementation follows the API used by HP, IBM, and Digital. -.Sh HISTORY -The -.Fn getservent , -.Fn getservbyport , -.Fn getservbyname , -.Fn setservent , -and -.Fn endservent -functions appeared in -.Bx 4.2 . -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions appeared in -.Ox 3.7 . -.Sh BUGS -The non-reentrant functions use static data storage; if the data is needed -for future use, it should be copied before any subsequent calls overwrite it. -Expecting port numbers to fit in a 32-bit quantity is probably naive. diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c deleted file mode 100644 index 220a5851ce..0000000000 --- a/src/lib/libc/net/getservent.c +++ /dev/null @@ -1,171 +0,0 @@ -/* $OpenBSD: getservent.c,v 1.15 2015/09/14 07:38:38 guenther Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -void -setservent_r(int f, struct servent_data *sd) -{ - if (sd->fp == NULL) - sd->fp = fopen(_PATH_SERVICES, "re" ); - else - rewind(sd->fp); - sd->stayopen |= f; -} -DEF_WEAK(setservent_r); - -void -endservent_r(struct servent_data *sd) -{ - if (sd->fp) { - fclose(sd->fp); - sd->fp = NULL; - } - free(sd->aliases); - sd->aliases = NULL; - sd->maxaliases = 0; - free(sd->line); - sd->line = NULL; - sd->stayopen = 0; -} -DEF_WEAK(endservent_r); - -int -getservent_r(struct servent *se, struct servent_data *sd) -{ - char *p, *cp, **q, *endp; - size_t len; - long l; - int serrno; - - if (sd->fp == NULL && (sd->fp = fopen(_PATH_SERVICES, "re" )) == NULL) - return (-1); -again: - if ((p = fgetln(sd->fp, &len)) == NULL) - return (-1); - if (len == 0 || *p == '#' || *p == '\n') - goto again; - if (p[len-1] == '\n') - len--; - if ((cp = memchr(p, '#', len)) != NULL) - len = cp - p; - cp = realloc(sd->line, len + 1); - if (cp == NULL) - return (-1); - sd->line = se->s_name = memcpy(cp, p, len); - cp[len] = '\0'; - p = strpbrk(cp, " \t"); - if (p == NULL) - goto again; - *p++ = '\0'; - while (*p == ' ' || *p == '\t') - p++; - cp = strpbrk(p, ",/"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - l = strtol(p, &endp, 10); - if (endp == p || *endp != '\0' || l < 0 || l > USHRT_MAX) - goto again; - se->s_port = htons((in_port_t)l); - se->s_proto = cp; - if (sd->aliases == NULL) { - sd->maxaliases = 10; - sd->aliases = calloc(sd->maxaliases, sizeof(char *)); - if (sd->aliases == NULL) { - serrno = errno; - endservent_r(sd); - errno = serrno; - return (-1); - } - } - q = se->s_aliases = sd->aliases; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q == &se->s_aliases[sd->maxaliases - 1]) { - p = reallocarray(se->s_aliases, sd->maxaliases, - 2 * sizeof(char *)); - if (p == NULL) { - serrno = errno; - endservent_r(sd); - errno = serrno; - return (-1); - } - sd->maxaliases *= 2; - q = (char **)p + (q - se->s_aliases); - se->s_aliases = sd->aliases = (char **)p; - } - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (0); -} -DEF_WEAK(getservent_r); - -struct servent_data _servent_data; /* shared with getservby{name,port}.c */ - -void -setservent(int f) -{ - setservent_r(f, &_servent_data); -} - -void -endservent(void) -{ - endservent_r(&_servent_data); -} - -struct servent * -getservent(void) -{ - static struct servent serv; - - if (getservent_r(&serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} diff --git a/src/lib/libc/net/herror.c b/src/lib/libc/net/herror.c deleted file mode 100644 index 356c85fa1d..0000000000 --- a/src/lib/libc/net/herror.c +++ /dev/null @@ -1,106 +0,0 @@ -/* $OpenBSD: herror.c,v 1.10 2015/09/14 07:38:38 guenther Exp $ */ - -/* - * ++Copyright++ 1987, 1993 - * - - * Copyright (c) 1987, 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. 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. - * - - * --Copyright-- - */ - -#include -#include -#include -#include -#include - -const char * const h_errlist[] = { - "Resolver Error 0 (no error)", - "Unknown host", /* 1 HOST_NOT_FOUND */ - "Host name lookup failure", /* 2 TRY_AGAIN */ - "Unknown server error", /* 3 NO_RECOVERY */ - "No address associated with name", /* 4 NO_ADDRESS */ -}; -const int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; - -extern int h_errno; - -/* - * herror -- - * print the error indicated by the h_errno value. - */ -void -herror(const char *s) -{ - struct iovec iov[4]; - struct iovec *v = iov; - - if (s && *s) { - v->iov_base = (char *)s; - v->iov_len = strlen(s); - v++; - v->iov_base = ": "; - v->iov_len = 2; - v++; - } - v->iov_base = (char *)hstrerror(h_errno); - v->iov_len = strlen(v->iov_base); - v++; - v->iov_base = "\n"; - v->iov_len = 1; - writev(STDERR_FILENO, iov, (v - iov) + 1); -} - -const char * -hstrerror(int err) -{ - if (err < 0) - return ("Resolver internal error"); - else if (err < h_nerr) - return (h_errlist[err]); - return ("Unknown resolver error"); -} -DEF_WEAK(hstrerror); diff --git a/src/lib/libc/net/htobe64.3 b/src/lib/libc/net/htobe64.3 deleted file mode 100644 index e41c9124c4..0000000000 --- a/src/lib/libc/net/htobe64.3 +++ /dev/null @@ -1,164 +0,0 @@ -.\" $OpenBSD: htobe64.3,v 1.2 2024/08/03 23:06:56 guenther Exp $ -.\" -.\" Copyright (c) 1983, 1991, 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. 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. -.\" -.Dd $Mdocdate: August 3 2024 $ -.Dt HTOBE64 3 -.Os -.Sh NAME -.Nm htobe64 , -.Nm htobe32 , -.Nm htobe16 , -.Nm be64toh , -.Nm be32toh , -.Nm be16toh , -.Nm betoh64 , -.Nm betoh32 , -.Nm betoh16 , -.Nm htole64 , -.Nm htole32 , -.Nm htole16 , -.Nm le64toh , -.Nm le32toh , -.Nm le16toh , -.Nm letoh64 , -.Nm letoh32 , -.Nm letoh16 , -.Nm swap64 , -.Nm swap32 , -.Nm swap16 -.Nd convert values between different byte orderings -.Sh SYNOPSIS -.In endian.h -.Ft uint64_t -.Fn htobe64 "uint64_t host64" -.Ft uint32_t -.Fn htobe32 "uint32_t host32" -.Ft uint16_t -.Fn htobe16 "uint16_t host16" -.Ft uint64_t -.Fn be64toh "uint64_t big64" -.Ft uint32_t -.Fn be32toh "uint32_t big32" -.Ft uint16_t -.Fn be16toh "uint16_t big16" -.Ft uint64_t -.Fn betoh64 "uint64_t big64" -.Ft uint32_t -.Fn betoh32 "uint32_t big32" -.Ft uint16_t -.Fn betoh16 "uint16_t big16" -.Ft uint64_t -.Fn htole64 "uint64_t host64" -.Ft uint32_t -.Fn htole32 "uint32_t host32" -.Ft uint16_t -.Fn htole16 "uint16_t host16" -.Ft uint64_t -.Fn letoh64 "uint64_t little64" -.Ft uint64_t -.Fn le64toh "uint64_t little64" -.Ft uint32_t -.Fn le32toh "uint32_t little32" -.Ft uint16_t -.Fn le16toh "uint16_t little16" -.Ft uint32_t -.Fn letoh32 "uint32_t little32" -.Ft uint16_t -.Fn letoh16 "uint16_t little16" -.Ft uint64_t -.Fn swap64 "uint64_t val64" -.Ft uint32_t -.Fn swap32 "uint32_t val32" -.Ft uint16_t -.Fn swap16 "uint16_t val16" -.Sh DESCRIPTION -These routines convert 16, 32 and 64-bit quantities between different -byte orderings. -The -.Dq swap -functions reverse the byte ordering of -the given quantity; the others convert either from/to the native -byte order used by the host to/from either little- or big-endian (a.k.a -network) order. -.Pp -Apart from the swap functions, -the names containing -.Dq be -convert between host and big-endian (most significant byte first) order -of the given quantity, while the names containing -.Dq le -convert between host and little-endian (least significant byte first) order -of the given quantity. -.Pp -All these functions use the numbers -16, 32, or 64 for specifying the bitwidth of the quantities they operate on. -Currently all supported architectures are either big- or little-endian -so either the -.Dq be -or -.Dq le -variants are implemented as null macros. -.Sh SEE ALSO -.Xr htonl 3 -.Sh STANDARDS -The -.Fn htobe64 , -.Fn htobe32 , -.Fn htobe16 , -.Fn be64toh , -.Fn be32toh , -.Fn be16toh , -.Fn htole64 , -.Fn htole32 , -.Fn htole16 , -.Fn le64toh , -.Fn le32toh , -and -.Fn le16toh -functions conform to -.St -p1003.1-2024 . -The other functions are extensions that should not be used -when portability is required. -.Sh HISTORY -The -.Nm swap{size} -and -.Nm {src-order}to{dst-order}{size} -functions appeared in -.Bx 4.2 . -The -.Nm {src-order}{size}to{dst-order} -functions appeared in -.Ox 5.6 . -.Sh BUGS -The perceived antagonism between -.Sq host -and -.Sq network -byte order does not allow PDP-11 users to sleep soundly at night. diff --git a/src/lib/libc/net/htonl.3 b/src/lib/libc/net/htonl.3 deleted file mode 100644 index 65fa9a53b5..0000000000 --- a/src/lib/libc/net/htonl.3 +++ /dev/null @@ -1,102 +0,0 @@ -.\" $OpenBSD: htonl.3,v 1.6 2022/09/11 06:38:10 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 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. 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. -.\" -.Dd $Mdocdate: September 11 2022 $ -.Dt HTONL 3 -.Os -.Sh NAME -.Nm htonl , -.Nm htons , -.Nm ntohl , -.Nm ntohs -.Nd convert values between host and network byte orderings -.Sh SYNOPSIS -.In arpa/inet.h -.Ft uint32_t -.Fn htonl "uint32_t host32" -.Ft uint16_t -.Fn htons "uint16_t host16" -.Ft uint32_t -.Fn ntohl "uint32_t net32" -.Ft uint16_t -.Fn ntohs "uint16_t net16" -.Sh DESCRIPTION -These routines convert 16 and 32-bit quantities between different -byte orderings. -.Pp -The -.Fn htonl -and -.Fn htons -functions convert quantities from host to network byte order while the -.Fn ntohl -and -.Fn ntohs -functions convert in the other direction. -.Pp -The last letter -.Pf ( Sq s -or -.Sq l ) -is a mnemonic -for the traditional names for such quantities, -short and long, respectively. -Today, the C concept of -.Vt short -and -.Vt long -integers need not coincide with this traditional misunderstanding. -On machines which have a byte order which is the same as the network -order, routines are defined as null macros. -.Pp -These routines are most often used in conjunction with Internet -addresses and ports as returned by -.Xr gethostbyname 3 -and -.Xr getservent 3 . -.Sh SEE ALSO -.Xr gethostbyname 3 , -.Xr getservent 3 , -.Xr htobe64 3 -.Sh STANDARDS -The -.Fn htonl , -.Fn htons , -.Fn ntohl , -and -.Fn ntohs -functions conform to -.St -p1003.1 . -.Sh HISTORY -These functions appeared in -.Bx 4.2 . -.Sh BUGS -On the alpha, amd64, i386, and some mips and arm architectures, -bytes are handled backwards from most everyone else in the world. -This is not expected to be fixed in the near future. diff --git a/src/lib/libc/net/htonl.c b/src/lib/libc/net/htonl.c deleted file mode 100644 index 58bfb4699a..0000000000 --- a/src/lib/libc/net/htonl.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: htonl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */ -/* - * Public domain. - */ - -#include -#include - -#undef htonl - -uint32_t -htonl(uint32_t x) -{ - return htobe32(x); -} diff --git a/src/lib/libc/net/htons.c b/src/lib/libc/net/htons.c deleted file mode 100644 index 28b13cef98..0000000000 --- a/src/lib/libc/net/htons.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: htons.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */ -/* - * Public domain. - */ - -#include -#include - -#undef htons - -uint16_t -htons(uint16_t x) -{ - return htobe16(x); -} diff --git a/src/lib/libc/net/if_indextoname.3 b/src/lib/libc/net/if_indextoname.3 deleted file mode 100644 index 25d2a2722f..0000000000 --- a/src/lib/libc/net/if_indextoname.3 +++ /dev/null @@ -1,143 +0,0 @@ -.\" $OpenBSD: if_indextoname.3,v 1.16 2015/11/21 07:48:10 jmc Exp $ -.\" Copyright (c) 1983, 1991, 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. 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. -.\" -.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd $Mdocdate: November 21 2015 $ -.Dt IF_NAMETOINDEX 3 -.Os -.Sh NAME -.Nm if_nametoindex , -.Nm if_indextoname , -.Nm if_nameindex , -.Nm if_freenameindex -.Nd convert interface index to name, and vice versa -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In net/if.h -.Ft "unsigned int" -.Fn if_nametoindex "const char *ifname" -.Ft "char *" -.Fn if_indextoname "unsigned int ifindex" "char *ifname" -.Ft "struct if_nameindex *" -.Fn if_nameindex "void" -.Ft "void" -.Fn if_freenameindex "struct if_nameindex *ptr" -.Sh DESCRIPTION -These functions map interface indexes to interface names (such as -.Dq lo0 ) , -and vice versa. -.Pp -The -.Fn if_nametoindex -function converts an interface name specified by the -.Fa ifname -argument to an interface index (positive integer value). -If the specified interface does not exist, 0 will be returned. -.Pp -.Fn if_indextoname -converts an interface index specified by the -.Fa ifindex -argument to an interface name. -The -.Fa ifname -argument must point to a buffer of at least -.Dv IF_NAMESIZE -bytes into which the interface name corresponding to the specified index is -returned. -.Pf ( Dv IF_NAMESIZE -is also defined in -.In net/if.h -and its value includes a terminating NUL byte at the end of the -interface name.) -This pointer is also the return value of the function. -If there is no interface corresponding to the specified index, -.Dv NULL -is returned. -.Pp -.Fn if_nameindex -returns an array of -.Vt if_nameindex -structures. -.Vt if_nameindex -is also defined in -.In net/if.h , -and is as follows: -.Bd -literal -offset indent -struct if_nameindex { - unsigned int if_index; /* 1, 2, ... */ - char *if_name; /* NUL-terminated name */ -}; -.Ed -.Pp -The end of the array of structures is indicated by a structure with -an -.Fa if_index -of 0 and an -.Fa if_name -of -.Dv NULL . -The function returns a null pointer on error. -The memory used for this array of structures along with the interface -names pointed to by the -.Fa if_name -members is obtained dynamically. -This memory is freed by the -.Fn if_freenameindex -function. -.Pp -.Fn if_freenameindex -takes a pointer that was returned by -.Fn if_nameindex -as argument -.Pq Fa ptr , -and it reclaims the region allocated. -.Sh DIAGNOSTICS -.Fn if_nametoindex -returns 0 on error, positive integer on success. -.Fn if_indextoname -and -.Fn if_nameindex -return -.Dv NULL -on errors. -.Sh SEE ALSO -.Xr getifaddrs 3 , -.Xr netintro 4 -.Sh STANDARDS -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%D February 2003 -.%R RFC 3493 -.%T Basic Socket Interface Extensions for IPv6 -.Re diff --git a/src/lib/libc/net/if_indextoname.c b/src/lib/libc/net/if_indextoname.c deleted file mode 100644 index 3c6e8681fb..0000000000 --- a/src/lib/libc/net/if_indextoname.c +++ /dev/null @@ -1,78 +0,0 @@ -/* $OpenBSD: if_indextoname.c,v 1.12 2018/05/10 13:44:43 tb Exp $ */ -/* $KAME: if_indextoname.c,v 1.6 2000/11/07 22:33:25 jinmei Exp $ */ - -/*- - * Copyright (c) 2015 Claudio Jeker - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. 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. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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. - * - * BSDI Id: if_indextoname.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2553: - * - * The second function maps an interface index into its corresponding - * name. - * - * #include - * - * char *if_indextoname(unsigned int ifindex, char *ifname); - * - * The ifname argument must point to a buffer of at least IF_NAMESIZE - * bytes into which the interface name corresponding to the specified - * index is returned. (IF_NAMESIZE is also defined in and - * its value includes a terminating null byte at the end of the - * interface name.) This pointer is also the return value of the - * function. If there is no interface corresponding to the specified - * index, NULL is returned, and errno is set to ENXIO, if there was a - * system error (such as running out of memory), if_indextoname returns - * NULL and errno would be set to the proper value (e.g., ENOMEM). - */ - -char * -if_indextoname(unsigned int ifindex, char *ifname) -{ - struct if_nameindex *ifni, *ifni2; - - if ((ifni = if_nameindex()) == NULL) - return NULL; - - for (ifni2 = ifni; ifni2->if_index != 0; ifni2++) { - if (ifni2->if_index == ifindex) { - strlcpy(ifname, ifni2->if_name, IFNAMSIZ); - if_freenameindex(ifni); - return ifname; - } - } - - if_freenameindex(ifni); - errno = ENXIO; - return NULL; -} -DEF_WEAK(if_indextoname); diff --git a/src/lib/libc/net/if_nameindex.c b/src/lib/libc/net/if_nameindex.c deleted file mode 100644 index 6e5bc0809a..0000000000 --- a/src/lib/libc/net/if_nameindex.c +++ /dev/null @@ -1,145 +0,0 @@ -/* $OpenBSD: if_nameindex.c,v 1.13 2016/12/16 17:44:59 krw Exp $ */ -/* $KAME: if_nameindex.c,v 1.7 2000/11/24 08:17:20 itojun Exp $ */ - -/*- - * Copyright (c) 2015 Claudio Jeker - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. 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. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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. - * - * BSDI Id: if_nameindex.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2553: - * - * 4.3 Return All Interface Names and Indexes - * - * The if_nameindex structure holds the information about a single - * interface and is defined as a result of including the - * header. - * - * struct if_nameindex { - * unsigned int if_index; - * char *if_name; - * }; - * - * The final function returns an array of if_nameindex structures, one - * structure per interface. - * - * struct if_nameindex *if_nameindex(void); - * - * The end of the array of structures is indicated by a structure with - * an if_index of 0 and an if_name of NULL. The function returns a NULL - * pointer upon an error, and would set errno to the appropriate value. - * - * The memory used for this array of structures along with the interface - * names pointed to by the if_name members is obtained dynamically. - * This memory is freed by the next function. - * - * 4.4. Free Memory - * - * The following function frees the dynamic memory that was allocated by - * if_nameindex(). - * - * #include - * - * void if_freenameindex(struct if_nameindex *ptr); - * - * The argument to this function must be a pointer that was returned by - * if_nameindex(). - */ - -struct if_nameindex * -if_nameindex(void) -{ - struct if_nameindex_msg *ifnm = NULL; - struct if_nameindex *ifni = NULL, *ifni2; - char *cp; - size_t needed; - unsigned int ni, i; - int mib[6]; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; /* protocol */ - mib[3] = 0; /* not used */ - mib[4] = NET_RT_IFNAMES; - mib[5] = 0; /* no flags */ - while (1) { - struct if_nameindex_msg *buf = NULL; - - if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1) - goto out; - if (needed == 0) - break; - if ((buf = realloc(ifnm, needed)) == NULL) - goto out; - ifnm = buf; - if (sysctl(mib, 6, ifnm, &needed, NULL, 0) == -1) { - if (errno == ENOMEM) - continue; - goto out; - } - break; - } - - /* - * Allocate a chunk of memory, use the first part for the array of - * structures, and the last part for the strings. - */ - ni = needed / sizeof(*ifnm); - ifni = calloc(ni + 1, sizeof(struct if_nameindex) + IF_NAMESIZE); - if (ifni == NULL) - goto out; - cp = (char *)(ifni + (ni + 1)); - - ifni2 = ifni; - for (i = 0; i < ni; i++) { - ifni2->if_index = ifnm[i].if_index; - /* don't care about truncation */ - strlcpy(cp, ifnm[i].if_name, IF_NAMESIZE); - ifni2->if_name = cp; - ifni2++; - cp += IF_NAMESIZE; - } - /* Finally, terminate the array. */ - ifni2->if_index = 0; - ifni2->if_name = NULL; -out: - free(ifnm); - return ifni; -} - -void -if_freenameindex(struct if_nameindex *ptr) -{ - free(ptr); -} -DEF_WEAK(if_nameindex); -DEF_WEAK(if_freenameindex); diff --git a/src/lib/libc/net/if_nametoindex.c b/src/lib/libc/net/if_nametoindex.c deleted file mode 100644 index 7a4492e37d..0000000000 --- a/src/lib/libc/net/if_nametoindex.c +++ /dev/null @@ -1,77 +0,0 @@ -/* $OpenBSD: if_nametoindex.c,v 1.10 2015/10/23 13:09:19 claudio Exp $ */ -/* $KAME: if_nametoindex.c,v 1.5 2000/11/24 08:04:40 itojun Exp $ */ - -/*- - * Copyright (c) 2015 Claudio Jeker - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. 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. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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. - * - * BSDI Id: if_nametoindex.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2553: - * - * 4.1 Name-to-Index - * - * - * The first function maps an interface name into its corresponding - * index. - * - * #include - * - * unsigned int if_nametoindex(const char *ifname); - * - * If the specified interface name does not exist, the return value is - * 0, and errno is set to ENXIO. If there was a system error (such as - * running out of memory), the return value is 0 and errno is set to the - * proper value (e.g., ENOMEM). - */ - -unsigned int -if_nametoindex(const char *ifname) -{ - struct if_nameindex *ifni, *ifni2; - unsigned int index; - - if ((ifni = if_nameindex()) == NULL) - return(0); - - for (ifni2 = ifni; ifni2->if_index != 0; ifni2++) { - if (strcmp(ifni2->if_name, ifname) == 0) { - index = ifni2->if_index; - if_freenameindex(ifni); - return index; - } - } - - if_freenameindex(ifni); - errno = ENXIO; - return 0; -} -DEF_WEAK(if_nametoindex); diff --git a/src/lib/libc/net/inet6_opt_init.3 b/src/lib/libc/net/inet6_opt_init.3 deleted file mode 100644 index 41ba842166..0000000000 --- a/src/lib/libc/net/inet6_opt_init.3 +++ /dev/null @@ -1,328 +0,0 @@ -.\" $OpenBSD: inet6_opt_init.3,v 1.8 2022/03/31 17:27:16 naddy Exp $ -.\" $KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" 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. Neither the name of the project 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 PROJECT 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 PROJECT 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. -.\" -.Dd $Mdocdate: March 31 2022 $ -.Dt INET6_OPT_INIT 3 -.Os -.\" -.Sh NAME -.Nm inet6_opt_init , -.Nm inet6_opt_append , -.Nm inet6_opt_finish , -.Nm inet6_opt_set_val , -.Nm inet6_opt_next , -.Nm inet6_opt_find , -.Nm inet6_opt_get_val -.Nd IPv6 Hop-by-Hop and Destination Options manipulation -.\" -.Sh SYNOPSIS -.In netinet/in.h -.Ft "int" -.Fn inet6_opt_init "void *extbuf" "socklen_t extlen" -.Ft "int" -.Fn inet6_opt_append "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t len" "u_int8_t align" "void **databufp" -.Ft "int" -.Fn inet6_opt_finish "void *extbuf" "socklen_t extlen" "int offset" -.Ft "int" -.Fn inet6_opt_set_val "void *databuf" "int offset" "void *val" "socklen_t vallen" -.Ft "int" -.Fn inet6_opt_next "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t *typep" "socklen_t *lenp" "void **databufp" -.Ft "int" -.Fn inet6_opt_find "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t *lenp" "void **databufp" -.Ft "int" -.Fn inet6_opt_get_val "void *databuf" "socklen_t offset" "void *val" "socklen_t vallen" -.\" -.Sh DESCRIPTION -Building and parsing the Hop-by-Hop and Destination options is -complicated. -The advanced sockets API defines a set of functions to -help applications create and manipulate Hop-by-Hop and Destination -options. -These functions use the -formatting rules specified in Appendix B in RFC 2460, i.e. that the -largest field is placed last in the option. -The function prototypes -for these functions are all contained in the header file -.In netinet/in.h . -.\" -.Ss inet6_opt_init -The -.Fn inet6_opt_init -function -returns the number of bytes needed for an empty -extension header, one without any options. -If the -.Va extbuf -argument points to a valid section of memory -then the -.Fn inet6_opt_init -function also initializes the extension header's length field. -When attempting to initialize an extension buffer passed in the -.Va extbuf -argument, -.Fa extlen -must be a positive multiple of 8 or else the function fails and -returns \-1 to the caller. -.\" -.Ss inet6_opt_append -The -.Fn inet6_opt_append -function can perform different jobs. -When a valid -.Fa extbuf -argument is supplied, it appends an option to the extension buffer and -returns the updated total length as well as a pointer to the newly -created option in -.Fa databufp . -If the value -of -.Fa extbuf -is -.Dv NULL -then the -.Fn inet6_opt_append -function only reports what the total length would -be if the option were actually appended. -The -.Fa len -and -.Fa align -arguments specify the length of the option and the required data -alignment which must be used when appending the option. -The -.Fa offset -argument should be the length returned by the -.Fn inet6_opt_init -function or a previous call to -.Fn inet6_opt_append . -.Pp -The -.Fa type -argument is the 8-bit option type. -.Pp -After -.Fn inet6_opt_append -has been called, the application can use the buffer pointed to by -.Fa databufp -directly, or use -.Fn inet6_opt_set_val -to specify the data to be contained in the option. -.Pp -Option types of -.Li 0 -and -.Li 1 -are reserved for the -.Li Pad1 -and -.Li PadN -options. -All other values from 2 through 255 may be used by applications. -.Pp -The length of the option data is contained in an 8-bit value and so -may contain any value from 0 through 255. -.Pp -The -.Fa align -parameter must have a value of 1, 2, 4, or 8 and cannot exceed the -value of -.Fa len . -The alignment values represent no alignment, 16-bit, 32-bit and 64-bit -alignments respectively. -.\" -.Ss inet6_opt_finish -The -.Fn inet6_opt_finish -function calculates the final padding necessary to make the extension header a -multiple of 8 bytes, as required by the IPv6 extension header -specification, and returns the extension header's updated total -length. -The -.Fa offset -argument should be the length returned by -.Fn inet6_opt_init -or -.Fn inet6_opt_append . -When -.Fa extbuf -is not -.Dv NULL , -the function also sets up the appropriate padding bytes by inserting a -Pad1 or PadN option of the proper length. -.Pp -If the extension header is too small to contain the proper padding -then an error of \-1 is returned to the caller. -.\" -.Ss inet6_opt_set_val -The -.Fn inet6_opt_set_val -function inserts data items of various sizes into the data portion of -the option. -The -.Fa databuf -argument is a pointer to memory that was returned by the -.Fn inet6_opt_append -call and the -.Fa offset -argument specifies where the option should be placed in the -data buffer. -The -.Fa val -argument points to an area of memory containing the data to be -inserted into the extension header, and the -.Fa vallen -argument indicates how much data to copy. -.Pp -The caller should ensure that each field is aligned on its natural -boundaries as described in Appendix B of RFC 2460. -.Pp -The function returns the offset for the next field which is calculated as -.Fa offset -+ -.Fa vallen -and is used when composing options with multiple fields. -.\" -.Ss inet6_opt_next -The -.Fn inet6_opt_next -function parses received extension headers. -The -.Fa extbuf -and -.Fa extlen -arguments specify the location and length of the extension header -being parsed. -The -.Fa offset -argument should either be zero, for the first option, or the length value -returned by a previous call to -.Fn inet6_opt_next -or -.Fn inet6_opt_find . -The return value specifies the position where to continue scanning the -extension buffer. -The option is returned in the arguments -.Fa typep , lenp , -and -.Fa databufp . -.Fa typep , lenp , -and -.Fa databufp -point to the 8-bit option type, the 8-bit option length and the option -data respectively. -This function does not return any PAD1 or PADN options. -When an error occurs or there are no more options, the return -value is \-1. -.\" -.Ss inet6_opt_find -The -.Fn inet6_opt_find -function searches the extension buffer for a particular option type, -passed in through the -.Fa type -argument. -If the option is found then the -.Fa lenp -and -.Fa databufp -arguments are updated to point to the option's length and data -respectively. -.Fa extbuf -and -.Fa extlen -must point to a valid extension buffer and give its length. -The -.Fa offset -argument can be used to search from a location anywhere in the -extension header. -.Ss inet6_opt_get_val -The -.Fn inet6_opt_get_val -function extracts data items of various sizes in the data portion of -the option. -The -.Fa databuf -is a pointer returned by the -.Fn inet6_opt_next -or -.Fn inet6_opt_find -functions. -The -.Fa val -argument points to where the data will be extracted. -The -.Fa offset -argument specifies from where in the data portion of the option the -value should be extracted; the first byte of option data is specified -by an offset of zero. -.Pp -It is expected that each field is aligned on its natural boundaries as -described in Appendix B of RFC 2460. -.Pp -The function returns the offset for the next field -by calculating -.Fa offset -+ -.Fa vallen -which can be used when extracting option content with multiple fields. -Robust receivers must verify alignment before calling this function. -.\" -.Sh EXAMPLES -RFC 3542 gives comprehensive examples in Section 23. -KAME also provides examples in the -.Pa advapitest -directory of its kit. -.\" -.Sh DIAGNOSTICS -All the functions return -\-1 -on an error. -.\" -.Sh STANDARDS -.Rs -.%A S. Deering -.%A R. Hinden -.%D December 1998 -.%R RFC 2460 -.%T Internet Protocol, Version 6 (IPv6) Specification -.Re -.Pp -.Rs -.%A W. Stevens -.%A M. Thomas -.%A E. Nordmark -.%A T. Jinmei -.%D May 2003 -.%R RFC 3542 -.%T Advanced Sockets Application Program Interface (API) for IPv6 -.Re -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. -.\" diff --git a/src/lib/libc/net/inet6_rth_space.3 b/src/lib/libc/net/inet6_rth_space.3 deleted file mode 100644 index c40b45057e..0000000000 --- a/src/lib/libc/net/inet6_rth_space.3 +++ /dev/null @@ -1,220 +0,0 @@ -.\" $OpenBSD: inet6_rth_space.3,v 1.8 2022/03/31 17:27:16 naddy Exp $ -.\" $KAME: inet6_rth_space.3,v 1.7 2005/01/05 03:00:44 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" 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. Neither the name of the project 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 PROJECT 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 PROJECT 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. -.\" -.Dd $Mdocdate: March 31 2022 $ -.Dt INET6_RTH_SPACE 3 -.Os -.\" -.Sh NAME -.Nm inet6_rth_space , -.Nm inet6_rth_init , -.Nm inet6_rth_add , -.Nm inet6_rth_reverse , -.Nm inet6_rth_segments , -.Nm inet6_rth_getaddr -.Nd IPv6 Routing Header Options manipulation -.\" -.Sh SYNOPSIS -.In netinet/in.h -.Ft socklen_t -.Fn inet6_rth_space "int" "int" -.Ft "void *" -.Fn inet6_rth_init "void *" "socklen_t" "int" "int" -.Ft int -.Fn inet6_rth_add "void *" "const struct in6_addr *" -.Ft int -.Fn inet6_rth_reverse "const void *" "void *" -.Ft int -.Fn inet6_rth_segments "const void *" -.Ft "struct in6_addr *" -.Fn inet6_rth_getaddr "const void *" "int" -.\" -.Sh DESCRIPTION -The IPv6 Advanced API, RFC 3542, defines the functions that an -application calls to build and examine IPv6 Routing headers. -Routing headers are used to perform source routing in IPv6 networks. -The RFC uses the word -.Dq segments -to describe addresses and that is the term used here as well. -All of the functions are defined in the header file -.In netinet/in.h . -The functions described in this manual page all operate -on routing header structures which are defined in -.In netinet/ip6.h -but which should not need to be modified outside the use of this API. -The size and shape of the route header structures may change, so using -the APIs is a more portable, long term, solution. -.Pp -The functions in the API are split into two groups, those that build a -routing header and those that parse a received routing header. -The builder functions are described first, followed by the parser functions. -.Ss inet6_rth_space -The -.Fn inet6_rth_space -function returns the number of bytes required to hold a Routing Header -of the type, specified in the -.Fa type -argument and containing the number of addresses specified in the -.Fa segments -argument. -When the type is -.Dv IPV6_RTHDR_TYPE_0 , -the number of segments must be from 0 through 127. -The return value from this function is the number of bytes required to -store the routing header. -If the value 0 is returned then either the -route header type was not recognized or another error occurred. -.Ss inet6_rth_init -The -.Fn inet6_rth_init -function initializes the pre-allocated buffer pointed to by -.Fa bp -to contain a routing header of the specified type. -The -.Fa bp_len -argument is used to verify that the buffer is large enough. -The caller must allocate the buffer pointed to by bp. -The necessary buffer size should be determined by calling -.Fn inet6_rth_space -described in the previous sections. -.Pp -The -.Fn inet6_rth_init -function returns a pointer to -.Fa bp -on success and -.Dv NULL -when there is an error. -.Ss inet6_rth_add -The -.Fn inet6_rth_add -function adds the IPv6 address pointed to by -.Fa addr -to the end of the routing header being constructed. -.Pp -A successful addition results in the function returning 0, otherwise -\-1 is returned. -.Ss inet6_rth_reverse -The -.Fn inet6_rth_reverse -function takes a routing header, pointed to by the -argument -.Fa in , -and writes a new routing header into the argument pointed to by -.Fa out . -The routing header at that sends datagrams along the reverse of that -route. -Both arguments are allowed to point to the same buffer meaning -that the reversal can occur in place. -.Pp -The return value of the function is 0 on success, or \-1 when -there is an error. -.\" -.Pp -The next set of functions operate on a routing header that the -application wants to parse. -In the usual case such a routing header -is received from the network, although these functions can also be -used with routing headers that the application itself created. -.Ss inet6_rth_segments -The -.Fn inet6_rth_segments -function returns the number of segments contained in the -routing header pointed to by -.Fa bp . -The return value is the number of segments contained in the routing -header, or \-1 if an error occurred. -It is not an error for 0 to be -returned as a routing header may contain 0 segments. -.\" -.Ss inet6_rth_getaddr -The -.Fn inet6_rth_getaddr -function is used to retrieve a single address from a routing header. -The -.Fa index -is the location in the routing header from which the application wants -to retrieve an address. -The -.Fa index -parameter must have a value between 0 and one less than the number of -segments present in the routing header. -The -.Fn inet6_rth_segments -function, described in the last section, should be used to determine -the total number of segments in the routing header. -The -.Fn inet6_rth_getaddr -function returns a pointer to an IPv6 address on success or -.Dv NULL -when an error has occurred. -.\" -.Sh EXAMPLES -RFC 3542 gives extensive examples in Section 21, Appendix B. -KAME also provides examples in the advapitest directory of its kit. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_rth_space -and -.Fn inet6_rth_getaddr -functions return 0 on errors. -.Pp -The -.Fn inet6_rth_init -function returns -.Dv NULL -on error. -The -.Fn inet6_rth_add -and -.Fn inet6_rth_reverse -functions return 0 on success, or \-1 upon an error. -.\" -.Sh STANDARDS -.Rs -.%A S. Deering -.%A R. Hinden -.%D December 1998 -.%R RFC 2460 -.%T Internet Protocol, Version 6 (IPv6) Specification -.Re -.Pp -.Rs -.%A W. Stevens -.%A M. Thomas -.%A E. Nordmark -.%A T. Jinmei -.%D May 2003 -.%R RFC 3542 -.%T Advanced Sockets Application Programming Interface (API) for IPv6 -.Re -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. diff --git a/src/lib/libc/net/inet_addr.3 b/src/lib/libc/net/inet_addr.3 deleted file mode 100644 index cbb9e14f6d..0000000000 --- a/src/lib/libc/net/inet_addr.3 +++ /dev/null @@ -1,195 +0,0 @@ -.\" $OpenBSD: inet_addr.3,v 1.7 2024/03/06 07:29:37 bentley Exp $ -.\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ -.\" -.\" Copyright (c) 1983, 1990, 1991, 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. 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. -.\" -.\" @(#)inet.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd $Mdocdate: March 6 2024 $ -.Dt INET_ADDR 3 -.Os -.Sh NAME -.Nm inet_aton , -.Nm inet_addr , -.Nm inet_network , -.Nm inet_ntoa -.Nd Internet Protocol version 4 (IPv4) address manipulation routines -.Sh SYNOPSIS -.In arpa/inet.h -.Ft int -.Fn inet_aton "const char *cp" "struct in_addr *addr" -.Ft in_addr_t -.Fn inet_addr "const char *cp" -.Ft in_addr_t -.Fn inet_network "const char *cp" -.Ft char * -.Fn inet_ntoa "struct in_addr in" -.Sh DESCRIPTION -The functions presented here only support IPv4 addresses. -In order to support IPv6 addresses as well, -.Xr inet_ntop 3 -and -.Xr inet_pton 3 -should be used rather than the functions presented here. -Scoped IPv6 addresses are supported via -.Xr getaddrinfo 3 -and -.Xr getnameinfo 3 . -.Pp -The routines -.Fn inet_aton , -.Fn inet_addr , -and -.Fn inet_network -interpret character strings representing -numbers expressed in the Internet standard -.Dq dot -notation. -.Pp -The -.Fn inet_aton -routine interprets the specified character string as an Internet address, -placing the address into the structure provided. -It returns 1 if the string was successfully interpreted, -or 0 if the string was invalid. -.Pp -The -.Fn inet_addr -and -.Fn inet_network -functions return numbers suitable for use -as Internet addresses and Internet network -numbers, respectively. -Both functions return the constant -.Dv INADDR_NONE -if the specified character string is malformed. -.Pp -The routine -.Fn inet_ntoa -takes an Internet address and returns an -ASCII string representing the address in dot notation. -.Pp -All Internet addresses are returned in network -order (bytes ordered from left to right). -All network numbers and local address parts are -returned as machine format integer values. -.Sh INTERNET ADDRESSES (IP VERSION 4) -Values specified using dot notation take one of the following forms: -.Bd -literal -offset indent -a.b.c.d -a.b.c -a.b -a -.Ed -.Pp -When four parts are specified, each is interpreted -as a byte of data and assigned, from left to right, -to the four bytes of an Internet address. -Note that when an Internet address is viewed as a 32-bit -integer quantity on a system that uses little-endian -byte order -(such as AMD64 or ARM processors) -the bytes referred to above appear as -.Dq Li d.c.b.a . -That is, little-endian bytes are ordered from right to left. -.Pp -When a three part address is specified, the last -part is interpreted as a 16-bit quantity and placed -in the rightmost two bytes of the network address. -This makes the three part address format convenient -for specifying Class B network addresses as -.Dq Li 128.net.host . -.Pp -When a two part address is supplied, the last part -is interpreted as a 24-bit quantity and placed in -the rightmost three bytes of the network address. -This makes the two part address format convenient -for specifying Class A network addresses as -.Dq Li net.host . -.Pp -When only one part is given, the value is stored -directly in the network address without any byte -rearrangement. -.Pp -All numbers supplied as -.Dq parts -in a dot notation -may be decimal, octal, or hexadecimal, as specified -in the C language (i.e., a leading 0x or 0X implies -hexadecimal; a leading 0 implies octal; -otherwise, the number is interpreted as decimal). -.Sh SEE ALSO -.Xr gethostbyname 3 , -.Xr htonl 3 , -.Xr inet_lnaof 3 , -.Xr inet_net_ntop 3 , -.Xr inet_ntop 3 , -.Xr hosts 5 -.Sh STANDARDS -The -.Nm inet_addr -and -.Nm inet_ntoa -functions conform to -.St -p1003.1-2008 . -.Sh HISTORY -The -.Nm inet_addr -and -.Nm inet_network -functions appeared in -.Bx 4.2 . -The -.Nm inet_aton -and -.Nm inet_ntoa -functions appeared in -.Bx 4.3 . -.Sh BUGS -The value -.Dv INADDR_NONE -(0xffffffff) is a valid broadcast address, but -.Fn inet_addr -cannot return that value without indicating failure. -Also, -.Fn inet_addr -should have been designed to return a -.Vt struct in_addr . -The newer -.Fn inet_aton -function does not share these problems, and almost all existing code -should be modified to use -.Fn inet_aton -instead. -.Pp -The problem of host byte ordering versus network byte ordering is -confusing. -.Pp -The string returned by -.Fn inet_ntoa -resides in a static memory area. diff --git a/src/lib/libc/net/inet_addr.c b/src/lib/libc/net/inet_addr.c deleted file mode 100644 index 62d46ad664..0000000000 --- a/src/lib/libc/net/inet_addr.c +++ /dev/null @@ -1,175 +0,0 @@ -/* $OpenBSD: inet_addr.c,v 1.12 2015/09/13 21:36:08 guenther Exp $ */ - -/* - * ++Copyright++ 1983, 1990, 1993 - * - - * 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. 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. - * - - * --Copyright-- - */ - -#include -#include -#include -#include - -/* - * Ascii internet address interpretation routine. - * 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); -} - -/* - * 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) -{ - in_addr_t val; - int base, n; - char c; - u_int parts[4]; - u_int *pp = parts; - - c = *cp; - for (;;) { - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. - */ - if (!isdigit((unsigned char)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((unsigned char)c) && - isdigit((unsigned char)c)) { - val = (val * base) + (c - '0'); - c = *++cp; - } else if (base == 16 && - isascii((unsigned char)c) && - isxdigit((unsigned char)c)) { - val = (val << 4) | - (c + 10 - (islower((unsigned char)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((unsigned char)c) || !isspace((unsigned char)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); -} -DEF_WEAK(inet_aton); diff --git a/src/lib/libc/net/inet_lnaof.3 b/src/lib/libc/net/inet_lnaof.3 deleted file mode 100644 index 6151f7fe34..0000000000 --- a/src/lib/libc/net/inet_lnaof.3 +++ /dev/null @@ -1,89 +0,0 @@ -.\" $OpenBSD: inet_lnaof.3,v 1.4 2019/08/30 20:06:07 jmc Exp $ -.\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ -.\" -.\" Copyright (c) 1983, 1990, 1991, 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. 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. -.\" -.\" @(#)inet.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd $Mdocdate: August 30 2019 $ -.Dt INET_LNAOF 3 -.Os -.Sh NAME -.Nm inet_makeaddr , -.Nm inet_netof , -.Nm inet_lnaof -.Nd routines for manipulating classful Internet Protocol version 4 (IPv4) addresses -.Sh SYNOPSIS -.In arpa/inet.h -.Ft struct in_addr -.Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" -.Ft in_addr_t -.Fn inet_netof "struct in_addr in" -.Ft in_addr_t -.Fn inet_lnaof "struct in_addr in" -.Sh DESCRIPTION -As originally designed, -IP version 4 split each address into a network part and local network -address part, encoding that split into the address itself. -It is frequency-encoded; -the most-significant bit is clear in Class A addresses, -in which the high-order 8 bits are the network number. -Class B addresses use the high-order 16 bits as the network field, -and Class C addresses have a 24-bit network part. -.Pp -The routine -.Fn inet_makeaddr -takes an Internet network number and a local -network address and constructs an Internet address -from it. -.Pp -The routines -.Fn inet_netof -and -.Fn inet_lnaof -break apart Internet host addresses, returning -the network number and local network address part, -respectively. -.Pp -All Internet addresses are returned in network -order (bytes ordered from left to right). -All network numbers and local address parts are -returned as machine format integer values. -.Sh SEE ALSO -.Xr gethostbyname 3 , -.Xr inet_addr 3 , -.Xr inet_net_ntop 3 , -.Xr hosts 5 -.Sh HISTORY -The -.Nm inet_makeaddr , -.Nm inet_lnaof , -and -.Nm inet_netof -functions appeared in -.Bx 4.2 . diff --git a/src/lib/libc/net/inet_lnaof.c b/src/lib/libc/net/inet_lnaof.c deleted file mode 100644 index 92845387d3..0000000000 --- a/src/lib/libc/net/inet_lnaof.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: inet_lnaof.c,v 1.7 2015/01/16 16:48:51 deraadt Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include - -/* - * 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) -{ - in_addr_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/src/lib/libc/net/inet_makeaddr.c b/src/lib/libc/net/inet_makeaddr.c deleted file mode 100644 index 88ddd2850e..0000000000 --- a/src/lib/libc/net/inet_makeaddr.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD: inet_makeaddr.c,v 1.7 2015/01/16 16:48:51 deraadt Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include - -/* - * Formulate an Internet address from network + host. Used in - * building addresses stored in the ifnet structure. - */ -struct in_addr -inet_makeaddr(in_addr_t net, in_addr_t host) -{ - in_addr_t addr; - - 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); - return (*(struct in_addr *)&addr); -} diff --git a/src/lib/libc/net/inet_net_ntop.3 b/src/lib/libc/net/inet_net_ntop.3 deleted file mode 100644 index 4212af3bb6..0000000000 --- a/src/lib/libc/net/inet_net_ntop.3 +++ /dev/null @@ -1,195 +0,0 @@ -.\" $OpenBSD: inet_net_ntop.3,v 1.4 2022/09/11 06:38:10 jmc Exp $ -.\" $NetBSD: inet_net.3,v 1.1 1997/06/18 02:25:27 lukem Exp $ -.\" -.\" Copyright (c) 1997 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Luke Mewburn. -.\" -.\" 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. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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. -.\" -.Dd $Mdocdate: September 11 2022 $ -.Dt INET_NET_NTOP 3 -.Os -.Sh NAME -.Nm inet_net_ntop , -.Nm inet_net_pton -.Nd Internet network number manipulation routines -.Sh SYNOPSIS -.In sys/socket.h -.In arpa/inet.h -.Ft char * -.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" -.Ft int -.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" -.Sh DESCRIPTION -The -.Fn inet_net_ntop -function converts an Internet network number from network format (usually a -.Vt struct in_addr -or some other binary form, in network byte order) to CIDR presentation format -(suitable for external display purposes). -.Fa bits -is the number of bits in -.Fa src -that are the network number. -It returns -.Dv NULL -if a system error occurs (in which case, -.Va errno -will have been set), or it returns a pointer to the destination string. -.Pp -The -.Fn inet_net_pton -function converts a presentation format Internet network number (that is, -printable form as held in a character string) to network format (usually a -.Vt struct in_addr -or some other internal binary representation, in network byte order). -It returns the number of bits (either computed based on the class, or -specified with /CIDR), or \-1 if a failure occurred -(in which case -.Va errno -will have been set. -It will be set to -.Er ENOENT -if the Internet network number was not valid). -.Pp -Caution: -The -.Fa dst -field should be zeroed before calling -.Fn inet_net_pton -as the function will only fill the number of bytes necessary to -encode the network number in network byte order. -.Pp -The only values for -.Fa af -currently supported are -.Dv AF_INET -and -.Dv AF_INET6 . -.Fa size -is the size of the result buffer -.Fa dst . -.Sh NETWORK NUMBERS (IP VERSION 4) -The external representation of Internet network numbers may be specified in -one of the following forms: -.Bd -literal -offset indent -a -a.b -a.b.c -a.b.c.d -.Ed -.Pp -Any of the above four forms may have -.Dq Li /bits -appended where -.Dq Li bits -is in the range -.Li 0-32 -and is used to explicitly specify the number of bits in the network address. -When -.Dq Li /bits -is not specified, the number of bits in the network address is calculated -as the larger of the number of bits in the class to which the address -belongs and the number of bits provided rounded up modulo 8. -Examples: -.Pp -.Bl -tag -width 10.1.2.3/24 -offset indent -compact -.It Li 10 -an 8-bit network number (class A), value -.Li 10.0.0.0 . -.It Li 192 -a 24-bit network number (class C), value -.Li 192.0.0.0 . -.It Li 10.10 -a 16-bit network number, value -.Li 10.10.0.0 . -.It Li 10.1.2 -a 24-bit network number, value -.Li 10.1.2.0 . -.It Li 10.1.2.3 -a 32-bit network number, value -.Li 10.1.2.3 . -.It Li 10.1.2.3/24 -a 24-bit network number (explicit), value -.Li 10.1.2.3 . -.El -.Pp -Note that when the number of bits is specified using -.Dq Li /bits -notation, the value of the address still includes all bits supplied -in the external representation, even those bits which are the host -part of an Internet address. -Also, unlike -.Xr inet_pton 3 -where the external representation is assumed to be a host address, the -external representation for -.Fn inet_net_pton -is assumed to be a network address. -Thus -.Dq Li 10.1 -is assumed to be -.Dq Li 10.1.0.0 -not -.Dq Li 10.0.0.1 -.Pp -All numbers supplied as -.Dq parts -in a -.Ql \&. -notation -may be decimal, octal, or hexadecimal, as specified -in the C language (i.e., a leading 0x or 0X implies -hexadecimal; otherwise, a leading 0 implies octal; -otherwise, the number is interpreted as decimal). -.Sh NETWORK NUMBERS (IP VERSION 6) -See -.Xr inet_pton 3 -for valid external representations of IP version 6 addresses. -A valid external representation may have -.Dq Li /bits -appended where -.Dq Li bits -is in the range -.Li 0-128 -and is used to explicitly specify the number of bits in the network address. -When -.Dq Li /bits -is not specified, 128 is used. -Note that when the number of bits is specified using -.Dq Li /bits -notation, the value of the address still includes all bits supplied -in the external representation, even those bits which are the host -part of an Internet address. -.Sh SEE ALSO -.Xr htonl 3 , -.Xr inet_pton 3 , -.Xr inet 4 , -.Xr hosts 5 -.Sh HISTORY -The -.Nm inet_net_ntop -and -.Nm inet_net_pton -functions first appeared in BIND 4.9.4. diff --git a/src/lib/libc/net/inet_net_ntop.c b/src/lib/libc/net/inet_net_ntop.c deleted file mode 100644 index 1f1c4bed12..0000000000 --- a/src/lib/libc/net/inet_net_ntop.c +++ /dev/null @@ -1,160 +0,0 @@ -/* $OpenBSD: inet_net_ntop.c,v 1.9 2019/07/03 03:24:04 deraadt Exp $ */ - -/* - * Copyright (c) 2012 by Gilles Chehade - * 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. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -static char *inet_net_ntop_ipv4(const u_char *, int, char *, size_t); -static char *inet_net_ntop_ipv6(const u_char *, int, char *, size_t); - -/* - * char * - * inet_net_ntop(af, src, bits, dst, size) - * convert network number from network to presentation format. - * generates CIDR style result always. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * author: - * Paul Vixie (ISC), July 1996 - */ -char * -inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_net_ntop_ipv4(src, bits, dst, size)); - case AF_INET6: - return (inet_net_ntop_ipv6(src, bits, dst, size)); - default: - errno = EAFNOSUPPORT; - return (NULL); - } -} - -/* - * static char * - * inet_net_ntop_ipv4(src, bits, dst, size) - * convert IPv4 network number from network to presentation format. - * generates CIDR style result always. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * note: - * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. - * author: - * Paul Vixie (ISC), July 1996 - */ -static char * -inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) -{ - char *odst = dst; - u_int m; - int b; - char *ep; - int advance; - - ep = dst + size; - if (ep <= dst) - goto emsgsize; - - if (bits < 0 || bits > 32) { - errno = EINVAL; - return (NULL); - } - if (bits == 0) { - if (ep - dst < sizeof "0") - goto emsgsize; - *dst++ = '0'; - *dst = '\0'; - } - - /* Format whole octets. */ - for (b = bits / 8; b > 0; b--) { - if (ep - dst < sizeof "255.") - goto emsgsize; - advance = snprintf(dst, ep - dst, "%u", *src++); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - if (b > 1) { - if (dst + 1 >= ep) - goto emsgsize; - *dst++ = '.'; - *dst = '\0'; - } - } - - /* Format partial octet. */ - b = bits % 8; - if (b > 0) { - if (ep - dst < sizeof ".255") - goto emsgsize; - if (dst != odst) - *dst++ = '.'; - m = ((1 << b) - 1) << (8 - b); - advance = snprintf(dst, ep - dst, "%u", *src & m); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - } - - /* Format CIDR /width. */ - if (ep - dst < sizeof "/32") - goto emsgsize; - advance = snprintf(dst, ep - dst, "/%u", bits); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - return (odst); - - emsgsize: - errno = EMSGSIZE; - return (NULL); -} - -static char * -inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) -{ - int ret; - char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")]; - - if (bits < 0 || bits > 128) { - errno = EINVAL; - return (NULL); - } - - if (inet_ntop(AF_INET6, src, buf, size) == NULL) - return (NULL); - - ret = snprintf(dst, size, "%s/%d", buf, bits); - if (ret < 0 || ret >= size) { - errno = EMSGSIZE; - return (NULL); - } - - return (dst); -} diff --git a/src/lib/libc/net/inet_net_pton.c b/src/lib/libc/net/inet_net_pton.c deleted file mode 100644 index c5baa4d6f4..0000000000 --- a/src/lib/libc/net/inet_net_pton.c +++ /dev/null @@ -1,246 +0,0 @@ -/* $OpenBSD: inet_net_pton.c,v 1.14 2022/12/27 17:10:06 jmc Exp $ */ - -/* - * Copyright (c) 2012 by Gilles Chehade - * 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. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -static int inet_net_pton_ipv4(const char *, u_char *, size_t); -static int inet_net_pton_ipv6(const char *, u_char *, size_t); - -/* - * static int - * inet_net_pton(af, src, dst, size) - * convert network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not a valid network specification. - * author: - * Paul Vixie (ISC), June 1996 - */ -int -inet_net_pton(int af, const char *src, void *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_net_pton_ipv4(src, dst, size)); - case AF_INET6: - return (inet_net_pton_ipv6(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (-1); - } -} - -/* - * static int - * inet_net_pton_ipv4(src, dst, size) - * convert IPv4 network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not an IPv4 network specification. - * note: - * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. - * author: - * Paul Vixie (ISC), June 1996 - */ -static int -inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) -{ - static const char - xdigits[] = "0123456789abcdef", - digits[] = "0123456789"; - int n, ch, tmp, dirty, bits; - const u_char *odst = dst; - - ch = (unsigned char)*src++; - if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii((unsigned char)src[1]) && isxdigit((unsigned char)src[1])) { - /* Hexadecimal: Eat nybble string. */ - if (size == 0) - goto emsgsize; - tmp = 0, dirty = 0; - src++; /* skip x or X. */ - while ((ch = (unsigned char)*src++) != '\0' && - isascii(ch) && isxdigit(ch)) { - if (isupper(ch)) - ch = tolower(ch); - n = strchr(xdigits, ch) - xdigits; - assert(n >= 0 && n <= 15); - if (dirty == 0) - tmp = n; - else - tmp = (tmp << 4) | n; - if (++dirty == 2) { - if (size-- == 0) - goto emsgsize; - *dst++ = (u_char) tmp; - dirty = 0; - } - } - if (dirty) { /* Odd trailing nybble? */ - if (size-- == 0) - goto emsgsize; - *dst++ = (u_char) (tmp << 4); - } - } else if (isascii(ch) && isdigit(ch)) { - /* Decimal: eat dotted digit string. */ - for (;;) { - tmp = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - tmp *= 10; - tmp += n; - if (tmp > 255) - goto enoent; - } while ((ch = (unsigned char)*src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (size-- == 0) - goto emsgsize; - *dst++ = (u_char) tmp; - if (ch == '\0' || ch == '/') - break; - if (ch != '.') - goto enoent; - ch = (unsigned char)*src++; - if (!isascii(ch) || !isdigit(ch)) - goto enoent; - } - } else - goto enoent; - - bits = -1; - if (ch == '/' && isascii((unsigned char)src[0]) && - isdigit((unsigned char)src[0]) && dst > odst) { - /* CIDR width specifier. Nothing can follow it. */ - ch = (unsigned char)*src++; /* Skip over the /. */ - bits = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - bits *= 10; - bits += n; - if (bits > 32) - goto emsgsize; - } while ((ch = (unsigned char)*src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (ch != '\0') - goto enoent; - } - - /* Fiery death and destruction unless we prefetched EOS. */ - if (ch != '\0') - goto enoent; - - /* If nothing was written to the destination, we found no address. */ - if (dst == odst) - goto enoent; - /* If no CIDR spec was given, infer width from net class. */ - if (bits == -1) { - if (*odst >= 240) /* Class E */ - bits = 32; - else if (*odst >= 224) /* Class D */ - bits = 4; - else if (*odst >= 192) /* Class C */ - bits = 24; - else if (*odst >= 128) /* Class B */ - bits = 16; - else /* Class A */ - bits = 8; - /* If imputed mask is narrower than specified octets, widen. */ - if (bits < ((dst - odst) * 8)) - bits = (dst - odst) * 8; - } - /* Extend network to cover the actual mask. */ - while (bits > ((dst - odst) * 8)) { - if (size-- == 0) - goto emsgsize; - *dst++ = '\0'; - } - return (bits); - - enoent: - errno = ENOENT; - return (-1); - - emsgsize: - errno = EMSGSIZE; - return (-1); -} - - -static int -inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) -{ - struct in6_addr in6; - int ret; - int bits; - size_t bytes; - char buf[INET6_ADDRSTRLEN + sizeof("/128")]; - char *sep; - const char *errstr; - - if (strlcpy(buf, src, sizeof buf) >= sizeof buf) { - errno = EMSGSIZE; - return (-1); - } - - sep = strchr(buf, '/'); - if (sep != NULL) - *sep++ = '\0'; - - ret = inet_pton(AF_INET6, buf, &in6); - if (ret != 1) - return (-1); - - if (sep == NULL) - bits = 128; - else { - bits = strtonum(sep, 0, 128, &errstr); - if (errstr) { - errno = EINVAL; - return (-1); - } - } - - bytes = (bits + 7) / 8; - if (bytes > size) { - errno = EMSGSIZE; - return (-1); - } - memcpy(dst, &in6.s6_addr, bytes); - return (bits); -} diff --git a/src/lib/libc/net/inet_neta.c b/src/lib/libc/net/inet_neta.c deleted file mode 100644 index e3e7d0eb71..0000000000 --- a/src/lib/libc/net/inet_neta.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $OpenBSD: inet_neta.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ - -/* - * 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. - */ - -#include -#include -#include -#include - -#include -#include -#include - -/* - * char * - * inet_neta(src, dst, size) - * format an in_addr_t network number into presentation format. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * note: - * format of ``src'' is as for inet_network(). - * author: - * Paul Vixie (ISC), July 1996 - */ -char * -inet_neta(in_addr_t src, char *dst, size_t size) -{ - char *odst = dst; - char *ep; - int advance; - - if (src == 0x00000000) { - if (size < sizeof "0.0.0.0") - goto emsgsize; - strlcpy(dst, "0.0.0.0", size); - return dst; - } - ep = dst + size; - if (ep <= dst) - goto emsgsize; - while (src & 0xffffffff) { - u_char b = (src & 0xff000000) >> 24; - - src <<= 8; - if (b || src) { - if (ep - dst < sizeof "255.") - goto emsgsize; - advance = snprintf(dst, ep - dst, "%u", b); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - if (src != 0L) { - if (dst + 1 >= ep) - goto emsgsize; - *dst++ = '.'; - *dst = '\0'; - } - } - } - return (odst); - - emsgsize: - errno = EMSGSIZE; - return (NULL); -} diff --git a/src/lib/libc/net/inet_netof.c b/src/lib/libc/net/inet_netof.c deleted file mode 100644 index 4efceede13..0000000000 --- a/src/lib/libc/net/inet_netof.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: inet_netof.c,v 1.7 2015/01/16 16:48:51 deraadt Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include - -/* - * Return the network number from an internet - * address; handles class a/b/c network #'s. - */ -in_addr_t -inet_netof(struct in_addr in) -{ - in_addr_t i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); - else if (IN_CLASSB(i)) - return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); - else - return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); -} diff --git a/src/lib/libc/net/inet_network.c b/src/lib/libc/net/inet_network.c deleted file mode 100644 index 7b0cf50e79..0000000000 --- a/src/lib/libc/net/inet_network.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $OpenBSD: inet_network.c,v 1.13 2015/10/22 23:55:51 mmcc Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -#include -#include -#include -#include - -/* - * 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, base, n; - u_char c; - in_addr_t parts[4], *pp = parts; - int i; - -again: - val = 0; base = 10; - if (*cp == '0') - base = 8, cp++; - if (*cp == 'x' || *cp == 'X') - base = 16, cp++; - while ((c = *cp)) { - if (isdigit(c)) { - 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 (*cp == '.') { - if (pp >= parts + 3) - return (INADDR_NONE); - *pp++ = val, cp++; - goto again; - } - if (*cp && !isspace((unsigned char)*cp)) - return (INADDR_NONE); - *pp++ = val; - n = pp - parts; - for (val = 0, i = 0; i < 4; i++) { - val <<= 8; - if (i < n) - val |= parts[i] & 0xff; - } - return (val); -} -DEF_WEAK(inet_network); diff --git a/src/lib/libc/net/inet_ntoa.c b/src/lib/libc/net/inet_ntoa.c deleted file mode 100644 index ff5d93ded2..0000000000 --- a/src/lib/libc/net/inet_ntoa.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: inet_ntoa.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 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. 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. - */ - -/* - * Convert network-format internet address - * to base 256 d.d.d.d representation. - */ -#include -#include -#include -#include - -char * -inet_ntoa(struct in_addr in) -{ - static char b[18]; - char *p; - - p = (char *)∈ -#define UC(b) (((int)b)&0xff) - (void)snprintf(b, sizeof(b), - "%u.%u.%u.%u", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); - return (b); -} diff --git a/src/lib/libc/net/inet_ntop.3 b/src/lib/libc/net/inet_ntop.3 deleted file mode 100644 index e5c1c574f8..0000000000 --- a/src/lib/libc/net/inet_ntop.3 +++ /dev/null @@ -1,213 +0,0 @@ -.\" $OpenBSD: inet_ntop.3,v 1.6 2022/09/11 06:38:10 jmc Exp $ -.\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ -.\" -.\" Copyright (c) 1983, 1990, 1991, 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. 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. -.\" -.\" @(#)inet.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd $Mdocdate: September 11 2022 $ -.Dt INET_NTOP 3 -.Os -.Sh NAME -.Nm inet_ntop , -.Nm inet_pton -.Nd convert Internet addresses between presentation and network formats -.Sh SYNOPSIS -.In sys/socket.h -.In arpa/inet.h -.Ft const char * -.Fn inet_ntop "int af" "const void * restrict src" "char * restrict dst" "socklen_t size" -.Ft int -.Fn inet_pton "int af" "const char * restrict src" "void * restrict dst" -.Sh DESCRIPTION -The -.Fn inet_pton -function converts a presentation format address (that is, printable form -as held in a character string) to network format (usually a -.Vt struct in_addr -or some other internal binary representation, in network byte order). -It returns 1 if the address was valid for the specified address family; -0 if the address wasn't parseable in the specified address family; or \-1 -if some system error occurred (in which case -.Va errno -will have been set). -This function is presently valid for -.Dv AF_INET -and -.Dv AF_INET6 . -.Pp -The function -.Fn inet_ntop -converts an address from network format to presentation format. -It returns -.Dv NULL -if a system -error occurs (in which case, -.Va errno -will have been set), or it returns a pointer to the destination string. -.Pp -All Internet addresses are returned in network -order (bytes ordered from left to right). -.Sh INTERNET ADDRESSES (IP VERSION 4) -Values must be specified using the standard dot notation: -.Bd -literal -offset indent -a.b.c.d -.Ed -.Pp -All four parts must be decimal numbers between 0 and 255, inclusive, -and are assigned, from left to right, -to the four bytes of an Internet address. -Note that when an Internet address is viewed as a 32-bit integer -quantity on a system that uses little-endian byte order -(such as AMD64 or ARM processors) -the bytes referred to above appear as -.Dq Li d.c.b.a . -That is, little-endian bytes are ordered from right to left. -.Sh INTERNET ADDRESSES (IP VERSION 6) -In order to support scoped IPv6 addresses, -.Xr getaddrinfo 3 -and -.Xr getnameinfo 3 -are recommended rather than the functions presented here. -.Pp -The presentation format of an IPv6 address is given in RFC 4291: -.Pp -There are three conventional forms for representing IPv6 addresses as -text strings: -.Bl -enum -.It -The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the -hexadecimal values of the eight 16-bit pieces of the address. -Examples: -.Bd -literal -offset indent -FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 -1080:0:0:0:8:800:200C:417A -.Ed -.Pp -Note that it is not necessary to write the leading zeros in an -individual field, but there must be at least one numeral in -every field (except for the case described in 2.). -.It -Due to the method of allocating certain styles of IPv6 -addresses, it will be common for addresses to contain long -strings of zero bits. -In order to make writing addresses -containing zero bits easier, a special syntax is available to -compress the zeros. -The use of -.Dq \&:\&: -indicates multiple groups -of 16 bits of zeros. -The -.Dq \&:\&: -can only appear once in an -address. -The -.Dq \&:\&: -can also be used to compress the leading and/or trailing zeros in an address. -.Pp -For example the following addresses: -.Bd -literal -offset indent -1080:0:0:0:8:800:200C:417A a unicast address -FF01:0:0:0:0:0:0:43 a multicast address -0:0:0:0:0:0:0:1 the loopback address -0:0:0:0:0:0:0:0 the unspecified addresses -.Ed -.Pp -may be represented as: -.Bd -literal -offset indent -1080::8:800:200C:417A a unicast address -FF01::43 a multicast address -::1 the loopback address -:: the unspecified addresses -.Ed -.It -An alternative form that is sometimes more convenient when -dealing with a mixed environment of IPv4 and IPv6 nodes is -x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values -of the six high-order 16-bit pieces of the address, and the 'd's -are the decimal values of the four low-order 8-bit pieces of the -address (standard IPv4 representation). -Examples: -.Bd -literal -offset indent -0:0:0:0:0:0:13.1.68.3 -0:0:0:0:0:FFFF:129.144.52.38 -.Ed -.Pp -or in compressed form: -.Bd -literal -offset indent -::13.1.68.3 -::FFFF:129.144.52.38 -.Ed -.El -.Sh SEE ALSO -.Xr gethostbyname 3 , -.Xr inet_addr 3 , -.Xr inet_net_ntop 3 , -.Xr hosts 5 -.Sh STANDARDS -The -.Nm inet_ntop -and -.Nm inet_pton -functions conform to the IETF IPv6 BSD API and address formatting -specifications, as well as -.St -p1003.1-2008 . -.Sh HISTORY -The -.Nm inet_pton -and -.Nm inet_ntop -functions appeared in BIND 4.9.4. -.Sh CAVEATS -Note that -.Nm inet_pton -does not accept 1-, 2-, or 3-part dotted addresses; -all four parts must be specified and must be in decimal -(and not octal or hexadecimal). -This is a narrower input set than that accepted by -.Nm inet_aton . -.Pp -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%D February 2003 -.%R RFC 3493 -.%T Basic Socket Interface Extensions for IPv6 -.Re -.Pp -.Rs -.%A R. Hinden -.%A S. Deering -.%D February 2006 -.%R RFC 4291 -.%T IP Version 6 Addressing Architecture -.Re diff --git a/src/lib/libc/net/inet_ntop.c b/src/lib/libc/net/inet_ntop.c deleted file mode 100644 index 2bb11c2ab2..0000000000 --- a/src/lib/libc/net/inet_ntop.c +++ /dev/null @@ -1,205 +0,0 @@ -/* $OpenBSD: inet_ntop.c,v 1.13 2016/09/21 04:38:56 guenther Exp $ */ - -/* 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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static const char *inet_ntop4(const u_char *src, char *dst, size_t size); -static const char *inet_ntop6(const u_char *src, char *dst, size_t size); - -/* const 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). - * author: - * Paul Vixie, 1996. - */ -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 */ -} -DEF_WEAK(inet_ntop); - -/* 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 u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop4(const u_char *src, char *dst, size_t size) -{ - char tmp[sizeof "255.255.255.255"]; - int l; - - l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u", - src[0], src[1], src[2], src[3]); - if (l <= 0 || l >= size) { - errno = ENOSPC; - return (NULL); - } - strlcpy(dst, tmp, size); - return (dst); -} - -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop6(const u_char *src, char *dst, size_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"]; - char *tp, *ep; - struct { int base, len; } best, cur; - u_int words[IN6ADDRSZ / INT16SZ]; - int i; - int advance; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - 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; - ep = tmp + sizeof(tmp); - for (i = 0; i < (IN6ADDRSZ / INT16SZ) && tp < ep; 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) { - if (tp + 1 >= ep) { - errno = ENOSPC; - return (NULL); - } - *tp++ = ':'; - } - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) { - if (tp + 1 >= ep) { - errno = ENOSPC; - return (NULL); - } - *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, ep - tp)) - return (NULL); - tp += strlen(tp); - break; - } - advance = snprintf(tp, ep - tp, "%x", words[i]); - if (advance <= 0 || advance >= ep - tp) { - errno = ENOSPC; - return (NULL); - } - tp += advance; - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) { - if (tp + 1 >= ep) { - errno = ENOSPC; - return (NULL); - } - *tp++ = ':'; - } - if (tp + 1 >= ep) { - errno = ENOSPC; - return (NULL); - } - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) { - errno = ENOSPC; - return (NULL); - } - strlcpy(dst, tmp, size); - return (dst); -} diff --git a/src/lib/libc/net/inet_pton.c b/src/lib/libc/net/inet_pton.c deleted file mode 100644 index 45bafd2ffc..0000000000 --- a/src/lib/libc/net/inet_pton.c +++ /dev/null @@ -1,213 +0,0 @@ -/* $OpenBSD: inet_pton.c,v 1.11 2024/09/03 17:05:59 deraadt Exp $ */ - -/* 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. - */ - -#include -#include -#include -#include -#include -#include -#include - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static int inet_pton4(const char *src, u_char *dst); -static int inet_pton6(const char *src, u_char *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. - */ -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 */ -} -DEF_WEAK(inet_pton); - -/* 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. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(const char *src, u_char *dst) -{ - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - u_char tmp[INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr(digits, ch)) != NULL) { - u_int new = *tp * 10 + (pch - digits); - - if (new > 255) - return (0); - if (!saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - *tp = new; - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - - 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: - * does not touch `dst' unless it's returning 1. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton6(const char *src, u_char *dst) -{ - static const char xdigits_l[] = "0123456789abcdef", - xdigits_u[] = "0123456789ABCDEF"; - u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp; - const char *xdigits, *curtok; - int ch, saw_xdigit, count_xdigit; - u_int val; - - 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 = count_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) { - if (count_xdigit >= 4) - return (0); - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - count_xdigit++; - 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++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - saw_xdigit = 0; - count_xdigit = 0; - val = 0; - continue; - } - if (ch == '.' && ((tp + INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { - tp += INADDRSZ; - saw_xdigit = 0; - count_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - return (0); - } - if (saw_xdigit) { - if (tp + INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) 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); - memcpy(dst, tmp, IN6ADDRSZ); - return (1); -} diff --git a/src/lib/libc/net/ip6opt.c b/src/lib/libc/net/ip6opt.c deleted file mode 100644 index 3837489448..0000000000 --- a/src/lib/libc/net/ip6opt.c +++ /dev/null @@ -1,285 +0,0 @@ -/* $OpenBSD: ip6opt.c,v 1.10 2020/01/22 07:52:37 deraadt Exp $ */ -/* $KAME: ip6opt.c,v 1.18 2005/06/15 07:11:35 keiichi Exp $ */ - -/* - * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. - * 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. Neither the name of the project 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 PROJECT 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 PROJECT 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. - */ - -#include -#include - -#include -#include - -#include -#include - -static int ip6optlen(u_int8_t *opt, u_int8_t *lim); - -/* - * Calculate the length of a given IPv6 option. Also checks - * if the option is safely stored in user's buffer according to the - * calculated length and the limitation of the buffer. - */ -static int -ip6optlen(u_int8_t *opt, u_int8_t *lim) -{ - int optlen; - - if (*opt == IP6OPT_PAD1) - optlen = 1; - else { - /* is there enough space to store type and len? */ - if (opt + 2 > lim) - return (0); - optlen = *(opt + 1) + 2; - } - if (opt + optlen <= lim) - return (optlen); - - return (0); -} - -/* - * The following functions are defined in RFC3542, which is a successor - * of RFC2292. - */ - -int -inet6_opt_init(void *extbuf, socklen_t extlen) -{ - struct ip6_ext *ext = (struct ip6_ext *)extbuf; - - if (ext) { - if (extlen <= 0 || (extlen % 8)) - return (-1); - ext->ip6e_len = (extlen >> 3) - 1; - } - - return (2); /* sizeof the next and the length fields */ -} - -int -inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, - socklen_t len, u_int8_t align, void **databufp) -{ - int currentlen = offset, padlen = 0; - - /* - * The option type must have a value from 2 to 255, inclusive. - * (0 and 1 are reserved for the Pad1 and PadN options, respectively.) - */ -#if 0 /* always false */ - if (type < 2 || type > 255) -#else - if (type < 2) -#endif - return (-1); - - /* - * The option data length must have a value between 0 and 255, - * inclusive, and is the length of the option data that follows. - */ - if (len > 255) - return (-1); - - /* - * The align parameter must have a value of 1, 2, 4, or 8. - * The align value can not exceed the value of len. - */ - if (align != 1 && align != 2 && align != 4 && align != 8) - return (-1); - if (align > len) - return (-1); - - /* Calculate the padding length. */ - currentlen += 2 + len; /* 2 means "type + len" */ - if (currentlen % align) - padlen = align - (currentlen % align); - - /* The option must fit in the extension header buffer. */ - currentlen += padlen; - if (extlen && /* XXX: right? */ - currentlen > extlen) - return (-1); - - if (extbuf) { - u_int8_t *optp = (u_int8_t *)extbuf + offset; - - if (padlen == 1) { - /* insert a Pad1 option */ - *optp = IP6OPT_PAD1; - optp++; - } else if (padlen > 0) { - /* insert a PadN option for alignment */ - *optp++ = IP6OPT_PADN; - *optp++ = padlen - 2; - memset(optp, 0, padlen - 2); - optp += (padlen - 2); - } - - *optp++ = type; - *optp++ = len; - - *databufp = optp; - } - - return (currentlen); -} - -int -inet6_opt_finish(void *extbuf, socklen_t extlen, int offset) -{ - int updatelen = offset > 0 ? (1 + ((offset - 1) | 7)) : 0; - - if (extbuf) { - u_int8_t *padp; - int padlen = updatelen - offset; - - if (updatelen > extlen) - return (-1); - - padp = (u_int8_t *)extbuf + offset; - if (padlen == 1) - *padp = IP6OPT_PAD1; - else if (padlen > 0) { - *padp++ = IP6OPT_PADN; - *padp++ = (padlen - 2); - memset(padp, 0, padlen - 2); - } - } - - return (updatelen); -} - -int -inet6_opt_set_val(void *databuf, int offset, void *val, socklen_t vallen) -{ - - memcpy((u_int8_t *)databuf + offset, val, vallen); - return (offset + vallen); -} - -int -inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, - socklen_t *lenp, void **databufp) -{ - u_int8_t *optp, *lim; - int optlen; - - /* Validate extlen. XXX: is the variable really necessary?? */ - if (extlen == 0 || (extlen % 8)) - return (-1); - lim = (u_int8_t *)extbuf + extlen; - - /* - * If this is the first time this function called for this options - * header, simply return the 1st option. - * Otherwise, search the option list for the next option. - */ - if (offset == 0) - optp = (u_int8_t *)((struct ip6_hbh *)extbuf + 1); - else - optp = (u_int8_t *)extbuf + offset; - - /* Find the next option skipping any padding options. */ - while (optp < lim) { - switch(*optp) { - case IP6OPT_PAD1: - optp++; - break; - case IP6OPT_PADN: - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - optp += optlen; - break; - default: /* found */ - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - *typep = *optp; - *lenp = optlen - 2; - *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); - } - } - - optend: - *databufp = NULL; /* for safety */ - return (-1); -} - -int -inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, - socklen_t *lenp, void **databufp) -{ - u_int8_t *optp, *lim; - int optlen; - - /* Validate extlen. XXX: is the variable really necessary?? */ - if (extlen == 0 || (extlen % 8)) - return (-1); - lim = (u_int8_t *)extbuf + extlen; - - /* - * If this is the first time this function called for this options - * header, simply return the 1st option. - * Otherwise, search the option list for the next option. - */ - if (offset == 0) - optp = (u_int8_t *)((struct ip6_hbh *)extbuf + 1); - else - optp = (u_int8_t *)extbuf + offset; - - /* Find the specified option */ - while (optp < lim) { - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - - if (*optp == type) { /* found */ - *lenp = optlen - 2; - *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); - } - - optp += optlen; - } - - optend: - *databufp = NULL; /* for safety */ - return (-1); -} - -int -inet6_opt_get_val(void *databuf, int offset, void *val, socklen_t vallen) -{ - - /* we can't assume alignment here */ - memcpy(val, (u_int8_t *)databuf + offset, vallen); - - return (offset + vallen); -} diff --git a/src/lib/libc/net/link_ntoa.3 b/src/lib/libc/net/link_ntoa.3 deleted file mode 100644 index 8953677441..0000000000 --- a/src/lib/libc/net/link_ntoa.3 +++ /dev/null @@ -1,78 +0,0 @@ -.\" $OpenBSD: link_ntoa.3,v 1.2 2015/09/10 10:14:20 jmc Exp $ -.\" -.\" Copyright (c) 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Donn Seeley at BSDI. -.\" -.\" 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. 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. -.\" -.Dd $Mdocdate: September 10 2015 $ -.Dt LINK_NTOA 3 -.Os -.Sh NAME -.Nm link_ntoa -.Nd elementary address specification routine for link level access -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In net/if_dl.h -.Ft char * -.Fn link_ntoa "const struct sockaddr_dl *sdl" -.Sh DESCRIPTION -The -.Fn link_ntoa -function takes -a link-level -address and returns an -.Tn ASCII -string representing some of the information present, -including the link level address itself, and the interface name -or number, if present. -This facility is experimental and is -still subject to change. -.Sh RETURN VALUES -.Fn link_ntoa -always returns a NUL-terminated string. -.Sh SEE ALSO -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn link_ntoa -function appeared in -.Bx 4.3 Reno . -.Sh BUGS -The returned values for -.Fn link_ntoa -reside in a static memory area. -.Pp -If the -.Fa sdl_len -field of the link socket address -.Fa sdl -is 0, -.Fn link_ntoa -will not insert a colon before the interface address bytes. diff --git a/src/lib/libc/net/linkaddr.c b/src/lib/libc/net/linkaddr.c deleted file mode 100644 index 9101e23a86..0000000000 --- a/src/lib/libc/net/linkaddr.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $OpenBSD: linkaddr.c,v 1.9 2016/12/08 03:20:50 millert Exp $ */ -/*- - * Copyright (c) 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. 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. - */ - -#include -#include -#include -#include -#include - -static const char hexlist[] = "0123456789abcdef"; - -char * -link_ntoa(const struct sockaddr_dl *sdl) -{ - static char obuf[64]; - char *out; - const u_char *in, *inlim; - int namelen, i, rem; - - namelen = (sdl->sdl_nlen <= IFNAMSIZ) ? sdl->sdl_nlen : IFNAMSIZ; - - out = obuf; - rem = sizeof(obuf); - if (namelen > 0) { - memcpy(out, sdl->sdl_data, namelen); - out += namelen; - rem -= namelen; - if (sdl->sdl_alen > 0) { - *out++ = ':'; - rem--; - } - } - - in = (const u_char *)sdl->sdl_data + sdl->sdl_nlen; - inlim = in + sdl->sdl_alen; - - while (in < inlim && rem > 1) { - if (in != (const u_char *)sdl->sdl_data + sdl->sdl_nlen) { - *out++ = '.'; - rem--; - } - i = *in++; - if (i > 0xf) { - if (rem < 3) - break; - *out++ = hexlist[i >> 4]; - *out++ = hexlist[i & 0xf]; - rem -= 2; - } else { - if (rem < 2) - break; - *out++ = hexlist[i]; - rem--; - } - } - *out = 0; - return (obuf); -} diff --git a/src/lib/libc/net/ntohl.c b/src/lib/libc/net/ntohl.c deleted file mode 100644 index 7592398e8c..0000000000 --- a/src/lib/libc/net/ntohl.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: ntohl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */ -/* - * Public domain. - */ - -#include -#include - -#undef ntohl - -uint32_t -ntohl(uint32_t x) -{ - return be32toh(x); -} diff --git a/src/lib/libc/net/ntohs.c b/src/lib/libc/net/ntohs.c deleted file mode 100644 index ef22ea3068..0000000000 --- a/src/lib/libc/net/ntohs.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: ntohs.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */ -/* - * Public domain. - */ - -#include -#include - -#undef ntohs - -uint16_t -ntohs(uint16_t x) -{ - return be16toh(x); -} diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3 deleted file mode 100644 index b2a5cdea9b..0000000000 --- a/src/lib/libc/net/rcmd.3 +++ /dev/null @@ -1,232 +0,0 @@ -.\" $OpenBSD: rcmd.3,v 1.34 2016/05/28 15:48:30 millert Exp $ -.\" -.\" Copyright (c) 1983, 1991, 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. 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. -.\" -.Dd $Mdocdate: May 28 2016 $ -.Dt RCMD 3 -.Os -.Sh NAME -.Nm rcmd , -.Nm rcmd_af , -.Nm rresvport , -.Nm rresvport_af , -.Nm ruserok -.Nd routines for returning a stream to a remote command -.Sh SYNOPSIS -.In unistd.h -.Ft int -.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" -.Ft int -.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af" -.Ft int -.Fn rresvport "int *port" -.Ft int -.Fn rresvport_af "int *port" "int af" -.Ft int -.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" -.Sh DESCRIPTION -The -.Fn rcmd -function is used by the superuser to execute a command on a remote -machine using an authentication scheme based on reserved -port numbers. -If the calling process is not setuid, the -.Ev RSH -environment variable is set, and -.Fa inport -is -.Dq shell/tcp , -.Xr rcmdsh 3 -is called instead with the value of -.Ev RSH . -Alternately, if the user is not the superuser, -.Fn rcmd -will invoke -.Xr rcmdsh 3 -to run the command via -.Xr ssh 1 . -While -.Fn rcmd -can handle IPv4 cases only, -the -.Fn rcmd_af -function can handle other cases as well. -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions return a descriptor to a socket -with an address in the privileged port space. -The -.Fn ruserok -function is used by servers -to authenticate clients requesting service with -.Fn rcmd . -.Pp -The -.Fn rcmd -function looks up the host -.Fa *ahost -using -.Xr getaddrinfo 3 -and, if the host exists, -.Fa *ahost -is set to the canonical name of the host. -A connection is then established to a server -residing at the well-known Internet port -.Fa inport . -If the user is not the superuser, the only valid port is -.Dq shell/tcp -(usually port 514). -.Pp -If the connection succeeds, -a socket in the Internet domain of type -.Dv SOCK_STREAM -is returned to the caller, and given to the remote -command as stdin and stdout. -If -.Fa fd2p -is non-zero, then an auxiliary channel to a control -process will be set up, and a descriptor for it will be placed -in -.Fa *fd2p . -The control process will return diagnostic -output from the command (unit 2) on this channel, and will also -accept bytes on this channel as being -.Tn UNIX -signal numbers, to be -forwarded to the process group of the command. -If -.Fa fd2p -is -.Va NULL , -then the standard error (unit 2 of the remote command) will be made -the same as the standard output and no provision is made for sending -arbitrary signals to the remote process, although you may be able to -get its attention by using out-of-band data. -Note that if the user is not the superuser, -.Fa fd2p -must be -.Va NULL . -.Pp -.Fn rcmd_af -takes address family in the last argument. -If the last argument is -.Dv AF_UNSPEC , -interpretation of -.Fa *ahost -will obey the underlying address resolution like DNS. -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions are used to obtain a socket with a privileged -address bound to it. -This socket is suitable for use by -.Fn rcmd -and several other functions. -Privileged Internet ports are those in the range 0 to -.Va IPPORT_RESERVED - 1 , -which happens to be 1023. -Only the superuser is allowed to bind an address of this sort to a socket. -.Fn rresvport -and -.Fn rresvport_af -need to be seeded with a port number; if that port -is not available these functions will find another. -.Pp -The -.Fn ruserok -function takes a remote host's name, two user names, -and a flag indicating whether the local user's -name is that of the superuser. -Then, if the user is -.Em not -the superuser, it checks the -.Pa /etc/hosts.equiv -file. -If that lookup is not done, or is unsuccessful, the -.Pa .rhosts -in the local user's home directory is checked to see if the request for -service is allowed. -.Pp -If this file does not exist, is not a regular file, is owned by anyone -other than the user or the superuser, or is writeable by anyone other -than the owner, the check automatically fails. -Zero is returned if the machine name is listed in the -.Pa hosts.equiv -file, or the host and remote user name are found in the -.Pa .rhosts -file; otherwise -.Fn ruserok -returns \-1. -If the local domain (as obtained from -.Xr getaddrinfo 3 ) -is the same as the remote domain, only the machine name need be specified. -.Pp -.Fn ruserok -implicitly requires trusting the DNS server for the remote host's domain. -.Sh DIAGNOSTICS -The -.Fn rcmd -function returns a valid socket descriptor on success. -It returns \-1 on error and prints a diagnostic message on the standard error. -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions return a valid, bound socket descriptor on success. -It returns \-1 on error with the global value -.Va errno -set according to the reason for failure. -The error code -.Er EAGAIN -is overloaded to mean -.Dq all network ports in use . -.Sh SEE ALSO -.Xr ssh 1 , -.Xr intro 2 , -.Xr bindresvport 3 , -.Xr bindresvport_sa 3 , -.Xr rcmdsh 3 -.Sh HISTORY -These -functions appeared in -.Bx 4.2 . -.Pp -The -.Fn iruserok -and -.Fn iruserok_sa -functions, IP address based versions of -.Fn ruserok , -were removed in -.Ox 6.0 . diff --git a/src/lib/libc/net/rcmd.c b/src/lib/libc/net/rcmd.c deleted file mode 100644 index bf68603649..0000000000 --- a/src/lib/libc/net/rcmd.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. - * Copyright (c) 1983, 1993, 1994 - * 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. 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. - */ - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int -rcmd(char **ahost, int rport, const char *locuser, const char *remuser, - const char *cmd, int *fd2p) -{ - return rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET); -} - -int -rcmd_af(char **ahost, int porta, const char *locuser, const char *remuser, - const char *cmd, int *fd2p, int af) -{ - static char hbuf[HOST_NAME_MAX+1]; - char pbuf[NI_MAXSERV]; - struct addrinfo hints, *res, *r; - int error; - struct sockaddr_storage from; - sigset_t oldmask, mask; - pid_t pid; - int s, lport; - struct timespec timo; - char c, *p; - int refused; - in_port_t rport = porta; - int numread; - - /* call rcmdsh() with specified remote shell if appropriate. */ - if (!issetugid() && (p = getenv("RSH")) && *p) { - struct servent *sp = getservbyname("shell", "tcp"); - - if (sp && sp->s_port == rport) - return (rcmdsh(ahost, rport, locuser, remuser, - cmd, p)); - } - - /* use rsh(1) if non-root and remote port is shell. */ - if (geteuid()) { - struct servent *sp = getservbyname("shell", "tcp"); - - if (sp && sp->s_port == rport) - return (rcmdsh(ahost, rport, locuser, remuser, - cmd, NULL)); - } - - pid = getpid(); - snprintf(pbuf, sizeof(pbuf), "%u", ntohs(rport)); - memset(&hints, 0, sizeof(hints)); - hints.ai_family = af; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_CANONNAME; - error = getaddrinfo(*ahost, pbuf, &hints, &res); - if (error) { - (void)fprintf(stderr, "rcmd: %s: %s\n", *ahost, - gai_strerror(error)); - return (-1); - } - if (res->ai_canonname) { - strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); - *ahost = hbuf; - } else - ; /*XXX*/ - - r = res; - refused = 0; - timespecclear(&timo); - sigemptyset(&mask); - sigaddset(&mask, SIGURG); - sigprocmask(SIG_BLOCK, &mask, &oldmask); - for (timo.tv_sec = 1, lport = IPPORT_RESERVED - 1;;) { - s = rresvport_af(&lport, r->ai_family); - if (s < 0) { - if (errno == EAGAIN) - (void)fprintf(stderr, - "rcmd: socket: All ports in use\n"); - else - (void)fprintf(stderr, "rcmd: socket: %s\n", - strerror(errno)); - if (r->ai_next) { - r = r->ai_next; - continue; - } else { - sigprocmask(SIG_SETMASK, &oldmask, NULL); - freeaddrinfo(res); - return (-1); - } - } - fcntl(s, F_SETOWN, pid); - if (connect(s, r->ai_addr, r->ai_addrlen) >= 0) - break; - (void)close(s); - if (errno == EADDRINUSE) { - lport--; - continue; - } - if (errno == ECONNREFUSED) - refused++; - if (r->ai_next) { - int oerrno = errno; - char hbuf[NI_MAXHOST]; - const int niflags = NI_NUMERICHOST; - - hbuf[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) - strlcpy(hbuf, "(invalid)", sizeof hbuf); - (void)fprintf(stderr, "connect to address %s: ", hbuf); - errno = oerrno; - perror(0); - r = r->ai_next; - hbuf[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) - strlcpy(hbuf, "(invalid)", sizeof hbuf); - (void)fprintf(stderr, "Trying %s...\n", hbuf); - continue; - } - if (refused && timo.tv_sec <= 16) { - (void)nanosleep(&timo, NULL); - timo.tv_sec *= 2; - r = res; - refused = 0; - continue; - } - (void)fprintf(stderr, "%s: %s\n", res->ai_canonname, - strerror(errno)); - sigprocmask(SIG_SETMASK, &oldmask, NULL); - freeaddrinfo(res); - return (-1); - } - /* given "af" can be PF_UNSPEC, we need the real af for "s" */ - af = r->ai_family; - freeaddrinfo(res); - if (fd2p == 0) { - write(s, "", 1); - lport = 0; - } else { - struct pollfd pfd[2]; - char num[8]; - int s2 = rresvport_af(&lport, af), s3; - socklen_t len = sizeof(from); - - if (s2 < 0) - goto bad; - - listen(s2, 1); - (void)snprintf(num, sizeof(num), "%d", lport); - if (write(s, num, strlen(num)+1) != strlen(num)+1) { - (void)fprintf(stderr, - "rcmd: write (setting up stderr): %s\n", - strerror(errno)); - (void)close(s2); - goto bad; - } -again: - pfd[0].fd = s; - pfd[0].events = POLLIN; - pfd[1].fd = s2; - pfd[1].events = POLLIN; - - errno = 0; - if (poll(pfd, 2, INFTIM) < 1 || - (pfd[1].revents & (POLLIN|POLLHUP)) == 0) { - if (errno != 0) - (void)fprintf(stderr, - "rcmd: poll (setting up stderr): %s\n", - strerror(errno)); - else - (void)fprintf(stderr, - "poll: protocol failure in circuit setup\n"); - (void)close(s2); - goto bad; - } - s3 = accept(s2, (struct sockaddr *)&from, &len); - if (s3 < 0) { - (void)fprintf(stderr, - "rcmd: accept: %s\n", strerror(errno)); - lport = 0; - close(s2); - goto bad; - } - - /* - * XXX careful for ftp bounce attacks. If discovered, shut them - * down and check for the real auxiliary channel to connect. - */ - switch (from.ss_family) { - case AF_INET: - case AF_INET6: - if (getnameinfo((struct sockaddr *)&from, len, - NULL, 0, num, sizeof(num), NI_NUMERICSERV) == 0 && - atoi(num) != 20) { - break; - } - close(s3); - goto again; - default: - break; - } - (void)close(s2); - - *fd2p = s3; - switch (from.ss_family) { - case AF_INET: - case AF_INET6: - if (getnameinfo((struct sockaddr *)&from, len, - NULL, 0, num, sizeof(num), NI_NUMERICSERV) != 0 || - (atoi(num) >= IPPORT_RESERVED || - atoi(num) < IPPORT_RESERVED / 2)) { - (void)fprintf(stderr, - "socket: protocol failure in circuit setup.\n"); - goto bad2; - } - break; - default: - break; - } - } - (void)write(s, locuser, strlen(locuser)+1); - (void)write(s, remuser, strlen(remuser)+1); - (void)write(s, cmd, strlen(cmd)+1); - if ((numread = read(s, &c, 1)) != 1) { - (void)fprintf(stderr, - "rcmd: %s: %s\n", *ahost, - numread == -1 ? strerror(errno) : "Short read"); - goto bad2; - } - if (c != 0) { - while (read(s, &c, 1) == 1) { - (void)write(STDERR_FILENO, &c, 1); - if (c == '\n') - break; - } - goto bad2; - } - sigprocmask(SIG_SETMASK, &oldmask, NULL); - return (s); -bad2: - if (lport) - (void)close(*fd2p); -bad: - (void)close(s); - sigprocmask(SIG_SETMASK, &oldmask, NULL); - return (-1); -} -DEF_WEAK(rcmd_af); - diff --git a/src/lib/libc/net/rcmdsh.3 b/src/lib/libc/net/rcmdsh.3 deleted file mode 100644 index 9092d19f81..0000000000 --- a/src/lib/libc/net/rcmdsh.3 +++ /dev/null @@ -1,95 +0,0 @@ -.\" $OpenBSD: rcmdsh.3,v 1.18 2016/05/28 15:48:30 millert Exp $ -.\" -.\" Copyright (c) 1983, 1991, 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. 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. -.\" -.Dd $Mdocdate: May 28 2016 $ -.Dt RCMDSH 3 -.Os -.Sh NAME -.Nm rcmdsh -.Nd return a stream to a remote command without superuser -.Sh SYNOPSIS -.In unistd.h -.Ft int -.Fn rcmdsh "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "char *rshprog" -.Sh DESCRIPTION -The -.Fn rcmdsh -function is used by normal users to execute a command on a remote machine -using an authentication scheme based on reserved port numbers using -.Xr ssh 1 -or the value of -.Fa rshprog -(if non-null). -.Fa rshprog -may be a fully-qualified path, a non-qualified command, or a command containing -space-separated command line arguments. -.Pp -The -.Fn rcmdsh -function looks up the host -.Fa *ahost -using -.Xr getaddrinfo 3 -and, if the host exists, -.Fa *ahost -is set to the canonical name of the host. -A connection is then established to -a server residing at the well-known Internet port -.Li shell/tcp -(or whatever port is used by -.Fa rshprog ) . -The parameter -.Fa inport -is ignored; it is only included to provide an interface similar to -.Xr rcmd 3 . -.Pp -If the connection succeeds, a socket in the -.Ux Ns -domain -of type -.Dv SOCK_STREAM -is returned to the caller, and given to the remote -command as stdin and stdout, and stderr. -.Sh DIAGNOSTICS -The -.Fn rcmdsh -function returns a valid socket descriptor on success. -It returns \-1 on error and prints a diagnostic message on the standard error. -.Sh SEE ALSO -.Xr ssh 1 , -.Xr socketpair 2 , -.Xr rcmd 3 -.Sh HISTORY -The -.Fn rcmdsh -function first appeared in -.Ox 2.0 . -.Sh BUGS -If -.Xr ssh 1 -encounters an error, a file descriptor is still returned instead of \-1. diff --git a/src/lib/libc/net/rcmdsh.c b/src/lib/libc/net/rcmdsh.c deleted file mode 100644 index 66caac3f3d..0000000000 --- a/src/lib/libc/net/rcmdsh.c +++ /dev/null @@ -1,194 +0,0 @@ -/* $OpenBSD: rcmdsh.c,v 1.20 2019/06/28 13:32:42 deraadt Exp $ */ - -/* - * Copyright (c) 2001, MagniComp - * 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. Neither the name of the MagniComp 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 COPYRIGHT HOLDERS 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. - */ - -/* - * This is an rcmd() replacement originally by - * Chris Siebenmann . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * This is a replacement rcmd() function that uses the ssh(1) - * program in place of a direct rcmd(3) function call so as to - * avoid having to be root. Note that rport is ignored. - */ -int -rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, - const char *cmd, char *rshprog) -{ - static char hbuf[HOST_NAME_MAX+1]; - struct addrinfo hint, *res; - int sp[2]; - pid_t cpid; - char *p, pwbuf[_PW_BUF_LEN]; - struct passwd pwstore, *pw = NULL; - - /* What rsh/shell to use. */ - if (rshprog == NULL) - rshprog = _PATH_RSH; - - /* locuser must exist on this host. */ - getpwnam_r(locuser, &pwstore, pwbuf, sizeof(pwbuf), &pw); - if (pw == NULL) { - (void) fprintf(stderr, "rcmdsh: unknown user: %s\n", locuser); - return(-1); - } - - /* Validate remote hostname. */ - if (strcmp(*ahost, "localhost") != 0) { - memset(&hint, 0, sizeof(hint)); - hint.ai_family = PF_UNSPEC; - hint.ai_flags = AI_CANONNAME; - if (getaddrinfo(*ahost, NULL, &hint, &res) == 0) { - if (res->ai_canonname) { - strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); - *ahost = hbuf; - } - freeaddrinfo(res); - } - } - - /* Get a socketpair we'll use for stdin and stdout. */ - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) == -1) { - perror("rcmdsh: socketpair"); - return(-1); - } - - cpid = fork(); - if (cpid == -1) { - perror("rcmdsh: fork failed"); - return(-1); - } else if (cpid == 0) { - /* - * Child. We use sp[1] to be stdin/stdout, and close sp[0]. - */ - (void) close(sp[0]); - if (dup2(sp[1], 0) == -1 || dup2(0, 1) == -1) { - perror("rcmdsh: dup2 failed"); - _exit(255); - } - /* Fork again to lose parent. */ - cpid = fork(); - if (cpid == -1) { - perror("rcmdsh: fork to lose parent failed"); - _exit(255); - } - if (cpid > 0) - _exit(0); - - /* In grandchild here. Become local user for rshprog. */ - if (setuid(pw->pw_uid)) { - (void) fprintf(stderr, "rcmdsh: setuid(%u): %s\n", - pw->pw_uid, strerror(errno)); - _exit(255); - } - - /* - * If remote host is "localhost" and local and remote user - * are the same, avoid running remote shell for efficiency. - */ - if (!strcmp(*ahost, "localhost") && !strcmp(locuser, remuser)) { - char *argv[4]; - if (pw->pw_shell[0] == '\0') - rshprog = _PATH_BSHELL; - else - rshprog = pw->pw_shell; - p = strrchr(rshprog, '/'); - argv[0] = p ? p + 1 : rshprog; - argv[1] = "-c"; - argv[2] = (char *)cmd; - argv[3] = NULL; - execvp(rshprog, argv); - } else if ((p = strchr(rshprog, ' ')) == NULL) { - /* simple case */ - char *argv[6]; - p = strrchr(rshprog, '/'); - argv[0] = p ? p + 1 : rshprog; - argv[1] = "-l"; - argv[2] = (char *)remuser; - argv[3] = *ahost; - argv[4] = (char *)cmd; - argv[5] = NULL; - execvp(rshprog, argv); - } else { - /* must pull args out of rshprog and dyn alloc argv */ - char **argv, **ap; - int n; - for (n = 7; (p = strchr(++p, ' ')) != NULL; n++) - continue; - rshprog = strdup(rshprog); - ap = argv = calloc(sizeof(char *), n); - if (rshprog == NULL || argv == NULL) { - perror("rcmdsh"); - _exit(255); - } - while ((p = strsep(&rshprog, " ")) != NULL) { - if (*p == '\0') - continue; - *ap++ = p; - } - if (ap != argv) /* all spaces?!? */ - rshprog = argv[0]; - if ((p = strrchr(argv[0], '/')) != NULL) - argv[0] = p + 1; - *ap++ = "-l"; - *ap++ = (char *)remuser; - *ap++ = *ahost; - *ap++ = (char *)cmd; - *ap++ = NULL; - execvp(rshprog, argv); - } - (void) fprintf(stderr, "rcmdsh: execvp %s failed: %s\n", - rshprog, strerror(errno)); - _exit(255); - } else { - /* Parent. close sp[1], return sp[0]. */ - (void) close(sp[1]); - /* Reap child. */ - while (waitpid(cpid, NULL, 0) == -1 && errno == EINTR) - ; - return(sp[0]); - } - /* NOTREACHED */ -} -DEF_WEAK(rcmdsh); diff --git a/src/lib/libc/net/recv.c b/src/lib/libc/net/recv.c deleted file mode 100644 index 1488ca26bd..0000000000 --- a/src/lib/libc/net/recv.c +++ /dev/null @@ -1,41 +0,0 @@ -/* $OpenBSD: recv.c,v 1.7 2023/03/25 19:16:34 otto Exp $ */ -/* - * Copyright (c) 1988, 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. 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. - */ - -#include -#include - -#include - -ssize_t -recv(int s, void *buf, size_t len, int flags) -{ - return (recvfrom(s, buf, len, flags, NULL, NULL)); -} -DEF_WEAK(recv); diff --git a/src/lib/libc/net/res_comp.c b/src/lib/libc/net/res_comp.c deleted file mode 100644 index ce9f92ae77..0000000000 --- a/src/lib/libc/net/res_comp.c +++ /dev/null @@ -1,466 +0,0 @@ -/* $OpenBSD: res_comp.c,v 1.23 2023/03/15 22:12:00 millert Exp $ */ - -/* - * ++Copyright++ 1985, 1993 - * - - * Copyright (c) 1985, 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. 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. - * - - * --Copyright-- - */ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -static int dn_find(u_char *, u_char *, u_char **, u_char **); - -/* - * Expand compressed domain name 'comp_dn' to full domain name. - * 'msg' is a pointer to the beginning of the message, - * 'eomorig' points to the first location after the message, - * 'exp_dn' is a pointer to a buffer of size 'length' for the result. - * Return size of compressed name or -1 if there was an error. - */ -int -dn_expand(const u_char *msg, const u_char *eomorig, const u_char *comp_dn, - char *exp_dn, int length) -{ - const u_char *cp; - char *dn; - int n, c; - char *eom; - int len = -1, checked = 0; - - if (comp_dn < msg || comp_dn >= eomorig) - return (-1); - - dn = exp_dn; - cp = comp_dn; - if (length > HOST_NAME_MAX) - length = HOST_NAME_MAX; - eom = exp_dn + length; - /* - * fetch next label in domain name - */ - while ((n = *cp++)) { - if (cp >= eomorig) /* out of range */ - return (-1); - - /* - * Check for indirection - */ - switch (n & INDIR_MASK) { - case 0: - if (dn != exp_dn) { - if (dn >= eom) - return (-1); - *dn++ = '.'; - } - if (dn+n >= eom) - return (-1); - checked += n + 1; - while (--n >= 0) { - if (((c = *cp++) == '.') || (c == '\\')) { - if (dn + n + 2 >= eom) - return (-1); - *dn++ = '\\'; - } - *dn++ = c; - if (cp >= eomorig) /* out of range */ - return (-1); - } - break; - - case INDIR_MASK: - if (len < 0) - len = cp - comp_dn + 1; - cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); - if (cp < msg || cp >= eomorig) /* out of range */ - return (-1); - checked += 2; - /* - * Check for loops in the compressed name; - * if we've looked at the whole message, - * there must be a loop. - */ - if (checked >= eomorig - msg) - return (-1); - break; - - default: - return (-1); /* flag error */ - } - } - *dn = '\0'; - if (len < 0) - len = cp - comp_dn; - return (len); -} -DEF_WEAK(dn_expand); - -/* - * Compress domain name 'exp_dn' into 'comp_dn'. - * Return the size of the compressed name or -1. - * 'length' is the size of the array pointed to by 'comp_dn'. - * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0] - * is a pointer to the beginning of the message. The list ends with NULL. - * 'lastdnptr' is a pointer to the end of the array pointed to - * by 'dnptrs'. Side effect is to update the list of pointers for - * labels inserted into the message as we compress the name. - * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' - * is NULL, we don't update the list. - */ -int -dn_comp(const char *exp_dn, u_char *comp_dn, int length, u_char **dnptrs, - u_char **lastdnptr) -{ - u_char *cp, *dn; - int c, l; - u_char **cpp, **lpp, *sp, *eob; - u_char *msg; - - dn = (u_char *)exp_dn; - cp = comp_dn; - eob = cp + length; - lpp = cpp = NULL; - if (dnptrs != NULL) { - if ((msg = *dnptrs++) != NULL) { - for (cpp = dnptrs; *cpp != NULL; cpp++) - ; - lpp = cpp; /* end of list to search */ - } - } else - msg = NULL; - for (c = *dn++; c != '\0'; ) { - /* look to see if we can use pointers */ - if (msg != NULL) { - if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) { - if (cp+1 >= eob) - return (-1); - *cp++ = (l >> 8) | INDIR_MASK; - *cp++ = l % 256; - return (cp - comp_dn); - } - /* not found, save it */ - if (lastdnptr != NULL && cpp < lastdnptr-1) { - *cpp++ = cp; - *cpp = NULL; - } - } - sp = cp++; /* save ptr to length byte */ - do { - if (c == '.') { - c = *dn++; - break; - } - if (c == '\\') { - if ((c = *dn++) == '\0') - break; - } - if (cp >= eob) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *cp++ = c; - } while ((c = *dn++) != '\0'); - /* catch trailing '.'s but not '..' */ - if ((l = cp - sp - 1) == 0 && c == '\0') { - cp--; - break; - } - if (l <= 0 || l > MAXLABEL) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *sp = l; - } - if (cp >= eob) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *cp++ = '\0'; - return (cp - comp_dn); -} - -/* - * Skip over a compressed domain name. Return the size or -1. - */ -int -__dn_skipname(const u_char *comp_dn, const u_char *eom) -{ - const u_char *cp; - int n; - - cp = comp_dn; - while (cp < eom && (n = *cp++)) { - /* - * check for indirection - */ - switch (n & INDIR_MASK) { - case 0: /* normal case, n == len */ - cp += n; - continue; - case INDIR_MASK: /* indirection */ - cp++; - break; - default: /* illegal type */ - return (-1); - } - break; - } - if (cp > eom) - return (-1); - return (cp - comp_dn); -} - -/* - * Search for expanded name from a list of previously compressed names. - * Return the offset from msg if found or -1. - * dnptrs is the pointer to the first name on the list, - * not the pointer to the start of the message. - */ -static int -dn_find(u_char *exp_dn, u_char *msg, u_char **dnptrs, u_char **lastdnptr) -{ - u_char *dn, *cp, **cpp; - int n; - u_char *sp; - - for (cpp = dnptrs; cpp < lastdnptr; cpp++) { - dn = exp_dn; - sp = cp = *cpp; - while ((n = *cp++)) { - /* - * check for indirection - */ - switch (n & INDIR_MASK) { - case 0: /* normal case, n == len */ - while (--n >= 0) { - if (*dn == '.') - goto next; - if (*dn == '\\') - dn++; - if (tolower((unsigned char)*dn++) != - tolower((unsigned char)*cp++)) - goto next; - } - if ((n = *dn++) == '\0' && *cp == '\0') - return (sp - msg); - if (n == '.') - continue; - goto next; - - case INDIR_MASK: /* indirection */ - cp = msg + (((n & 0x3f) << 8) | *cp); - break; - - default: /* illegal type */ - return (-1); - } - } - if (*dn == '\0') - return (sp - msg); - next: ; - } - return (-1); -} - -/* - * Verify that a domain name uses an acceptable character set. - */ - -/* - * Note the conspicuous absence of ctype macros in these definitions. On - * non-ASCII hosts, we can't depend on string literals or ctype macros to - * tell us anything about network-format data. The rest of the BIND system - * is not careful about this, but for some reason, we're doing it right here. - */ -#define PERIOD 0x2e -#define hyphenchar(c) ((c) == 0x2d) -#define bslashchar(c) ((c) == 0x5c) -#define underscorechar(c) ((c) == 0x5f) -#define periodchar(c) ((c) == PERIOD) -#define asterchar(c) ((c) == 0x2a) -#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \ - || ((c) >= 0x61 && (c) <= 0x7a)) -#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) - -#define borderchar(c) (alphachar(c) || digitchar(c)) -#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) -#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) - -int -__res_hnok(const char *dn) -{ - int pch = PERIOD, ch = *dn++; - - while (ch != '\0') { - int nch = *dn++; - - if (periodchar(ch)) { - ; - } else if (periodchar(pch)) { - if (!borderchar(ch)) - return (0); - } else if (periodchar(nch) || nch == '\0') { - if (!borderchar(ch)) - return (0); - } else { - if (!middlechar(ch)) - return (0); - } - pch = ch, ch = nch; - } - return (1); -} -DEF_STRONG(__res_hnok); - -/* - * hostname-like (A, MX, WKS) owners can have "*" as their first label - * but must otherwise be as a host name. - */ -int -res_ownok(const char *dn) -{ - if (asterchar(dn[0])) { - if (periodchar(dn[1])) - return (res_hnok(dn+2)); - if (dn[1] == '\0') - return (1); - } - return (res_hnok(dn)); -} - -/* - * SOA RNAMEs and RP RNAMEs can have any printable character in their first - * label, but the rest of the name has to look like a host name. - */ -int -res_mailok(const char *dn) -{ - int ch, escaped = 0; - - /* "." is a valid missing representation */ - if (*dn == '\0') - return(1); - - /* otherwise