diff options
Diffstat (limited to 'lib/libc/net')
62 files changed, 0 insertions, 12946 deletions
diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc deleted file mode 100644 index c7381db..0000000 --- a/lib/libc/net/Makefile.inc +++ /dev/null @@ -1,54 +0,0 @@ -# from @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 -# $Id: Makefile.inc,v 1.24 1997/10/15 16:15:41 bde Exp $ - -# machine-independent net sources -.PATH: ${.CURDIR}/../libc/${MACHINE}/net ${.CURDIR}/../libc/net - -SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c \ - gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \ - getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \ - getproto.c getprotoent.c getprotoname.c getservbyname.c \ - getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \ - inet_makeaddr.c inet_net_ntop.c inet_net_pton.c inet_neta.c \ - inet_netof.c inet_network.c inet_ntoa.c inet_ntop.c \ - inet_pton.c linkaddr.c map_v4v6.c ns_addr.c ns_ntoa.c nsap_addr.c \ - rcmd.c recv.c res_comp.c res_data.c res_debug.c \ - res_init.c res_mkquery.c res_query.c res_send.c res_stubs.c \ - send.c -# not supported: iso_addr.c - -# machine-dependent net sources -.include "${.CURDIR}/../libc/${MACHINE}/net/Makefile.inc" - -.if ${LIB} == "c" -MAN3+= addr2ascii.3 byteorder.3 ethers.3 gethostbyname.3 \ - getnetent.3 getprotoent.3 getservent.3 \ - inet.3 linkaddr.3 rcmd.3 resolver.3 -# not installed: iso_addr.3 ns.3 - -MLINKS+=addr2ascii.3 ascii2addr.3 -MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ - byteorder.3 ntohs.3 -MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ - ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 -MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ - gethostbyname.3 gethostbyname2.3 gethostbyname.3 gethostent.3 \ - gethostbyname.3 herror.3 gethostbyname.3 hstrerror.3 \ - gethostbyname.3 sethostent.3 -MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \ - getnetent.3 getnetbyname.3 getnetent.3 setnetent.3 -MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \ - getprotoent.3 getprotobynumber.3 getprotoent.3 setprotoent.3 -MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \ - getservent.3 getservbyport.3 getservent.3 setservent.3 -MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \ - inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ - inet.3 inet_network.3 inet.3 inet_ntoa.3 inet.3 network.3 \ - inet.3 ntoa.3 -MLINKS+=linkaddr.3 link_addr.3 linkaddr.3 link_ntoa.3 -#MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3 -MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 -MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ - resolver.3 res_mkquery.3 resolver.3 res_query.3 \ - resolver.3 res_search.3 resolver.3 res_send.3 -.endif diff --git a/lib/libc/net/addr2ascii.3 b/lib/libc/net/addr2ascii.3 deleted file mode 100644 index 282acac..0000000 --- a/lib/libc/net/addr2ascii.3 +++ /dev/null @@ -1,215 +0,0 @@ -.\" -.\" Copyright 1996 Massachusetts Institute of Technology -.\" -.\" Permission to use, copy, modify, and distribute this software and -.\" its documentation for any purpose and without fee is hereby -.\" granted, provided that both the above copyright notice and this -.\" permission notice appear in all copies, that both the above -.\" copyright notice and this permission notice appear in all -.\" supporting documentation, and that the name of M.I.T. not be used -.\" in advertising or publicity pertaining to distribution of the -.\" software without specific, written prior permission. M.I.T. makes -.\" no representations about the suitability of this software for any -.\" purpose. It is provided "as is" without express or implied -.\" warranty. -.\" -.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS -.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, -.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT -.\" SHALL M.I.T. 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. -.\" -.\" $ANA: addr2ascii.3,v 1.1 1996/06/13 18:41:46 wollman Exp $ -.\" -.Dd June 13, 1996 -.Dt ADDR2ASCII 3 -.Os -.Sh NAME -.Nm addr2ascii , -.Nm ascii2addr -.Nd Generic address formatting routines -.Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/socket.h> -.Fd #include <netinet/in.h> -.Fd #include <arpa/inet.h> -.Ft "char *" -.Fn addr2ascii "int af" "const void *addrp" "int len" "char *buf" -.Ft int -.Fn ascii2addr "int af" "const char *ascii" "void *result" -.Sh DESCRIPTION -The routines -.Fn addr2ascii -and -.Fn ascii2addr -are used to convert network addresses between binary form and a -printable form appropriate to the address family. Both functions take -an -.Fa af -argument, specifying the address family to be used in the conversion -process. -(Currently, only the -.Dv AF_INET -and -.Dv AF_LINK -address families are supported.) -.Pp -The -.Fn addr2ascii -function -is used to convert binary, network-format addresses into printable -form. In addition to -.Fa af , -there are three other arguments. The -.Fa addrp -argument is a pointer to the network address to be converted. -The -.Fa len -argument is the length of the address. The -.Fa buf -argument is an optional pointer to a caller-allocated buffer to hold -the result; if a null pointer is passed, -.Fn addr2ascii -uses a statically-allocated buffer. -.Pp -The -.Fn ascii2addr -function performs the inverse operation to -.Fn addr2ascii . -In addition to -.Fa af , -it takes two parameters, -.Fa ascii -and -.Fa result . -The -.Fa ascii -parameter is a pointer to the string which is to be converted into -binary. The -.Fa result -parameter is a pointer to an appropriate network address structure for -the specified family. -.Pp -The following gives the appropriate structure to use for binary -addresses in the specified family: -.Pp -.Bl -tag -width AF_INETxxxx -compact -.It Dv AF_INET -.Li struct in_addr -.Pq in Aq Pa netinet/in.h -.It Dv AF_LINK -.Li struct sockaddr_dl -.Pq in Aq Pa net/if_dl.h -.\" .It Dv AF_INET6 -.\" .Li struct in6_addr -.\" .Pq in Aq Pa netinet6/in6.h -.El -.Sh RETURN VALUES -The -.Fn addr2ascii -function returns the address of the buffer it was passed, or a static -buffer if the a null pointer was passed; on failure, it returns a null -pointer. -The -.Fn ascii2addr -function returns the length of the binary address in bytes, or -1 on -failure. -.Sh EXAMPLES -The -.Xr inet 3 -functions -.Fn inet_ntoa -and -.Fn inet_aton -could be implemented thusly: -.Bd -literal -offset indent -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -char * -inet_ntoa(struct in_addr addr) -{ - return addr2ascii(AF_INET, &addr, sizeof addr, 0); -} - -int -inet_aton(const char *ascii, struct in_addr *addr) -{ - return (ascii2addr(AF_INET, ascii, addr) - == sizeof(*addr)); -} -.Ed -.Pp -In actuality, this cannot be done because -.Fn addr2ascii -and -.Fn ascii2addr -are implemented in terms of the -.Xr inet 3 -functions, rather than the other way around. -.Sh ERRORS -When a failure is returned, -.Li errno -is set to one of the following values: -.Bl -tag -width [EPROTONOSUPPORT] -.It Bq Er ENAMETOOLONG -The -.Fn addr2ascii -routine was passed a -.Fa len -parameter which was inappropriate for the address family given by -.Fa af . -.It Bq Er EPROTONOSUPPORT -Either routine was passed an -.Fa af -parameter other than -.Dv AF_INET -or -.Dv AF_LINK . -.It Bq Er EINVAL -The string passed to -.Fn ascii2addr -was improperly formatted for address family -.Fa af . -.El -.Sh SEE ALSO -.Xr inet 3 , -.Xr linkaddr 3 , -.Xr inet 4 -.Sh HISTORY -An interface close to this one was originally suggested by Craig -Partridge. This particular interface originally apppeared in the -.Tn INRIA -.Tn IPv6 -implementation. -.Sh AUTHOR -Code and documentation by Garrett A. Wollman, MIT Laboratory for -Computer Science. -.Sh BUGS -The original implementations supported IPv6. This support should -eventually be resurrected. The -.Tn NRL -implementation also included support for the -.Dv AF_ISO -and -.Dv AF_NS -address families. -.Pp -The genericity of this interface is somewhat questionable. A truly -generic interface would provide a means for determining the length of -the buffer to be used so that it could be dynamically allocated, and -would always require a -.Dq Li "struct sockaddr" -to hold the binary address. Unfortunately, this is incompatible with existing -practice. This limitation means that a routine for printing network -addresses from arbitrary address families must still have internal -knowledge of the maximum buffer length needed and the appropriate part -of the address to use as the binary address. diff --git a/lib/libc/net/addr2ascii.c b/lib/libc/net/addr2ascii.c deleted file mode 100644 index 5bee3ea..0000000 --- a/lib/libc/net/addr2ascii.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 1996 Massachusetts Institute of Technology - * - * Permission to use, copy, modify, and distribute this software and - * its documentation for any purpose and without fee is hereby - * granted, provided that both the above copyright notice and this - * permission notice appear in all copies, that both the above - * copyright notice and this permission notice appear in all - * supporting documentation, and that the name of M.I.T. not be used - * in advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. M.I.T. makes - * no representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied - * warranty. - * - * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS - * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT - * SHALL M.I.T. 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. - * - * $ANA: addr2ascii.c,v 1.1 1996/06/13 18:41:46 wollman Exp $ - */ - -#include <sys/types.h> -#include <sys/socket.h> - -#include <errno.h> -#include <string.h> - -#include <net/if_dl.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -/*- - * Convert a network address from binary to printable numeric format. - * This API is copied from INRIA's IPv6 implementation, but it is a - * bit bogus in two ways: - * - * 1) There is no value in passing both an address family and - * an address length; either one should imply the other, - * or we should be passing sockaddrs instead. - * 2) There should by contrast be /added/ a length for the buffer - * that we pass in, so that programmers are spared the need to - * manually calculate (read: ``guess'') the maximum length. - * - * Flash: the API is also the same in the NRL implementation, and seems to - * be some sort of standard, so we appear to be stuck with both the bad - * naming and the poor choice of arguments. - */ -char * -addr2ascii(af, addrp, len, buf) - int af; - const void *addrp; - int len; /* should be size_t XXX */ - char *buf; /* XXX should pass length of buffer */ -{ - static char staticbuf[64]; /* 64 for AF_LINK > 16 for AF_INET */ - - if (!buf) - buf = staticbuf; - - switch(af) { - case AF_INET: - if (len != sizeof(struct in_addr)) { - errno = ENAMETOOLONG; - return 0; - } - strcpy(buf, inet_ntoa(*(const struct in_addr *)addrp)); - break; - - case AF_LINK: - if (len != sizeof(struct sockaddr_dl)) { - errno = ENAMETOOLONG; - return 0; - } - strcpy(buf, link_ntoa((const struct sockaddr_dl *)addrp)); - break; - - default: - errno = EPROTONOSUPPORT; - return 0; - } - return buf; -} diff --git a/lib/libc/net/ascii2addr.c b/lib/libc/net/ascii2addr.c deleted file mode 100644 index 0b5bab4..0000000 --- a/lib/libc/net/ascii2addr.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 1996 Massachusetts Institute of Technology - * - * Permission to use, copy, modify, and distribute this software and - * its documentation for any purpose and without fee is hereby - * granted, provided that both the above copyright notice and this - * permission notice appear in all copies, that both the above - * copyright notice and this permission notice appear in all - * supporting documentation, and that the name of M.I.T. not be used - * in advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. M.I.T. makes - * no representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied - * warranty. - * - * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS - * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT - * SHALL M.I.T. 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. - * - * $ANA: ascii2addr.c,v 1.2 1996/06/13 18:46:02 wollman Exp $ - */ - -#include <sys/types.h> -#include <sys/socket.h> - -#include <errno.h> -#include <string.h> - -#include <net/if_dl.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -int -ascii2addr(af, ascii, result) - int af; - const char *ascii; - void *result; -{ - struct in_addr *ina; - char strbuf[4*sizeof("123")]; /* long enough for V4 only */ - - switch(af) { - case AF_INET: - ina = result; - strbuf[0] = '\0'; - strncat(strbuf, ascii, (sizeof strbuf)-1); - if (inet_aton(strbuf, ina)) - return sizeof(struct in_addr); - errno = EINVAL; - break; - - case AF_LINK: - link_addr(ascii, result); - /* oops... no way to detect failure */ - return sizeof(struct sockaddr_dl); - - default: - errno = EPROTONOSUPPORT; - break; - } - - return -1; -} diff --git a/lib/libc/net/base64.c b/lib/libc/net/base64.c deleted file mode 100644 index 868826a..0000000 --- a/lib/libc/net/base64.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * 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 <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> - -#include <ctype.h> -#include <resolv.h> -#include <stdio.h> - -#if defined(BSD) && (BSD >= 199103) && defined(AF_INET6) -# include <stdlib.h> -# include <string.h> -#else -# include "../conf/portability.h" -#endif - -#define Assert(Cond) if (!(Cond)) abort() - -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(src, srclength, target, targsize) - u_char const *src; - size_t srclength; - char *target; - size_t targsize; -{ - size_t datalength = 0; - u_char input[3]; - u_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; - Assert(output[0] < 64); - Assert(output[1] < 64); - Assert(output[2] < 64); - Assert(output[3] < 64); - - 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); - Assert(output[0] < 64); - Assert(output[1] < 64); - Assert(output[2] < 64); - - 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(src, target, targsize) - char const *src; - u_char *target; - size_t targsize; -{ - int tarindex, state, ch; - char *pos; - - state = 0; - tarindex = 0; - - while ((ch = *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 + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex+1] = ((pos - Base64) & 0x0f) - << 4 ; - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex+1] = ((pos - Base64) & 0x03) - << 6; - } - tarindex++; - state = 3; - break; - case 3: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64); - } - tarindex++; - state = 0; - break; - default: - abort(); - } - } - - /* - * 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 = *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 (NULL; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return (-1); - ch = *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 (NULL; ch != '\0'; ch = *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 && 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/lib/libc/net/byteorder.3 b/lib/libc/net/byteorder.3 deleted file mode 100644 index 666521b..0000000 --- a/lib/libc/net/byteorder.3 +++ /dev/null @@ -1,76 +0,0 @@ -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt BYTEORDER 3 -.Os BSD 4.2 -.Sh NAME -.Nm htonl , -.Nm htons , -.Nm ntohl , -.Nm ntohs -.Nd convert values between host and network byte order -.Sh SYNOPSIS -.Fd #include <sys/param.h> -.Ft u_long -.Fn htonl "u_long hostlong" -.Ft u_short -.Fn htons "u_short hostshort" -.Ft u_long -.Fn ntohl "u_long netlong" -.Ft u_short -.Fn ntohs "u_short netshort" -.Sh DESCRIPTION -These routines convert 16 and 32 bit quantities between network -byte order and host byte order. -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 -.Sh HISTORY -The -.Nm byteorder -functions appeared in -.Bx 4.2 . -.Sh BUGS -On the -.Tn VAX -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/lib/libc/net/ether_addr.c b/lib/libc/net/ether_addr.c deleted file mode 100644 index 9b7a9ab..0000000 --- a/lib/libc/net/ether_addr.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (c) 1995 - * Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY Bill Paul 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. - * - * ethernet address conversion and lookup routines - * - * Written by Bill Paul <wpaul@ctr.columbia.edu> - * Center for Telecommunications Research - * Columbia University, New York City - * - * $Id$ - */ - - -#include <stdio.h> -#include <paths.h> -#include <sys/types.h> -#include <string.h> -#include <stdlib.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <net/ethernet.h> -#ifdef YP -#include <rpc/rpc.h> -#include <rpcsvc/yp_prot.h> -#include <rpcsvc/ypclnt.h> -#endif - -#ifndef _PATH_ETHERS -#define _PATH_ETHERS "/etc/ethers" -#endif - -/* - * Parse a string of text containing an ethernet address and hostname - * and separate it into its component parts. - */ -int ether_line(l, e, hostname) - char *l; - struct ether_addr *e; - char *hostname; -{ - int i, o[6]; - - i = sscanf(l, "%x:%x:%x:%x:%x:%x %s", &o[0], &o[1], &o[2], - &o[3], &o[4], &o[5], - hostname); - if (i != 7) - return (i); - - for (i=0; i<6; i++) - e->octet[i] = o[i]; - return (0); -} - -/* - * Convert an ASCII representation of an ethernet address to - * binary form. - */ -struct ether_addr *ether_aton(a) - char *a; -{ - int i; - static struct ether_addr o; - unsigned int o0, o1, o2, o3, o4, o5; - - i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5); - - if (i != 6) - return (NULL); - - o.octet[0]=o0; - o.octet[1]=o1; - o.octet[2]=o2; - o.octet[3]=o3; - o.octet[4]=o4; - o.octet[5]=o5; - - return ((struct ether_addr *)&o); -} - -/* - * Convert a binary representation of an ethernet address to - * an ASCII string. - */ -char *ether_ntoa(n) - struct ether_addr *n; -{ - int i; - static char a[18]; - - i = sprintf(a,"%x:%x:%x:%x:%x:%x",n->octet[0],n->octet[1],n->octet[2], - n->octet[3],n->octet[4],n->octet[5]); - if (i < 11) - return (NULL); - return ((char *)&a); -} - -/* - * Map an ethernet address to a hostname. Use either /etc/ethers or - * NIS/YP. - */ - -int ether_ntohost(hostname, e) - char *hostname; - struct ether_addr *e; -{ - FILE *fp; - char buf[BUFSIZ + 2]; - struct ether_addr local_ether; - char local_host[MAXHOSTNAMELEN]; -#ifdef YP - char *result; - int resultlen; - char *ether_a; - char *yp_domain; -#endif - if ((fp = fopen(_PATH_ETHERS, "r")) == NULL) - return (1); - - while (fgets(buf,BUFSIZ,fp)) { - if (buf[0] == '#') - continue; -#ifdef YP - if (buf[0] == '+') { - if (yp_get_default_domain(&yp_domain)) - continue; - ether_a = ether_ntoa(e); - if (yp_match(yp_domain, "ethers.byaddr", ether_a, - strlen(ether_a), &result, &resultlen)) { - continue; - } - strncpy(buf, result, resultlen); - buf[resultlen] = '\0'; - free(result); - } -#endif - if (!ether_line(buf, &local_ether, local_host)) { - if (!bcmp((char *)&local_ether.octet[0], - (char *)&e->octet[0], 6)) { - /* We have a match */ - strcpy(hostname, local_host); - fclose(fp); - return(0); - } - } - } - fclose(fp); - return (1); -} - -/* - * Map a hostname to an ethernet address using /etc/ethers or - * NIS/YP. - */ -int ether_hostton(hostname, e) - char *hostname; - struct ether_addr *e; -{ - FILE *fp; - char buf[BUFSIZ + 2]; - struct ether_addr local_ether; - char local_host[MAXHOSTNAMELEN]; -#ifdef YP - char *result; - int resultlen; - char *yp_domain; -#endif - if ((fp = fopen(_PATH_ETHERS, "r")) == NULL) - return (1); - - while (fgets(buf,BUFSIZ,fp)) { - if (buf[0] == '#') - continue; -#ifdef YP - if (buf[0] == '+') { - if (yp_get_default_domain(&yp_domain)) - continue; - if (yp_match(yp_domain, "ethers.byname", hostname, - strlen(hostname), &result, &resultlen)) { - continue; - } - strncpy(buf, result, resultlen); - buf[resultlen] = '\0'; - free(result); - } -#endif - if (!ether_line(buf, &local_ether, local_host)) { - if (!strcmp(hostname, local_host)) { - /* We have a match */ - bcopy((char *)&local_ether.octet[0], - (char *)&e->octet[0], 6); - fclose(fp); - return(0); - } - } - } - fclose(fp); - return (1); -} diff --git a/lib/libc/net/ethers.3 b/lib/libc/net/ethers.3 deleted file mode 100644 index afea483..0000000 --- a/lib/libc/net/ethers.3 +++ /dev/null @@ -1,193 +0,0 @@ -.\" Copyright (c) 1995 -.\" Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul. -.\" 4. Neither the name of the author nor the names of any co-contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY Bill Paul 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. -.\" -.\" $Id$ -.\" -.Dd April 12, 1995 -.Dt ETHERS 3 -.Os FreeBSD 2.1 -.Sh NAME -.Nm ethers , -.Nm ether_line , -.Nm ether_aton , -.Nm ether_ntoa , -.Nm ether_ntohost , -.Nm ether_hostton -.Nd Ethernet address conversion and lookup routines -.Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/socket.h> -.Fd #include <net/ethernet.h> -.Ft int -.Fn ether_line "char *l" "struct ether_addr *e" "char *hostname" -.Ft struct ether_addr * -.Fn ether_aton "char *a" -.Ft char * -.Fn ether_ntoa "struct ether_addr *n" -.Ft int -.Fn ether_ntohost "char *hostname" "struct ether_addr *e" -.Ft int -.Fn ether_hostton "char *hostname" "struct ether_addr *e" -.Sh DESCRIPTION -These functions operate on ethernet addresses using an -.Ar ether_addr -structure, which is defined in the header file -.Aq Pa netinet/if_ether.h : -.Bd -literal -offset indent -/* - * The number of bytes in an ethernet (MAC) address. - */ -#define ETHER_ADDR_LEN 6 - -/* - * Structure of a 48-bit Ethernet address. - */ -struct ether_addr { - u_char octet[ETHER_ADDR_LEN]; -}; -.Ed -.Pp -The function -.Fn ether_line -scans -.Ar l , -an -.Tn ASCII -string in -.Xr ethers 5 -format and sets -.Ar e -to the ethernet address specified in the string and -.Ar h -to the hostname. This function is used to parse lines from -.Pa /etc/ethers -into their component parts. -.Pp -The -.Fn ether_aton -function converts an -.Tn ASCII -representation of an ethernet address into an -.Ar ether_addr -structure. Likewise, -.Fn ether_ntoa -converts an ethernet address specified as an -.Ar ether_addr -structure into an -.Tn ASCII -string. -.Pp -The -.Fn ether_ntohost -and -.Fn ether_hostton -functions map ethernet addresses to their corresponding hostnames -as specified in the -.Pa /etc/ethers -database. -.Fn ether_ntohost -converts from ethernet address to hostname, and -.Fn ether_hostton -converts from hostname to ethernet address. -.Sh RETURN VALUES -.Fn ether_line -returns zero on success and non-zero if it was unable to parse -any part of the supplied line -.Ar l . -It returns the extracted ethernet address in the supplied -.Ar ether_addr -structure -.Ar e -and the hostname in the supplied string -.Ar h . -.Pp -On success, -.Fn ether_ntoa -returns a pointer to a string containing an -.Tn ASCII -representation of an ethernet address. If it is unable to convert -the supplied -.Ar ether_addr -structure, it returns a -.Dv NULL -pointer. Likewise, -.Fn ether_aton -returns a pointer to an -.Ar ether_addr -structure on success and a -.Dv NULL -pointer on failure. -.Pp -The -.Fn ether_ntohost -and -.Fn ether_hostton -functions both return zero on success or non-zero if they were -unable to find a match in the -.Pa /etc/ethers -database. -.Sh NOTES -The user must insure that the hostname strings passed to the -the -.Fn ether_line , -.Fn ether_ntohost -and -.Fn ether_hostton -functions are large enough to contain the returned hostnames. -.Sh NIS INTERACTION -If the -.Pa /etc/ethers -contains a line with a single + in it, the -.Fn ether_ntohost -and -.Fn ether_hostton -functions will attempt to consult the NIS -.Pa ethers.byname -and -.Pa ethers.byaddr -maps in addition to the data in the -.Pa /etc/ethers -file. -.Sh SEE ALSO -.Xr yp 4 , -.Xr ethers 5 -.Sh BUGS -.Pp -The -.Fn ether_aton -and -.Fn ether_ntoa -functions returns values that are stored in static memory areas -which may be overwritten the next time they are called. -.Sh HISTORY -This particular implementation of the -.Nm ethers -library functions were written for and first appeared in -.Fx 2.1 . diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c deleted file mode 100644 index 4d13e2e..0000000 --- a/lib/libc/net/gethostbydns.c +++ /dev/null @@ -1,736 +0,0 @@ -/* - * ++Copyright++ 1985, 1988, 1993 - * - - * Copyright (c) 1985, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; -static char fromrcsid[] = "From: Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp"; -static char rcsid[] = "$Id: gethostbydns.c,v 1.21 1997/03/12 11:02:00 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <netdb.h> -#include <resolv.h> -#include <ctype.h> -#include <errno.h> -#include <syslog.h> - -#include "res_config.h" - -#define SPRINTF(x) ((size_t)sprintf x) - -#define MAXALIASES 35 -#define MAXADDRS 35 - -static const char AskedForGot[] = - "gethostby*.gethostanswer: asked for \"%s\", got \"%s\""; - -static char *h_addr_ptrs[MAXADDRS + 1]; - -static struct hostent host; -static char *host_aliases[MAXALIASES]; -static char hostbuf[8*1024]; -static u_char host_addr[16]; /* IPv4 or IPv6 */ - -#ifdef RESOLVSORT -static void addrsort __P((char **, int)); -#endif - -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - int32_t al; - char ac; -} align; - -extern int h_errno; -int _dns_ttl_; - -#ifdef DEBUG -static void -dprintf(msg, num) - char *msg; - int num; -{ - if (_res.options & RES_DEBUG) { - int save = errno; - - printf(msg, num); - errno = save; - } -} -#else -# define dprintf(msg, num) /*nada*/ -#endif - -static struct hostent * -gethostanswer(answer, anslen, qname, qtype) - const querybuf *answer; - int anslen; - const char *qname; - int qtype; -{ - register const HEADER *hp; - register const u_char *cp; - register int n; - const u_char *eom; - char *bp, **ap, **hap; - int type, class, buflen, ancount, qdcount; - int haveanswer, had_error; - int toobig = 0; - char tbuf[MAXDNAME]; - const char *tname; - int (*name_ok) __P((const char *)); - - tname = qname; - host.h_name = NULL; - eom = answer->buf + anslen; - switch (qtype) { - case T_A: - case T_AAAA: - name_ok = res_hnok; - break; - case T_PTR: - name_ok = res_dnok; - break; - default: - h_errno = NO_RECOVERY; - return (NULL); /* XXX should be abort(); */ - } - /* - * find first satisfactory answer - */ - hp = &answer->hdr; - ancount = ntohs(hp->ancount); - qdcount = ntohs(hp->qdcount); - bp = hostbuf; - buflen = sizeof hostbuf; - cp = answer->buf + HFIXEDSZ; - if (qdcount != 1) { - h_errno = NO_RECOVERY; - return (NULL); - } - n = dn_expand(answer->buf, eom, cp, bp, buflen); - if ((n < 0) || !(*name_ok)(bp)) { - h_errno = NO_RECOVERY; - return (NULL); - } - cp += n + QFIXEDSZ; - if (qtype == T_A || qtype == T_AAAA) { - /* res_send() has already verified that the query name is the - * same as the one we sent; this just gets the expanded name - * (i.e., with the succeeding search-domain tacked on). - */ - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - h_errno = NO_RECOVERY; - return (NULL); - } - host.h_name = bp; - bp += n; - buflen -= n; - /* The qname can be abbreviated, but h_name is now absolute. */ - qname = host.h_name; - } - ap = host_aliases; - *ap = NULL; - host.h_aliases = host_aliases; - hap = h_addr_ptrs; - *hap = NULL; - host.h_addr_list = h_addr_ptrs; - haveanswer = 0; - had_error = 0; - _dns_ttl_ = -1; - while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, buflen); - if ((n < 0) || !(*name_ok)(bp)) { - had_error++; - continue; - } - cp += n; /* name */ - type = _getshort(cp); - cp += INT16SZ; /* type */ - class = _getshort(cp); - cp += INT16SZ; /* class */ - if (qtype == T_A && type == T_A) - _dns_ttl_ = _getlong(cp); - cp += INT32SZ; /* TTL */ - n = _getshort(cp); - cp += INT16SZ; /* len */ - if (class != C_IN) { - /* XXX - debug? syslog? */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { - if (ap >= &host_aliases[MAXALIASES-1]) - continue; - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !(*name_ok)(tbuf)) { - had_error++; - continue; - } - cp += n; - /* Store alias. */ - *ap++ = bp; - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - bp += n; - buflen -= n; - /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ - if (n > buflen || n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - strcpy(bp, tbuf); - host.h_name = bp; - bp += n; - buflen -= n; - continue; - } - if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if (n < 0 || !res_dnok(tbuf)) { - had_error++; - continue; - } - cp += n; - /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ - if (n > buflen || n >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - strcpy(bp, tbuf); - tname = bp; - bp += n; - buflen -= n; - continue; - } - if (type != qtype) { - syslog(LOG_NOTICE|LOG_AUTH, - "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"", - qname, p_class(C_IN), p_type(qtype), - p_type(type)); - cp += n; - continue; /* XXX - had_error++ ? */ - } - switch (type) { - case T_PTR: - if (strcasecmp(tname, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, qname, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - n = dn_expand(answer->buf, eom, cp, bp, buflen); - if ((n < 0) || !res_hnok(bp)) { - had_error++; - break; - } -#if MULTI_PTRS_ARE_ALIASES - cp += n; - if (!haveanswer) - host.h_name = bp; - else if (ap < &host_aliases[MAXALIASES-1]) - *ap++ = bp; - else - n = -1; - if (n != -1) { - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - break; - } - bp += n; - buflen -= n; - } - break; -#else - host.h_name = bp; - if (_res.options & RES_USE_INET6) { - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - break; - } - bp += n; - buflen -= n; - _map_v4v6_hostent(&host, &bp, &buflen); - } - h_errno = NETDB_SUCCESS; - return (&host); -#endif - case T_A: - case T_AAAA: - if (strcasecmp(host.h_name, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, host.h_name, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - if (n != host.h_length) { - cp += n; - continue; - } - if (!haveanswer) { - register int nn; - - host.h_name = bp; - nn = strlen(bp) + 1; /* for the \0 */ - bp += nn; - buflen -= nn; - } - - bp += sizeof(align) - ((u_long)bp % sizeof(align)); - - if (bp + n >= &hostbuf[sizeof hostbuf]) { - dprintf("size (%d) too big\n", n); - had_error++; - continue; - } - if (hap >= &h_addr_ptrs[MAXADDRS-1]) { - if (!toobig++) - dprintf("Too many addresses (%d)\n", - MAXADDRS); - cp += n; - continue; - } - bcopy(cp, *hap++ = bp, n); - bp += n; - buflen -= n; - cp += n; - break; - default: - dprintf("Impossible condition (type=%d)\n", type); - h_errno = NO_RECOVERY; - return (NULL); - /* BIND has abort() here, too risky on bad data */ - } - if (!had_error) - haveanswer++; - } - if (haveanswer) { - *ap = NULL; - *hap = NULL; -# if defined(RESOLVSORT) - /* - * Note: we sort even if host can take only one address - * in its return structures - should give it the "best" - * address in that case, not some random one - */ - if (_res.nsort && haveanswer > 1 && qtype == T_A) - addrsort(h_addr_ptrs, haveanswer); -# endif /*RESOLVSORT*/ - if (!host.h_name) { - n = strlen(qname) + 1; /* for the \0 */ - if (n > buflen || n >= MAXHOSTNAMELEN) - goto no_recovery; - strcpy(bp, qname); - host.h_name = bp; - bp += n; - buflen -= n; - } - if (_res.options & RES_USE_INET6) - _map_v4v6_hostent(&host, &bp, &buflen); - h_errno = NETDB_SUCCESS; - return (&host); - } - no_recovery: - h_errno = NO_RECOVERY; - return (NULL); -} - -struct hostent * -__dns_getanswer(answer, anslen, qname, qtype) - const char *answer; - int anslen; - const char *qname; - int qtype; -{ - switch(qtype) { - case T_AAAA: - host.h_addrtype = AF_INET6; - host.h_length = IN6ADDRSZ; - break; - case T_A: - default: - host.h_addrtype = AF_INET; - host.h_length = INADDRSZ; - break; - } - - return(gethostanswer((const querybuf *)answer, anslen, qname, qtype)); -} - -struct hostent * -_gethostbydnsname(name, af) - const char *name; - int af; -{ - querybuf buf; - register const char *cp; - char *bp; - int n, size, type, len; - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - - switch (af) { - case AF_INET: - size = INADDRSZ; - type = T_A; - break; - case AF_INET6: - size = IN6ADDRSZ; - type = T_AAAA; - break; - default: - h_errno = NETDB_INTERNAL; - errno = EAFNOSUPPORT; - return (NULL); - } - - host.h_addrtype = af; - host.h_length = size; - - /* - * if there aren't any dots, it could be a user-level alias. - * this is also done in res_query() since we are not the only - * function that looks up host names. - */ - if (!strchr(name, '.') && (cp = __hostalias(name))) - name = cp; - - /* - * disallow names consisting only of digits/dots, unless - * they end in a dot. - */ - if (isdigit(name[0])) - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-numeric, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - strncpy(hostbuf, name, MAXDNAME); - hostbuf[MAXDNAME] = '\0'; - bp = hostbuf + MAXDNAME; - len = sizeof hostbuf - MAXDNAME; - host.h_name = hostbuf; - host.h_aliases = host_aliases; - host_aliases[0] = NULL; - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - if (_res.options & RES_USE_INET6) - _map_v4v6_hostent(&host, &bp, &len); - h_errno = NETDB_SUCCESS; - return (&host); - } - if (!isdigit(*cp) && *cp != '.') - break; - } - if ((isxdigit(name[0]) && strchr(name, ':') != NULL) || - name[0] == ':') - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-IPv6-legal, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - strncpy(hostbuf, name, MAXDNAME); - hostbuf[MAXDNAME] = '\0'; - bp = hostbuf + MAXDNAME; - len = sizeof hostbuf - MAXDNAME; - host.h_name = hostbuf; - host.h_aliases = host_aliases; - host_aliases[0] = NULL; - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - h_errno = NETDB_SUCCESS; - return (&host); - } - if (!isxdigit(*cp) && *cp != ':' && *cp != '.') - break; - } - - if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) { - dprintf("res_search failed (%d)\n", n); - return (NULL); - } - return (gethostanswer(&buf, n, name, type)); -} - -struct hostent * -_gethostbydnsaddr(addr, len, af) - const char *addr; /* XXX should have been def'd as u_char! */ - int len, af; -{ - const u_char *uaddr = (const u_char *)addr; - static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff }; - static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 }; - int n, size; - querybuf buf; - register struct hostent *hp; - char qbuf[MAXDNAME+1], *qp; -#ifdef SUNSECURITY - register struct hostent *rhp; - char **haddr; - u_long old_options; - char hname2[MAXDNAME+1]; -#endif /*SUNSECURITY*/ - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - if (af == AF_INET6 && len == IN6ADDRSZ && - (!bcmp(uaddr, mapped, sizeof mapped) || - !bcmp(uaddr, tunnelled, sizeof tunnelled))) { - /* Unmap. */ - addr += sizeof mapped; - uaddr += sizeof mapped; - af = AF_INET; - len = INADDRSZ; - } - switch (af) { - case AF_INET: - size = INADDRSZ; - break; - case AF_INET6: - size = IN6ADDRSZ; - break; - default: - errno = EAFNOSUPPORT; - h_errno = NETDB_INTERNAL; - return (NULL); - } - if (size != len) { - errno = EINVAL; - h_errno = NETDB_INTERNAL; - return (NULL); - } - switch (af) { - case AF_INET: - (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", - (uaddr[3] & 0xff), - (uaddr[2] & 0xff), - (uaddr[1] & 0xff), - (uaddr[0] & 0xff)); - break; - case AF_INET6: - qp = qbuf; - for (n = IN6ADDRSZ - 1; n >= 0; n--) { - qp += SPRINTF((qp, "%x.%x.", - uaddr[n] & 0xf, - (uaddr[n] >> 4) & 0xf)); - } - strcpy(qp, "ip6.int"); - break; - default: - abort(); - } - n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf); - if (n < 0) { - dprintf("res_query failed (%d)\n", n); - return (NULL); - } - if (!(hp = gethostanswer(&buf, n, qbuf, T_PTR))) - return (NULL); /* h_errno was set by gethostanswer() */ -#ifdef SUNSECURITY - if (af == AF_INET) { - /* - * turn off search as the name should be absolute, - * 'localhost' should be matched by defnames - */ - strncpy(hname2, hp->h_name, MAXDNAME); - hname2[MAXDNAME] = '\0'; - old_options = _res.options; - _res.options &= ~RES_DNSRCH; - _res.options |= RES_DEFNAMES; - if (!(rhp = gethostbyname(hname2))) { - syslog(LOG_NOTICE|LOG_AUTH, - "gethostbyaddr: No A record for %s (verifying [%s])", - hname2, inet_ntoa(*((struct in_addr *)addr))); - _res.options = old_options; - h_errno = HOST_NOT_FOUND; - return (NULL); - } - _res.options = old_options; - for (haddr = rhp->h_addr_list; *haddr; haddr++) - if (!memcmp(*haddr, addr, INADDRSZ)) - break; - if (!*haddr) { - syslog(LOG_NOTICE|LOG_AUTH, - "gethostbyaddr: A record of %s != PTR record [%s]", - hname2, inet_ntoa(*((struct in_addr *)addr))); - h_errno = HOST_NOT_FOUND; - return (NULL); - } - } -#endif /*SUNSECURITY*/ - hp->h_addrtype = af; - hp->h_length = len; - bcopy(addr, host_addr, len); - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - if (af == AF_INET && (_res.options & RES_USE_INET6)) { - _map_v4v6_address((char*)host_addr, (char*)host_addr); - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - } - h_errno = NETDB_SUCCESS; - return (hp); -} - -#ifdef RESOLVSORT -static void -addrsort(ap, num) - char **ap; - int num; -{ - int i, j; - char **p; - short aval[MAXADDRS]; - int needsort = 0; - - p = ap; - for (i = 0; i < num; i++, p++) { - for (j = 0 ; (unsigned)j < _res.nsort; j++) - if (_res.sort_list[j].addr.s_addr == - (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask)) - break; - aval[i] = j; - if (needsort == 0 && i > 0 && j < aval[i-1]) - needsort = i; - } - if (!needsort) - return; - - while (needsort < num) { - for (j = needsort - 1; j >= 0; j--) { - if (aval[j] > aval[j+1]) { - char *hp; - - i = aval[j]; - aval[j] = aval[j+1]; - aval[j+1] = i; - - hp = ap[j]; - ap[j] = ap[j+1]; - ap[j+1] = hp; - - } else - break; - } - needsort++; - } -} -#endif -void -_sethostdnsent(stayopen) - int stayopen; -{ - if ((_res.options & RES_INIT) == 0 && res_init() == -1) - return; - if (stayopen) - _res.options |= RES_STAYOPEN | RES_USEVC; -} - -void -_endhostdnsent() -{ - _res.options &= ~(RES_STAYOPEN | RES_USEVC); - res_close(); -} diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c deleted file mode 100644 index cf12f57..0000000 --- a/lib/libc/net/gethostbyht.c +++ /dev/null @@ -1,202 +0,0 @@ -/*- - * Copyright (c) 1985, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$Id: gethostbyht.c,v 1.9 1997/02/22 15:00:07 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <stdio.h> -#include <ctype.h> -#include <errno.h> -#include <string.h> -#include <arpa/nameser.h> /* XXX */ -#include <resolv.h> /* XXX */ - -#define MAXALIASES 35 - -static struct hostent host; -static char *host_aliases[MAXALIASES]; -static char hostbuf[BUFSIZ+1]; -static FILE *hostf = NULL; -static u_char host_addr[16]; /* IPv4 or IPv6 */ -static char *h_addr_ptrs[2]; -static int stayopen = 0; - -void -_sethosthtent(f) - int f; -{ - if (!hostf) - hostf = fopen(_PATH_HOSTS, "r" ); - else - rewind(hostf); - stayopen = f; -} - -void -_endhosthtent() -{ - if (hostf && !stayopen) { - (void) fclose(hostf); - hostf = NULL; - } -} - -struct hostent * -gethostent() -{ - char *p; - register char *cp, **q; - int af, len; - - if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - again: - if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - if (*p == '#') - goto again; - if (!(cp = strpbrk(p, "#\n"))) - goto again; - *cp = '\0'; - if (!(cp = strpbrk(p, " \t"))) - goto again; - *cp++ = '\0'; - if (inet_pton(AF_INET6, p, host_addr) > 0) { - af = AF_INET6; - len = IN6ADDRSZ; - } else if (inet_pton(AF_INET, p, host_addr) > 0) { - if (_res.options & RES_USE_INET6) { - _map_v4v6_address((char*)host_addr, (char*)host_addr); - af = AF_INET6; - len = IN6ADDRSZ; - } else { - af = AF_INET; - len = INADDRSZ; - } - } else { - goto again; - } - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - host.h_length = len; - host.h_addrtype = af; - while (*cp == ' ' || *cp == '\t') - cp++; - host.h_name = cp; - q = host.h_aliases = host_aliases; - if ((cp = strpbrk(cp, " \t")) != NULL) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - if ((cp = strpbrk(cp, " \t")) != NULL) - *cp++ = '\0'; - } - *q = NULL; - h_errno = NETDB_SUCCESS; - return (&host); -} - -struct hostent * -_gethostbyhtname(name, af) - const char *name; - int af; -{ - register struct hostent *p; - register char **cp; - - sethostent(0); - while ((p = gethostent()) != NULL) { - if (p->h_addrtype != af) - continue; - if (strcasecmp(p->h_name, name) == 0) - break; - for (cp = p->h_aliases; *cp != 0; cp++) - if (strcasecmp(*cp, name) == 0) - goto found; - } -found: - endhostent(); - return (p); -} - -struct hostent * -_gethostbyhtaddr(addr, len, af) - const char *addr; - int len, af; -{ - register struct hostent *p; - - sethostent(0); - while ((p = gethostent()) != NULL) - if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len)) - break; - endhostent(); - return (p); -} diff --git a/lib/libc/net/gethostbyname.3 b/lib/libc/net/gethostbyname.3 deleted file mode 100644 index e520e33..0000000 --- a/lib/libc/net/gethostbyname.3 +++ /dev/null @@ -1,305 +0,0 @@ -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 -.\" $Id$ -.\" -.Dd May 25, 1995 -.Dt GETHOSTBYNAME 3 -.Os BSD 4.2 -.Sh NAME -.Nm gethostbyname , -.Nm gethostbyname2 , -.Nm gethostbyaddr , -.Nm gethostent , -.Nm sethostent , -.Nm endhostent , -.Nm herror , -.Nm hstrerror -.Nd get network host entry -.Sh SYNOPSIS -.Fd #include <netdb.h> -.Fd extern int h_errno; -.Ft struct hostent * -.Fn gethostbyname "const char *name" -.Ft struct hostent * -.Fn gethostbyname2 "const char *name" "int af" -.Ft struct hostent * -.Fn gethostbyaddr "const char *addr" "int len" "int type" -.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" -.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 name or by address, respectively. -This structure contains either the information obtained from the name server, -.Xr named 8 , -or broken-out fields from a line in -.Pa /etc/hosts . -If the local name server is not running these routines do a lookup in -.Pa /etc/hosts . -.Bd -literal -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 addresses from name server */ -}; -#define h_addr h_addr_list[0] /* address, for backward compatibility */ -.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 NULL-terminated array of alternate names for the host. -.It Fa h_addrtype -The type of address being returned; usually -.Dv AF_INET . -.It Fa h_length -The length, in bytes, of the address. -.It Fa h_addr_list -A NULL-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 -When using the nameserver, -.Fn gethostbyname -and -.Fn gethostbyname -will search for the named host in the current domain and its parents -unless the name ends in a dot. -If the name contains no dot, and if the environment variable -.Dq Ev HOSTALIASES -contains the name of an alias file, the alias file will first be searched -for an alias matching the input name. -See -.Xr hostname 7 -for the domain search procedure and the alias file format. -.Pp -The -.Fn gethostbyname2 -function is an evolution of -.Fn gethostbyname -which is intended to allow lookups in address families other than -.Dv AF_INET , -for example -.Dv AF_INET6 . -Currently the -.Fa af -argument must be specified as -.Dv AF_INET -else the fuction will return -.Dv NULL -after having set -.Va h_errno -to -.Dv NETDB_INTERNAL -.Pp -The -.Fn sethostent -function -may be used to request the use of a connected -.Tn TCP -socket for queries. -If the -.Fa stayopen -flag is non-zero, -this sets the option to send all queries to the name server using -.Tn TCP -and to retain the connection after each call to -.Fn gethostbyname , -.Fn gethostbyname2 -or -.Fn gethostbyaddr . -Otherwise, queries are performed using -.Tn UDP -datagrams. -.Pp -The -.Fn endhostent -function -closes the -.Tn TCP -connection. -.Pp -The -.Fn herror -function writes a message to the diagnostic output consisting of the -string parameter -.Fa s , -the constant string ": ", and a message corresponding to the value of -.Va h_errno . -.Pp -The -.Fn hstrerror -function returns a string which is the message text corresponding to the -value of the -.Fa err -parameter. -.Sh FILES -.Bl -tag -width /etc/resolv.conf -compact -.It Pa /etc/hosts -.It Pa /etc/host.conf -.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 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. -The routine -.Fn herror -can be used to print an error message describing the failure. -If its argument -.Fa string -is -.Pf non Dv -NULL , -it is printed, followed by a colon and a space. -The error message is printed with a trailing newline. -.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. -.El -.Sh SEE ALSO -.Xr resolver 3 , -.Xr hosts 5 , -.Xr hostname 7 , -.Xr named 8 -.Sh CAVEAT -The -.Fn gethostent -function -is defined, and -.Fn sethostent -and -.Fn endhostent -are redefined, -when -.Xr libc 3 -is built to use only the routines to lookup in -.Pa /etc/hosts -and not the name server. -.Pp -The -.Fn gethostent -function -reads the next line of -.Pa /etc/hosts , -opening the file if necessary. -.Pp -The -.Fn sethostent -function -opens and/or rewinds the file -.Pa /etc/hosts . -If the -.Fa stayopen -argument is non-zero, -the file will not be closed after each call to -.Fn gethostbyname , -.Fn gethostbyname2 -or -.Fn gethostbyaddr . -.Pp -The -.Fn endhostent -function -closes the file. -.Sh HISTORY -The -.Fn herror -function appeared in -.Bx 4.3 . -The -.Fn endhostent , -.Fn gethostbyaddr , -.Fn gethostbyname , -.Fn gethostent , -and -.Fn sethostent -functions appeared in -.Bx 4.2 . -The -.Fn gethostbyname2 -function first appeared in bind-4.9.4. -.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. -Only the Internet -address format is currently understood. diff --git a/lib/libc/net/gethostbynis.c b/lib/libc/net/gethostbynis.c deleted file mode 100644 index 45dbe5a..0000000 --- a/lib/libc/net/gethostbynis.c +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * Copyright (c) 1994, Garrett Wollman - * - * 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 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)$Id$"; -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include <errno.h> -#include <string.h> -#ifdef YP -#include <rpc/rpc.h> -#include <rpcsvc/yp_prot.h> -#include <rpcsvc/ypclnt.h> -#endif - -#define MAXALIASES 35 -#define MAXADDRS 35 - -#ifdef YP -static char *host_aliases[MAXALIASES]; -static char hostaddr[MAXADDRS]; -static char *host_addrs[2]; -#endif /* YP */ - -static struct hostent * -_gethostbynis(name, map, af) - const char *name; - char *map; - int af; -{ -#ifdef YP - register char *cp, **q; - char *result; - int resultlen; - static struct hostent h; - static char *domain = (char *)NULL; - static char ypbuf[YPMAXRECORD + 2]; - - switch(af) { - case AF_INET: - break; - default: - case AF_INET6: - errno = EAFNOSUPPORT; - return NULL; - } - - if (domain == (char *)NULL) - if (yp_get_default_domain (&domain)) - return ((struct hostent *)NULL); - - if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) - return ((struct hostent *)NULL); - - /* avoid potential memory leak */ - bcopy((char *)result, (char *)&ypbuf, resultlen); - ypbuf[resultlen] = '\0'; - free(result); - result = (char *)&ypbuf; - - if ((cp = index(result, '\n'))) - *cp = '\0'; - - cp = strpbrk(result, " \t"); - *cp++ = '\0'; - h.h_addr_list = host_addrs; - h.h_addr = hostaddr; - *((u_long *)h.h_addr) = inet_addr(result); - h.h_length = sizeof(u_long); - h.h_addrtype = AF_INET; - while (*cp == ' ' || *cp == '\t') - cp++; - h.h_name = cp; - q = h.h_aliases = host_aliases; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (&h); -#else - return (NULL); -#endif /* YP */ -} - -struct hostent * -_gethostbynisname(name, af) - const char *name; - int af; -{ - return _gethostbynis(name, "hosts.byname", af); -} - -struct hostent * -_gethostbynisaddr(addr, len, af) - const char *addr; - int len; - int af; -{ - return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af); -} diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c deleted file mode 100644 index 9415a53..0000000 --- a/lib/libc/net/gethostnamadr.c +++ /dev/null @@ -1,224 +0,0 @@ -/*- - * Copyright (c) 1994, Garrett Wollman - * - * 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 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)$Id: gethostnamadr.c,v 1.12 1997/02/22 15:00:09 peter Exp $"; -static char rcsid[] = "$Id: gethostnamadr.c,v 1.12 1997/02/22 15:00:09 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <stdio.h> -#include <ctype.h> -#include <errno.h> -#include <string.h> -#include <arpa/nameser.h> /* XXX hack for _res */ -#include <resolv.h> /* XXX hack for _res */ - -#define _PATH_HOSTCONF "/etc/host.conf" - -enum service_type { - SERVICE_NONE = 0, - SERVICE_BIND, - SERVICE_HOSTS, - SERVICE_NIS }; -#define SERVICE_MAX SERVICE_NIS - -static struct { - const char *name; - enum service_type type; -} service_names[] = { - { "hosts", SERVICE_HOSTS }, - { "/etc/hosts", SERVICE_HOSTS }, - { "hosttable", SERVICE_HOSTS }, - { "htable", SERVICE_HOSTS }, - { "bind", SERVICE_BIND }, - { "dns", SERVICE_BIND }, - { "domain", SERVICE_BIND }, - { "yp", SERVICE_NIS }, - { "yellowpages", SERVICE_NIS }, - { "nis", SERVICE_NIS }, - { 0, SERVICE_NONE } -}; - -static enum service_type service_order[SERVICE_MAX + 1]; -static int service_done = 0; - -static enum service_type -get_service_name(const char *name) { - int i; - for(i = 0; service_names[i].type != SERVICE_NONE; i++) { - if(!strcasecmp(name, service_names[i].name)) { - return service_names[i].type; - } - } - return SERVICE_NONE; -} - -static void -init_services() -{ - char *cp, *p, buf[BUFSIZ]; - register int cc = 0; - FILE *fd; - - if ((fd = (FILE *)fopen(_PATH_HOSTCONF, "r")) == NULL) { - /* make some assumptions */ - service_order[0] = SERVICE_BIND; - service_order[1] = SERVICE_HOSTS; - service_order[2] = SERVICE_NONE; - } else { - while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) { - if(buf[0] == '#') - continue; - - p = buf; - while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0') - ; - if (cp == NULL) - continue; - do { - if (isalpha(cp[0])) { - service_order[cc] = get_service_name(cp); - if(service_order[cc] != SERVICE_NONE) - cc++; - } - while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0') - ; - } while(cp != NULL && cc < SERVICE_MAX); - } - service_order[cc] = SERVICE_NONE; - fclose(fd); - } - service_done = 1; -} - -struct hostent * -gethostbyname(const char *name) -{ - struct hostent *hp; - - if (_res.options & RES_USE_INET6) { /* XXX */ - hp = gethostbyname2(name, AF_INET6); /* XXX */ - if (hp) /* XXX */ - return (hp); /* XXX */ - } /* XXX */ - return (gethostbyname2(name, AF_INET)); -} - -struct hostent * -gethostbyname2(const char *name, int type) -{ - struct hostent *hp = 0; - int nserv = 0; - - if (!service_done) - init_services(); - - while (!hp) { - switch (service_order[nserv]) { - case SERVICE_NONE: - return NULL; - case SERVICE_HOSTS: - hp = _gethostbyhtname(name, type); - break; - case SERVICE_BIND: - hp = _gethostbydnsname(name, type); - break; - case SERVICE_NIS: - hp = _gethostbynisname(name, type); - break; - } - nserv++; - } - return hp; -} - -struct hostent * -gethostbyaddr(const char *addr, int len, int type) -{ - struct hostent *hp = 0; - int nserv = 0; - - if (!service_done) - init_services(); - - while (!hp) { - switch (service_order[nserv]) { - case SERVICE_NONE: - return 0; - case SERVICE_HOSTS: - hp = _gethostbyhtaddr(addr, len, type); - break; - case SERVICE_BIND: - hp = _gethostbydnsaddr(addr, len, type); - break; - case SERVICE_NIS: - hp = _gethostbynisaddr(addr, len, type); - break; - } - nserv++; - } - return hp; -} - -#ifdef _THREAD_SAFE -struct hostent_data; - -/* - * Temporary function (not thread safe) - */ -int gethostbyaddr_r(const char *addr, int len, int type, - struct hostent *result, struct hostent_data *buffer) -{ - struct hostent *hp; - int ret; - if ((hp = gethostbyaddr(addr, len, type)) == NULL) { - ret = -1; - } else { - memcpy(result, hp, sizeof(struct hostent)); - ret = 0; - } - return(ret); -} -#endif - -void -sethostent(stayopen) - int stayopen; -{ - _sethosthtent(stayopen); - _sethostdnsent(stayopen); -} - -void -endhostent() -{ - _endhosthtent(); - _endhostdnsent(); -} diff --git a/lib/libc/net/getnetbydns.c b/lib/libc/net/getnetbydns.c deleted file mode 100644 index bacdb67..0000000 --- a/lib/libc/net/getnetbydns.c +++ /dev/null @@ -1,313 +0,0 @@ -/*- - * Copyright (c) 1985, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ -/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$Id: getnetbydns.c,v 1.11 1997/06/27 08:22:01 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> - -#include <stdio.h> -#include <netdb.h> -#include <resolv.h> -#include <ctype.h> -#include <errno.h> -#include <string.h> -#include <unistd.h> -#include <syslog.h> - -#include "res_config.h" - -extern int h_errno; - -#define BYADDR 0 -#define BYNAME 1 -#define MAXALIASES 35 - -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - long al; - char ac; -} align; - -static struct netent * -getnetanswer(answer, anslen, net_i) - querybuf *answer; - int anslen; - int net_i; -{ - - register HEADER *hp; - register u_char *cp; - register int n; - u_char *eom; - int type, class, buflen, ancount, qdcount, haveanswer, i, nchar; - char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN]; - char *in, *st, *pauxt, *bp, **ap; - char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0; -static struct netent net_entry; -static char *net_aliases[MAXALIASES], netbuf[PACKETSZ]; - - /* - * find first satisfactory answer - * - * answer --> +------------+ ( MESSAGE ) - * | Header | - * +------------+ - * | Question | the question for the name server - * +------------+ - * | Answer | RRs answering the question - * +------------+ - * | Authority | RRs pointing toward an authority - * | Additional | RRs holding additional information - * +------------+ - */ - eom = answer->buf + anslen; - hp = &answer->hdr; - ancount = ntohs(hp->ancount); /* #/records in the answer section */ - qdcount = ntohs(hp->qdcount); /* #/entries in the question section */ - bp = netbuf; - buflen = sizeof(netbuf); - cp = answer->buf + HFIXEDSZ; - if (!qdcount) { - if (hp->aa) - h_errno = HOST_NOT_FOUND; - else - h_errno = TRY_AGAIN; - return (NULL); - } - while (qdcount-- > 0) - cp += __dn_skipname(cp, eom) + QFIXEDSZ; - ap = net_aliases; - *ap = NULL; - net_entry.n_aliases = net_aliases; - haveanswer = 0; - while (--ancount >= 0 && cp < eom) { - n = dn_expand(answer->buf, eom, cp, bp, buflen); - if ((n < 0) || !res_dnok(bp)) - break; - cp += n; - ans[0] = '\0'; - (void)strncpy(&ans[0], bp, sizeof(ans) - 1); - ans[sizeof(ans) - 1] = '\0'; - GETSHORT(type, cp); - GETSHORT(class, cp); - cp += INT32SZ; /* TTL */ - GETSHORT(n, cp); - if (class == C_IN && type == T_PTR) { - n = dn_expand(answer->buf, eom, cp, bp, buflen); - if ((n < 0) || !res_hnok(bp)) { - cp += n; - return (NULL); - } - cp += n; - *ap++ = bp; - bp += strlen(bp) + 1; - net_entry.n_addrtype = - (class == C_IN) ? AF_INET : AF_UNSPEC; - haveanswer++; - } - } - if (haveanswer) { - *ap = NULL; - switch (net_i) { - case BYADDR: - net_entry.n_name = *net_entry.n_aliases; - net_entry.n_net = 0L; - break; - case BYNAME: - in = *net_entry.n_aliases; - net_entry.n_name = &ans[0]; - aux2[0] = '\0'; - for (i = 0; i < 4; i++) { - for (st = in, nchar = 0; - *st != '.'; - st++, nchar++) - ; - if (nchar != 1 || *in != '0' || flag) { - flag = 1; - (void)strncpy(paux1, - (i==0) ? in : in-1, - (i==0) ?nchar : nchar+1); - paux1[(i==0) ? nchar : nchar+1] = '\0'; - pauxt = paux2; - paux2 = strcat(paux1, paux2); - paux1 = pauxt; - } - in = ++st; - } - net_entry.n_net = inet_network(paux2); - break; - } - net_entry.n_aliases++; - return (&net_entry); - } - h_errno = TRY_AGAIN; - return (NULL); -} - -struct netent * -_getnetbydnsaddr(net, net_type) - register unsigned long net; - register int net_type; -{ - unsigned int netbr[4]; - int nn, anslen; - querybuf buf; - char qbuf[MAXDNAME]; - unsigned long net2; - struct netent *net_entry; - - if (net_type != AF_INET) - return (NULL); - - for (nn = 4, net2 = net; net2; net2 >>= 8) - netbr[--nn] = net2 & 0xff; - switch (nn) { - case 3: /* Class A */ - sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]); - break; - case 2: /* Class B */ - sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]); - break; - case 1: /* Class C */ - sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2], - netbr[1]); - break; - case 0: /* Class D - E */ - sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2], - netbr[1], netbr[0]); - break; - } - anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); - if (anslen < 0) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf("res_query failed\n"); -#endif - return (NULL); - } - net_entry = getnetanswer(&buf, anslen, BYADDR); - if (net_entry) { - unsigned u_net = net; /* maybe net should be unsigned ? */ - - /* Strip trailing zeros */ - while ((u_net & 0xff) == 0 && u_net != 0) - u_net >>= 8; - net_entry->n_net = u_net; - return (net_entry); - } - return (NULL); -} - -struct netent * -_getnetbydnsname(net) - register const char *net; -{ - int anslen; - querybuf buf; - char qbuf[MAXDNAME]; - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - strncpy(qbuf, net, sizeof(qbuf) - 1); - qbuf[sizeof(qbuf) - 1] = '\0'; - anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); - if (anslen < 0) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf("res_query failed\n"); -#endif - return (NULL); - } - return getnetanswer(&buf, anslen, BYNAME); -} - -void -_setnetdnsent(stayopen) - int stayopen; -{ - if (stayopen) - _res.options |= RES_STAYOPEN | RES_USEVC; -} - -void -_endnetdnsent() -{ - _res.options &= ~(RES_STAYOPEN | RES_USEVC); - res_close(); -} diff --git a/lib/libc/net/getnetbyht.c b/lib/libc/net/getnetbyht.c deleted file mode 100644 index f7b7b10..0000000 --- a/lib/libc/net/getnetbyht.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * 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. - * - * from getnetent.c 1.1 (Coimbra) 93/06/02 - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; -static char orig_rcsid[] = "From: Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp"; -static chat rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> -#include <netdb.h> -#include <stdio.h> -#include <string.h> - -#define MAXALIASES 35 - -static FILE *netf; -static char line[BUFSIZ+1]; -static struct netent net; -static char *net_aliases[MAXALIASES]; -static int _net_stayopen; - -void -_setnethtent(f) - int f; -{ - - if (netf == NULL) - netf = fopen(_PATH_NETWORKS, "r" ); - else - rewind(netf); - _net_stayopen |= f; -} - -void -_endnethtent() -{ - - if (netf) { - fclose(netf); - netf = NULL; - } - _net_stayopen = 0; -} - -struct netent * -getnetent() -{ - char *p; - register char *cp, **q; - - if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) - return (NULL); -again: - p = fgets(line, sizeof line, netf); - if (p == NULL) - return (NULL); - if (*p == '#') - goto again; - cp = strpbrk(p, "#\n"); - if (cp == NULL) - goto again; - *cp = '\0'; - net.n_name = p; - cp = strpbrk(p, " \t"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - net.n_net = inet_network(cp); - net.n_addrtype = AF_INET; - q = net.n_aliases = net_aliases; - if (p != NULL) - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &net_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (&net); -} - -struct netent * -_getnetbyhtname(name) - register const char *name; -{ - register struct netent *p; - register char **cp; - - setnetent(_net_stayopen); - while ( (p = getnetent()) ) { - if (strcasecmp(p->n_name, name) == 0) - break; - for (cp = p->n_aliases; *cp != 0; cp++) - if (strcasecmp(*cp, name) == 0) - goto found; - } -found: - if (!_net_stayopen) - endnetent(); - return (p); -} - -struct netent * -_getnetbyhtaddr(net, type) - register unsigned long net; - register int type; -{ - register struct netent *p; - - setnetent(_net_stayopen); - while ( (p = getnetent()) ) - if (p->n_addrtype == type && p->n_net == net) - break; - if (!_net_stayopen) - endnetent(); - return (p); -} diff --git a/lib/libc/net/getnetbynis.c b/lib/libc/net/getnetbynis.c deleted file mode 100644 index 0549016..0000000 --- a/lib/libc/net/getnetbynis.c +++ /dev/null @@ -1,177 +0,0 @@ -/*- - * Copyright (c) 1994, Garrett Wollman - * - * 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 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)$Id$"; -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include <errno.h> -#include <string.h> -#include <arpa/nameser.h> -#ifdef YP -#include <rpc/rpc.h> -#include <rpcsvc/yp_prot.h> -#include <rpcsvc/ypclnt.h> -#endif - -#define MAXALIASES 35 -#define MAXADDRS 35 - -#ifdef YP -static char *host_aliases[MAXALIASES]; -#endif /* YP */ - -static struct netent * -_getnetbynis(name, map, af) - const char *name; - char *map; - int af; -{ -#ifdef YP - register char *cp, **q; - static char *result; - int resultlen; - static struct netent h; - static char *domain = (char *)NULL; - static char ypbuf[YPMAXRECORD + 2]; - - switch(af) { - case AF_INET: - break; - default: - case AF_INET6: - errno = EAFNOSUPPORT; - return NULL; - } - - if (domain == (char *)NULL) - if (yp_get_default_domain (&domain)) - return (NULL); - - if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) - return (NULL); - - bcopy((char *)result, (char *)&ypbuf, resultlen); - ypbuf[resultlen] = '\0'; - free(result); - result = (char *)&ypbuf; - - if ((cp = index(result, '\n'))) - *cp = '\0'; - - cp = strpbrk(result, " \t"); - *cp++ = '\0'; - h.n_name = result; - - while (*cp == ' ' || *cp == '\t') - cp++; - - h.n_net = inet_network(cp); - h.n_addrtype = AF_INET; - - q = h.n_aliases = host_aliases; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (&h); -#else - return (NULL); -#endif -} - -struct netent * -_getnetbynisname(name) - const char *name; -{ - return _getnetbynis(name, "networks.byname", AF_INET); -} - -struct netent * -_getnetbynisaddr(addr, af) - unsigned long addr; - int af; -{ - char *str, *cp; - unsigned long net2; - int nn; - unsigned int netbr[4]; - char buf[MAXDNAME]; - - if (af != AF_INET) { - errno = EAFNOSUPPORT; - return (NULL); - } - - for (nn = 4, net2 = addr; net2; net2 >>= 8) { - netbr[--nn] = net2 & 0xff; - } - - switch (nn) { - case 3: /* Class A */ - sprintf(buf, "%u", netbr[3]); - break; - case 2: /* Class B */ - sprintf(buf, "%u.%u", netbr[2], netbr[3]); - break; - case 1: /* Class C */ - sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]); - break; - case 0: /* Class D - E */ - sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1], - netbr[2], netbr[3]); - break; - } - - str = (char *)&buf; - cp = str + (strlen(str) - 2); - - while(!strcmp(cp, ".0")) { - *cp = '\0'; - cp = str + (strlen(str) - 2); - } - - return _getnetbynis(str, "networks.byaddr", af); -} diff --git a/lib/libc/net/getnetent.3 b/lib/libc/net/getnetent.3 deleted file mode 100644 index 8fb13c0..0000000 --- a/lib/libc/net/getnetent.3 +++ /dev/null @@ -1,158 +0,0 @@ -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt GETNETENT 3 -.Os BSD 4.2 -.Sh NAME -.Nm getnetent , -.Nm getnetbyaddr , -.Nm getnetbyname , -.Nm setnetent , -.Nm endnetent -.Nd get network entry -.Sh SYNOPSIS -.Fd #include <netdb.h> -.Ft struct netent * -.Fn getnetent void -.Ft struct netent * -.Fn getnetbyname "const char *name" -.Ft struct netent * -.Fn getnetbyaddr "unsigned long net" "int type" -.Ft void -.Fn setnetent "int stayopen" -.Ft void -.Fn endnetent void -.Sh DESCRIPTION -The -.Fn getnetent , -.Fn getnetbyname , -and -.Fn getnetbyaddr -functions -each return a pointer to an object with the -following structure -containing the broken-out -fields of a line in the network data base, -.Pa /etc/networks . -.Bd -literal -offset indent -struct netent { - char *n_name; /* official name of net */ - char **n_aliases; /* alias list */ - int n_addrtype; /* net number type */ - unsigned long 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 zero terminated list of alternate names for the network. -.It Fa n_addrtype -The type of the network number returned; currently only AF_INET. -.It Fa n_net -The network number. Network numbers are returned in machine byte -order. -.El -.Pp -The -.Fn getnetent -function -reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setnetent -function -opens and rewinds the file. If the -.Fa stayopen -flag is non-zero, -the net data base will not be closed after each call to -.Fn getnetbyname -or -.Fn getnetbyaddr . -.Pp -The -.Fn endnetent -function -closes the file. -.Pp -The -.Fn getnetbyname -function -and -.Fn getnetbyaddr -sequentially search from the beginning -of the file until a matching -net name or -net address and type is found, -or until -.Dv EOF -is encountered. The -.Fa type -must be -.Dv AF_INET . -Network numbers are supplied in host order. -.Sh FILES -.Bl -tag -width /etc/networks -compact -.It Pa /etc/networks -.El -.Sh DIAGNOSTICS -Null pointer -(0) returned on -.Dv EOF -or error. -.Sh SEE ALSO -.Xr networks 5 -.Pp -.%T RFC 1101 -.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 probably -naive. diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c deleted file mode 100644 index c964cff..0000000 --- a/lib/libc/net/getnetnamadr.c +++ /dev/null @@ -1,190 +0,0 @@ -/*- - * Copyright (c) 1994, Garrett Wollman - * - * 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 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id: getnetnamadr.c,v 1.9 1997/02/22 15:00:12 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <stdio.h> -#include <ctype.h> -#include <errno.h> -#include <string.h> - -#ifndef _PATH_NETCONF -#define _PATH_NETCONF "/etc/host.conf" -#endif - -enum service_type { - SERVICE_NONE = 0, - SERVICE_BIND, - SERVICE_TABLE, - SERVICE_NIS }; -#define SERVICE_MAX SERVICE_NIS - -static struct { - const char *name; - enum service_type type; -} service_names[] = { - { "hosts", SERVICE_TABLE }, - { "/etc/hosts", SERVICE_TABLE }, - { "hosttable", SERVICE_TABLE }, - { "htable", SERVICE_TABLE }, - { "bind", SERVICE_BIND }, - { "dns", SERVICE_BIND }, - { "domain", SERVICE_BIND }, - { "yp", SERVICE_NIS }, - { "yellowpages", SERVICE_NIS }, - { "nis", SERVICE_NIS }, - { 0, SERVICE_NONE } -}; - -static enum service_type service_order[SERVICE_MAX + 1]; -static int service_done = 0; - -static enum service_type -get_service_name(const char *name) { - int i; - for(i = 0; service_names[i].type != SERVICE_NONE; i++) { - if(!strcasecmp(name, service_names[i].name)) { - return service_names[i].type; - } - } - return SERVICE_NONE; -} - -static void -init_services() -{ - char *cp, *p, buf[BUFSIZ]; - register int cc = 0; - FILE *fd; - - if ((fd = (FILE *)fopen(_PATH_NETCONF, "r")) == NULL) { - /* make some assumptions */ - service_order[0] = SERVICE_TABLE; - service_order[1] = SERVICE_NONE; - } else { - while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) { - if(buf[0] == '#') - continue; - - p = buf; - while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0') - ; - if (cp == NULL) - continue; - do { - if (isalpha(cp[0])) { - service_order[cc] = get_service_name(cp); - if(service_order[cc] != SERVICE_NONE) - cc++; - } - while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0') - ; - } while(cp != NULL && cc < SERVICE_MAX); - } - service_order[cc] = SERVICE_NONE; - fclose(fd); - } - service_done = 1; -} - -struct netent * -getnetbyname(const char *name) -{ - struct netent *hp = 0; - int nserv = 0; - - if (!service_done) - init_services(); - - while (!hp) { - switch (service_order[nserv]) { - case SERVICE_NONE: - return NULL; - case SERVICE_TABLE: - hp = _getnetbyhtname(name); - break; - case SERVICE_BIND: - hp = _getnetbydnsname(name); - break; - case SERVICE_NIS: - hp = _getnetbynisname(name); - break; - } - nserv++; - } - return hp; -} - -struct netent * -getnetbyaddr(addr, af) - u_long addr; - int af; -{ - struct netent *hp = 0; - int nserv = 0; - - if (!service_done) - init_services(); - - while (!hp) { - switch (service_order[nserv]) { - case SERVICE_NONE: - return 0; - case SERVICE_TABLE: - hp = _getnetbyhtaddr(addr, af); - break; - case SERVICE_BIND: - hp = _getnetbydnsaddr(addr, af); - break; - case SERVICE_NIS: - hp = _getnetbynisaddr(addr, af); - break; - } - nserv++; - } - return hp; -} - -void -setnetent(stayopen) - int stayopen; -{ - _setnethtent(stayopen); - _setnetdnsent(stayopen); -} - -void -endnetent() -{ - _endnethtent(); - _endnetdnsent(); -} diff --git a/lib/libc/net/getproto.c b/lib/libc/net/getproto.c deleted file mode 100644 index 46f46d3..0000000 --- a/lib/libc/net/getproto.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getproto.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <netdb.h> - -extern int _proto_stayopen; - -struct protoent * -getprotobynumber(proto) - register int proto; -{ - register struct protoent *p; - - setprotoent(_proto_stayopen); - while ( (p = getprotoent()) ) - if (p->p_proto == proto) - break; - if (!_proto_stayopen) - endprotoent(); - return (p); -} diff --git a/lib/libc/net/getprotoent.3 b/lib/libc/net/getprotoent.3 deleted file mode 100644 index dbf3d1a..0000000 --- a/lib/libc/net/getprotoent.3 +++ /dev/null @@ -1,146 +0,0 @@ -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt GETPROTOENT 3 -.Os BSD 4.2 -.Sh NAME -.Nm getprotoent , -.Nm getprotobynumber , -.Nm getprotobyname , -.Nm setprotoent , -.Nm endprotoent -.Nd get protocol entry -.Sh SYNOPSIS -.Fd #include <netdb.h> -.Ft struct protoent * -.Fn getprotoent void -.Ft struct protoent * -.Fn getprotobyname "const char *name" -.Ft struct protoent * -.Fn getprotobynumber "int proto" -.Ft void -.Fn setprotoent "int stayopen" -.Ft void -.Fn endprotoent void -.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 data base, -.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 zero 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 net data base 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 -function -and -.Fn getprotobynumber -sequentially search from the beginning -of the file until a matching -protocol name or -protocol number is found, -or until -.Dv EOF -is encountered. -.Sh RETURN VALUES -Null pointer -(0) returned on -.Dv EOF -or error. -.Sh FILES -.Bl -tag -width /etc/protocols -compact -.It Pa /etc/protocols -.El -.Sh SEE ALSO -.Xr protocols 5 -.Sh HISTORY -The -.Fn getprotoent , -.Fn getprotobynumber , -.Fn getprotobyname , -.Fn setprotoent , -and -.Fn endprotoent -functions appeared in -.Bx 4.2 . -.Sh BUGS -These 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/lib/libc/net/getprotoent.c b/lib/libc/net/getprotoent.c deleted file mode 100644 index c10ae33..0000000 --- a/lib/libc/net/getprotoent.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <netdb.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#define MAXALIASES 35 - -static FILE *protof = NULL; -static char line[BUFSIZ+1]; -static struct protoent proto; -static char *proto_aliases[MAXALIASES]; -int _proto_stayopen; - -void -setprotoent(f) - int f; -{ - if (protof == NULL) - protof = fopen(_PATH_PROTOCOLS, "r" ); - else - rewind(protof); - _proto_stayopen |= f; -} - -void -endprotoent() -{ - if (protof) { - fclose(protof); - protof = NULL; - } - _proto_stayopen = 0; -} - -struct protoent * -getprotoent() -{ - char *p; - register char *cp, **q; - - if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) - return (NULL); -again: - if ((p = fgets(line, BUFSIZ, protof)) == NULL) - return (NULL); - if (*p == '#') - goto again; - cp = strpbrk(p, "#\n"); - if (cp == NULL) - goto again; - *cp = '\0'; - proto.p_name = p; - cp = strpbrk(p, " \t"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - proto.p_proto = atoi(cp); - q = proto.p_aliases = proto_aliases; - if (p != NULL) { - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &proto_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - } - *q = NULL; - return (&proto); -} diff --git a/lib/libc/net/getprotoname.c b/lib/libc/net/getprotoname.c deleted file mode 100644 index 0832acf..0000000 --- a/lib/libc/net/getprotoname.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getprotoname.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <netdb.h> -#include <string.h> - -extern int _proto_stayopen; - -struct protoent * -getprotobyname(name) - register const char *name; -{ - register struct protoent *p; - register char **cp; - - setprotoent(_proto_stayopen); - while ( (p = getprotoent()) ) { - if (strcmp(p->p_name, name) == 0) - break; - for (cp = p->p_aliases; *cp != 0; cp++) - if (strcmp(*cp, name) == 0) - goto found; - } -found: - if (!_proto_stayopen) - endprotoent(); - return (p); -} diff --git a/lib/libc/net/getservbyname.c b/lib/libc/net/getservbyname.c deleted file mode 100644 index 124f5ac..0000000 --- a/lib/libc/net/getservbyname.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <netdb.h> -#include <string.h> - -extern int _serv_stayopen; - -struct servent * -getservbyname(name, proto) - const char *name, *proto; -{ - register struct servent *p; - register char **cp; - -#ifdef YP - extern char *___getservbyname_yp; - extern char *___getservbyproto_yp; - - ___getservbyname_yp = (char *)name; - ___getservbyproto_yp = (char *)proto; -#endif - - setservent(_serv_stayopen); - while ( (p = getservent()) ) { - if (strcmp(name, p->s_name) == 0) - goto gotname; - for (cp = p->s_aliases; *cp; cp++) - if (strcmp(name, *cp) == 0) - goto gotname; - continue; -gotname: - if (proto == 0 || strcmp(p->s_proto, proto) == 0) - break; - } - if (!_serv_stayopen) - endservent(); - -#ifdef YP - ___getservbyname_yp = NULL; - ___getservbyproto_yp = NULL; -#endif - - return (p); -} diff --git a/lib/libc/net/getservbyport.c b/lib/libc/net/getservbyport.c deleted file mode 100644 index ef9a2e8..0000000 --- a/lib/libc/net/getservbyport.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getservbyport.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <netdb.h> -#include <string.h> - -extern int _serv_stayopen; - -struct servent * -getservbyport(port, proto) - int port; - const char *proto; -{ - register struct servent *p; - -#ifdef YP - extern int ___getservbyport_yp; - extern char *___getservbyproto_yp; - - ___getservbyport_yp = port; - ___getservbyproto_yp = (char *)proto; -#endif - - setservent(_serv_stayopen); - while ( (p = getservent()) ) { - if (p->s_port != port) - continue; - if (proto == 0 || strcmp(p->s_proto, proto) == 0) - break; - } - if (!_serv_stayopen) - endservent(); - -#ifdef YP - ___getservbyport_yp = 0; - ___getservbyproto_yp = NULL; -#endif - - return (p); -} diff --git a/lib/libc/net/getservent.3 b/lib/libc/net/getservent.3 deleted file mode 100644 index 79c18a3..0000000 --- a/lib/libc/net/getservent.3 +++ /dev/null @@ -1,156 +0,0 @@ -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" From: @(#)getservent.3 8.3 (Berkeley) 1/12/94 -.\" $Id$ -.\" -.Dd July 9, 1995 -.Dt GETSERVENT 3 -.Os BSD 4.2 -.Sh NAME -.Nm getservent , -.Nm getservbyport , -.Nm getservbyname , -.Nm setservent , -.Nm endservent -.Nd get service entry -.Sh SYNOPSIS -.Fd #include <netdb.h> -.Ft struct servent * -.Fn getservent -.Ft struct servent * -.Fn getservbyname "const char *name" "const char *proto" -.Ft struct servent * -.Fn getservbyport "int port" "const char *proto" -.Ft void -.Fn setservent "int stayopen" -.Ft void -.Fn endservent void -.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 data base, -.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 zero 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 net data base 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 is found, -or until -.Dv EOF -is encountered. -If a protocol name is also supplied (non- -.Dv NULL ) , -searches must also match the protocol. -.ne 1i -.Sh FILES -.Bl -tag -width /etc/services -compact -.It Pa /etc/services -.El -.Sh DIAGNOSTICS -Null pointer -(0) returned on -.Dv EOF -or error. -.Sh SEE ALSO -.Xr getprotoent 3 , -.Xr services 5 -.Sh HISTORY -The -.Fn getservent , -.Fn getservbyport , -.Fn getservbyname , -.Fn setservent , -and -.Fn endservent -functions appeared in -.Bx 4.2 . -.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. -Expecting port numbers to fit in a 32 bit -quantity is probably naive. diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c deleted file mode 100644 index cd4449f..0000000 --- a/lib/libc/net/getservent.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <netdb.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#ifdef YP -#include <rpc/rpc.h> -#include <rpcsvc/yp_prot.h> -#include <rpcsvc/ypclnt.h> -static int serv_stepping_yp = 0; -extern int _yp_check __P(( char ** )); -#endif - - -#define MAXALIASES 35 - -static FILE *servf = NULL; -static char line[BUFSIZ+1]; -static struct servent serv; -static char *serv_aliases[MAXALIASES]; -int _serv_stayopen; - -#ifdef YP -char *___getservbyname_yp = NULL; -char *___getservbyproto_yp = NULL; -int ___getservbyport_yp = 0; -static char *yp_domain = NULL; - -static int -_getservbyport_yp(line) - char *line; -{ - char *result; - int resultlen; - char buf[YPMAXRECORD + 2]; - int rv; - - snprintf(buf, sizeof(buf), "%d/%s", ntohs(___getservbyport_yp), - ___getservbyproto_yp); - - ___getservbyport_yp = 0; - ___getservbyproto_yp = NULL; - - if(!yp_domain) { - if(yp_get_default_domain(&yp_domain)) - return (0); - } - - /* - * We have to be a little flexible here. Ideally you're supposed - * to have both a services.byname and a services.byport map, but - * some systems have only services.byname. FreeBSD cheats a little - * by putting the services.byport information in the same map as - * services.byname so that either case will work. We allow for both - * possibilities here: if there is no services.byport map, we try - * services.byname instead. - */ - if ((rv = yp_match(yp_domain, "services.byport", buf, strlen(buf), - &result, &resultlen))) { - if (rv == YPERR_MAP) { - if (yp_match(yp_domain, "services.byname", buf, - strlen(buf), &result, &resultlen)) - return(0); - } else - return(0); - } - - /* getservent() expects lines terminated with \n -- make it happy */ - snprintf(line, BUFSIZ, "%.*s\n", resultlen, result); - - free(result); - return(1); -} - -static int -_getservbyname_yp(line) - char *line; -{ - char *result; - int resultlen; - char buf[YPMAXRECORD + 2]; - - if(!yp_domain) { - if(yp_get_default_domain(&yp_domain)) - return (0); - } - - snprintf(buf, sizeof(buf), "%s/%s", ___getservbyname_yp, - ___getservbyproto_yp); - - ___getservbyname_yp = 0; - ___getservbyproto_yp = NULL; - - if (yp_match(yp_domain, "services.byname", buf, strlen(buf), - &result, &resultlen)) { - return(0); - } - - /* getservent() expects lines terminated with \n -- make it happy */ - snprintf(line, BUFSIZ, "%.*s\n", resultlen, result); - - free(result); - return(1); -} - -static int -_getservent_yp(line) - char *line; -{ - static char *key = NULL; - static int keylen; - char *lastkey, *result; - int resultlen; - int rv; - - if(!yp_domain) { - if(yp_get_default_domain(&yp_domain)) - return (0); - } - - if (!serv_stepping_yp) { - if (key) - free(key); - if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen, - &result, &resultlen))) { - serv_stepping_yp = 0; - return(0); - } - serv_stepping_yp = 1; - } else { - lastkey = key; - rv = yp_next(yp_domain, "services.byname", key, keylen, &key, - &keylen, &result, &resultlen); - free(lastkey); - if (rv) { - serv_stepping_yp = 0; - return (0); - } - } - - /* getservent() expects lines terminated with \n -- make it happy */ - snprintf(line, BUFSIZ, "%.*s\n", resultlen, result); - - free(result); - - return(1); -} -#endif - -void -setservent(f) - int f; -{ - if (servf == NULL) - servf = fopen(_PATH_SERVICES, "r" ); - else - rewind(servf); - _serv_stayopen |= f; -} - -void -endservent() -{ - if (servf) { - fclose(servf); - servf = NULL; - } - _serv_stayopen = 0; -} - -struct servent * -getservent() -{ - char *p; - register char *cp, **q; - -#ifdef YP - if (serv_stepping_yp && _getservent_yp(line)) { - p = (char *)&line; - goto unpack; - } -tryagain: -#endif - if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) - return (NULL); -again: - if ((p = fgets(line, BUFSIZ, servf)) == NULL) - return (NULL); -#ifdef YP - if (*p == '+' && _yp_check(NULL)) { - if (___getservbyname_yp != NULL) { - if (!_getservbyname_yp(line)) - goto tryagain; - } - else if (___getservbyport_yp != 0) { - if (!_getservbyport_yp(line)) - goto tryagain; - } - else if (!_getservent_yp(line)) - goto tryagain; - } -unpack: -#endif - if (*p == '#') - goto again; - cp = strpbrk(p, "#\n"); - if (cp == NULL) - goto again; - *cp = '\0'; - serv.s_name = p; - p = strpbrk(p, " \t"); - if (p == NULL) - goto again; - *p++ = '\0'; - while (*p == ' ' || *p == '\t') - p++; - cp = strpbrk(p, ",/"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - serv.s_port = htons((u_short)atoi(p)); - serv.s_proto = cp; - q = serv.s_aliases = serv_aliases; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &serv_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (&serv); -} diff --git a/lib/libc/net/herror.c b/lib/libc/net/herror.c deleted file mode 100644 index f22f519..0000000 --- a/lib/libc/net/herror.c +++ /dev/null @@ -1,112 +0,0 @@ -/*- - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/uio.h> -#include <netdb.h> -#include <unistd.h> -#include <string.h> - -const char *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 */ -}; -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(s) - const char *s; -{ - struct iovec iov[4]; - register 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(err) - int err; -{ - if (err < 0) - return ("Resolver internal error"); - else if (err < h_nerr) - return (h_errlist[err]); - return ("Unknown resolver error"); -} diff --git a/lib/libc/net/inet.3 b/lib/libc/net/inet.3 deleted file mode 100644 index 6ad1bc6..0000000 --- a/lib/libc/net/inet.3 +++ /dev/null @@ -1,210 +0,0 @@ -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93 -.\" $Id: inet.3,v 1.5 1997/02/22 15:00:15 peter Exp $ -.\" -.Dd June 17, 1996 -.Dt INET 3 -.Os BSD 4.2 -.Sh NAME -.Nm inet_aton , -.Nm inet_addr , -.Nm inet_network , -.Nm inet_ntoa , -.Nm inet_makeaddr , -.Nm inet_lnaof , -.Nm inet_netof -.Nd Internet address manipulation routines -.Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/socket.h> -.Fd #include <netinet/in.h> -.Fd #include <arpa/inet.h> -.Ft int -.Fn inet_aton "const char *cp" "struct in_addr *pin" -.Ft unsigned long -.Fn inet_addr "const char *cp" -.Ft unsigned long -.Fn inet_network "const char *cp" -.Ft char * -.Fn inet_ntoa "struct in_addr in" -.Ft struct in_addr -.Fn inet_makeaddr "unsigned long net" "unsigned long lna" -.Ft unsigned long -.Fn inet_lnaof "struct in_addr in" -.Ft unsigned long -.Fn inet_netof "struct in_addr in" -.Sh DESCRIPTION -The routines -.Fn inet_aton , -.Fn inet_addr -and -.Fn inet_network -interpret character strings representing -numbers expressed in the Internet standard -.Ql \&. -notation. -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 is invalid. -The -.Fn inet_addr -and -.Fn inet_network -functions return numbers suitable for use -as Internet addresses and Internet network -numbers, respectively. -The routine -.Fn inet_ntoa -takes an Internet address and returns an -.Tn ASCII -string representing the address in -.Ql \&. -notation. The routine -.Fn inet_makeaddr -takes an Internet network number and a local -network address and constructs an Internet address -from it. 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 INTERNET ADDRESSES -Values specified using the -.Ql \&. -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 the -.Tn VAX -the bytes referred to -above appear as -.Dq Li d.c.b.a . -That is, -.Tn VAX -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 right-most 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 right most 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 -.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). -.Pp -The -.Fn inet_aton -and -.Fn inet_ntoa -functions are semi-deprecated in favor of the -.Xr addr2ascii 3 -family. However, since those functions are not yet widely implemented, -portable programs cannot rely on their presence and will continue -to use the -.Xr inet 3 -functions for some time. -.Sh DIAGNOSTICS -The constant -.Dv INADDR_NONE -is returned by -.Fn inet_addr -and -.Fn inet_network -for malformed requests. -.Sh SEE ALSO -.Xr addr2ascii 3 , -.Xr gethostbyname 3 , -.Xr getnetent 3 , -.Xr hosts 5 , -.Xr networks 5 -.Sh HISTORY -These -functions appeared in -.Bx 4.2 . -.Sh BUGS -The value -.Dv INADDR_NONE -(0xffffffff) is a valid broadcast address, but -.Fn inet_addr -cannot return that value without indicating failure. -The newer -.Fn inet_aton -function does not share this problem. -The problem of host byte ordering versus network byte ordering is -confusing. -The string returned by -.Fn inet_ntoa -resides in a static memory area. -.Pp -Inet_addr should return a -.Fa struct in_addr . diff --git a/lib/libc/net/inet_addr.c b/lib/libc/net/inet_addr.c deleted file mode 100644 index a1ac899..0000000 --- a/lib/libc/net/inet_addr.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * ++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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <ctype.h> - -/* - * Ascii internet address interpretation routine. - * The value returned is in network order. - */ -u_long -inet_addr(cp) - register 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(cp, addr) - register const char *cp; - struct in_addr *addr; -{ - register u_long val; - register int base, n; - register char c; - u_int parts[4]; - register 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(c)) - return (0); - val = 0; base = 10; - if (c == '0') { - c = *++cp; - if (c == 'x' || c == 'X') - base = 16, c = *++cp; - else - base = 8; - } - for (;;) { - if (isascii(c) && isdigit(c)) { - val = (val * base) + (c - '0'); - c = *++cp; - } else if (base == 16 && isascii(c) && isxdigit(c)) { - val = (val << 4) | - (c + 10 - (islower(c) ? 'a' : 'A')); - c = *++cp; - } else - break; - } - if (c == '.') { - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16 bits) - * a.b (with b treated as 24 bits) - */ - if (pp >= parts + 3) - return (0); - *pp++ = val; - c = *++cp; - } else - break; - } - /* - * Check for trailing characters. - */ - if (c != '\0' && (!isascii(c) || !isspace(c))) - return (0); - /* - * Concoct the address according to - * the number of parts specified. - */ - n = pp - parts + 1; - switch (n) { - - case 0: - return (0); /* initial nondigit */ - - case 1: /* a -- 32 bits */ - break; - - case 2: /* a.b -- 8.24 bits */ - if (val > 0xffffff) - return (0); - val |= parts[0] << 24; - break; - - case 3: /* a.b.c -- 8.8.16 bits */ - if (val > 0xffff) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16); - break; - - case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if (val > 0xff) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); - break; - } - if (addr) - addr->s_addr = htonl(val); - return (1); -} diff --git a/lib/libc/net/inet_lnaof.c b/lib/libc/net/inet_lnaof.c deleted file mode 100644 index 406be30..0000000 --- a/lib/libc/net/inet_lnaof.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -/* - * Return the local network address portion of an - * internet address; handles class a/b/c network - * number formats. - */ -u_long -inet_lnaof(in) - struct in_addr in; -{ - register u_long 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/lib/libc/net/inet_makeaddr.c b/lib/libc/net/inet_makeaddr.c deleted file mode 100644 index 7976188..0000000 --- a/lib/libc/net/inet_makeaddr.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -/* - * Formulate an Internet address from network + host. Used in - * building addresses stored in the ifnet structure. - */ -struct in_addr -inet_makeaddr(net, host) - u_long net, host; -{ - u_long 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/lib/libc/net/inet_net_ntop.c b/lib/libc/net/inet_net_ntop.c deleted file mode 100644 index 4c7893d..0000000 --- a/lib/libc/net/inet_net_ntop.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static const char orig_rcsid[] = "From Id: inet_net_ntop.c,v 8.2 1996/08/08 06:54:44 vixie Exp"; -static const char rcsid[] = "$Id$"; -#endif - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) -#endif - -static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits, - char *dst, size_t size)); - -/* - * 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(af, src, bits, dst, size) - 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)); - 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(src, bits, dst, size) - const u_char *src; - int bits; - char *dst; - size_t size; -{ - char *odst = dst; - char *t; - u_int m; - int b; - - if (bits < 0 || bits > 32) { - errno = EINVAL; - return (NULL); - } - if (bits == 0) { - if (size < sizeof "0") - goto emsgsize; - *dst++ = '0'; - *dst = '\0'; - } - - /* Format whole octets. */ - for (b = bits / 8; b > 0; b--) { - if (size < sizeof "255.") - goto emsgsize; - t = dst; - dst += SPRINTF((dst, "%u", *src++)); - if (b > 1) { - *dst++ = '.'; - *dst = '\0'; - } - size -= (size_t)(dst - t); - } - - /* Format partial octet. */ - b = bits % 8; - if (b > 0) { - if (size < sizeof ".255") - goto emsgsize; - t = dst; - if (dst != odst) - *dst++ = '.'; - m = ((1 << b) - 1) << (8 - b); - dst += SPRINTF((dst, "%u", *src & m)); - size -= (size_t)(dst - t); - } - - /* Format CIDR /width. */ - if (size < sizeof "/32") - goto emsgsize; - dst += SPRINTF((dst, "/%u", bits)); - return (odst); - - emsgsize: - errno = EMSGSIZE; - return (NULL); -} diff --git a/lib/libc/net/inet_net_pton.c b/lib/libc/net/inet_net_pton.c deleted file mode 100644 index 6fd6a06..0000000 --- a/lib/libc/net/inet_net_pton.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static const char orig_rcsid[] = "From Id: inet_net_pton.c,v 8.3 1996/11/11 06:36:52 vixie Exp"; -static const char rcsid[] = "$Id$"; -#endif - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#include <assert.h> -#include <ctype.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) -#endif - -static int inet_net_pton_ipv4 __P((const char *src, u_char *dst, - size_t size)); - -/* - * 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(af, src, dst, size) - int af; - const char *src; - void *dst; - size_t size; -{ - switch (af) { - case AF_INET: - return (inet_net_pton_ipv4(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(src, dst, size) - 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 = *src++; - if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii(src[1]) && isxdigit(src[1])) { - /* Hexadecimal: Eat nybble string. */ - if (size <= 0) - goto emsgsize; - *dst = 0, dirty = 0; - src++; /* skip x or X. */ - while ((ch = *src++) != '\0' && - isascii(ch) && isxdigit(ch)) { - if (isupper(ch)) - ch = tolower(ch); - n = strchr(xdigits, ch) - xdigits; - assert(n >= 0 && n <= 15); - *dst |= n; - if (!dirty++) - *dst <<= 4; - else if (size-- > 0) - *++dst = 0, dirty = 0; - else - goto emsgsize; - } - if (dirty) - size--; - } 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 = *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 = *src++; - if (!isascii(ch) || !isdigit(ch)) - goto enoent; - } - } else - goto enoent; - - bits = -1; - if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { - /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ - bits = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - bits *= 10; - bits += n; - } while ((ch = *src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (ch != '\0') - goto enoent; - if (bits > 32) - goto emsgsize; - } - - /* Firey 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 >= 8 && 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); -} diff --git a/lib/libc/net/inet_neta.c b/lib/libc/net/inet_neta.c deleted file mode 100644 index 15a1c70..0000000 --- a/lib/libc/net/inet_neta.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static const char orig_rcsid[] = "From Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp"; -static const char rcsid[] = "$Id$"; -#endif - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#include <errno.h> -#include <stdio.h> - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) -#endif - -/* - * char * - * inet_neta(src, dst, size) - * format a u_long 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(src, dst, size) - u_long src; - char *dst; - size_t size; -{ - char *odst = dst; - char *tp; - - while (src & 0xffffffff) { - u_char b = (src & 0xff000000) >> 24; - - src <<= 8; - if (b) { - if (size < sizeof "255.") - goto emsgsize; - tp = dst; - dst += SPRINTF((dst, "%u", b)); - if (src != 0L) { - *dst++ = '.'; - *dst = '\0'; - } - size -= (size_t)(dst - tp); - } - } - if (dst == odst) { - if (size < sizeof "0.0.0.0") - goto emsgsize; - strcpy(dst, "0.0.0.0"); - } - return (odst); - - emsgsize: - errno = EMSGSIZE; - return (NULL); -} diff --git a/lib/libc/net/inet_netof.c b/lib/libc/net/inet_netof.c deleted file mode 100644 index d6de694..0000000 --- a/lib/libc/net/inet_netof.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -/* - * Return the network number from an internet - * address; handles class a/b/c network #'s. - */ -u_long -inet_netof(in) - struct in_addr in; -{ - register u_long 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/lib/libc/net/inet_network.c b/lib/libc/net/inet_network.c deleted file mode 100644 index 6da2e8b..0000000 --- a/lib/libc/net/inet_network.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <ctype.h> - -/* - * Internet network address interpretation routine. - * The library routines call this routine to interpret - * network numbers. - */ -u_long -inet_network(cp) - register const char *cp; -{ - register u_long val, base, n; - register char c; - u_long parts[4], *pp = parts; - register 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(*cp)) - return (INADDR_NONE); - *pp++ = val; - n = pp - parts; - for (val = 0, i = 0; i < n; i++) { - val <<= 8; - val |= parts[i] & 0xff; - } - return (val); -} diff --git a/lib/libc/net/inet_ntoa.c b/lib/libc/net/inet_ntoa.c deleted file mode 100644 index a37b1db..0000000 --- a/lib/libc/net/inet_ntoa.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -/* - * Convert network-format internet address - * to base 256 d.d.d.d representation. - */ -#include <sys/types.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <stdio.h> - -char * -inet_ntoa(in) - struct in_addr in; -{ - static char b[18]; - register char *p; - - p = (char *)∈ -#define UC(b) (((int)b)&0xff) - (void)snprintf(b, sizeof(b), - "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); - return (b); -} diff --git a/lib/libc/net/inet_ntop.c b/lib/libc/net/inet_ntop.c deleted file mode 100644 index 36dcb32..0000000 --- a/lib/libc/net/inet_ntop.c +++ /dev/null @@ -1,190 +0,0 @@ -/* 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> -#include <string.h> -#include <errno.h> -#include <stdio.h> - -#define SPRINTF(x) ((size_t)sprintf x) - -/* - * 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 __P((const u_char *src, char *dst, size_t size)); -static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); - -/* 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(af, src, dst, size) - int af; - const void *src; - char *dst; - size_t size; -{ - switch (af) { - case AF_INET: - return (inet_ntop4(src, dst, size)); - case AF_INET6: - return (inet_ntop6(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (NULL); - } - /* NOTREACHED */ -} - -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address, more or less like inet_ntoa() - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop4(src, dst, size) - const u_char *src; - char *dst; - size_t size; -{ - static const char fmt[] = "%u.%u.%u.%u"; - char tmp[sizeof "255.255.255.255"]; - - if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) { - errno = ENOSPC; - return (NULL); - } - strcpy(dst, tmp); - 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(src, dst, size) - 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"], *tp; - struct { int base, len; } best, cur; - u_int words[IN6ADDRSZ / INT16SZ]; - int i; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for (i = 0; i < IN6ADDRSZ; i++) - words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); - best.base = -1; - cur.base = -1; - for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) { - if (i == best.base) - *tp++ = ':'; - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) - *tp++ = ':'; - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) - return (NULL); - tp += strlen(tp); - break; - } - tp += SPRINTF((tp, "%x", words[i])); - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) - *tp++ = ':'; - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) { - errno = ENOSPC; - return (NULL); - } - strcpy(dst, tmp); - return (dst); -} diff --git a/lib/libc/net/inet_pton.c b/lib/libc/net/inet_pton.c deleted file mode 100644 index 054ff7d..0000000 --- a/lib/libc/net/inet_pton.c +++ /dev/null @@ -1,214 +0,0 @@ -/* 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> -#include <string.h> -#include <errno.h> - -/* - * 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 __P((const char *src, u_char *dst)); -static int inet_pton6 __P((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(af, src, dst) - int af; - const char *src; - void *dst; -{ - switch (af) { - case AF_INET: - return (inet_pton4(src, dst)); - case AF_INET6: - return (inet_pton6(src, dst)); - default: - errno = EAFNOSUPPORT; - return (-1); - } - /* NOTREACHED */ -} - -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(src, dst) - 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); - *tp = new; - if (! saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - - memcpy(dst, tmp, INADDRSZ); - return (1); -} - -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton6(src, dst) - 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; - 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 = 0; - val = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) - pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - continue; - } - if (ch == ':') { - curtok = src; - if (!saw_xdigit) { - if (colonp) - return (0); - colonp = tp; - continue; - } - if (tp + INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - saw_xdigit = 0; - val = 0; - continue; - } - if (ch == '.' && ((tp + INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { - tp += INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - return (0); - } - if (saw_xdigit) { - if (tp + INT16SZ > endp) - return (0); - *tp++ = (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; - - 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/lib/libc/net/iso_addr.3 b/lib/libc/net/iso_addr.3 deleted file mode 100644 index 0565373..0000000 --- a/lib/libc/net/iso_addr.3 +++ /dev/null @@ -1,110 +0,0 @@ -.\" Copyright (c) 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)iso_addr.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt ISO_ADDR 3 -.Os -.Sh NAME -.Nm iso_addr , -.Nm iso_ntoa -.Nd "elementary network address conversion routines for Open System Interconnection -.Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <netiso/iso.h> -.Ft struct iso_addr * -.Fn iso_addr "char *cp" -.Ft char * -.Fn iso_ntoa "struct iso_addr *isoa" -.Sh DESCRIPTION -The routine -.Fn iso_addr -interprets character strings representing -.Tn OSI -addresses, returning binary information suitable -for use in system calls. -The routine -.Fn iso_ntoa -takes -.Tn OSI -addresses and returns -.Tn ASCII -strings representing NSAPs (network service -access points) in a -notation inverse to that accepted by -.Fn iso_addr . -.Pp -Unfortunately, no universal standard exists for representing -.Tn OSI -network addresses. -.Pp -The format employed by -.Fn iso_addr -is a sequence of hexadecimal -.Dq digits -(optionally separated by periods), -of the form: -.Bd -filled -offset indent -<hex digits>.<hex digits>.<hex digits> -.Ed -.Pp -Each pair of hexadecimal digits represents a byte -with the leading digit indicating the higher-ordered bits. -A period following an even number of bytes has no -effect (but may be used to increase legibility). -A period following an odd number of bytes has the -effect of causing the byte of address being translated -to have its higher order bits filled with zeros. -.Sh RETURN VALUES -.Fn iso_ntoa -always returns a null terminated string. -.Fn iso_addr -always returns a pointer to a struct iso_addr. -(See -.Sx BUGS . ) -.Sh SEE ALSO -.Xr iso 4 -.Sh HISTORY -The -.Fn iso_addr -and -.Fn iso_ntoa -functions appeared in -.Bx 4.3 Reno . -.Sh BUGS -The returned values -reside in a static memory area. -.Pp -The function -.Fn iso_addr -should diagnose improperly formed input, and there should be an unambiguous -way to recognize this. diff --git a/lib/libc/net/iso_addr.c b/lib/libc/net/iso_addr.c deleted file mode 100644 index 8829497..0000000 --- a/lib/libc/net/iso_addr.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)iso_addr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <netiso/iso.h> -#include <string.h> - -/* States*/ -#define VIRGIN 0 -#define GOTONE 1 -#define GOTTWO 2 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) - -struct iso_addr * -iso_addr(addr) - register const char *addr; -{ - static struct iso_addr out_addr; - register char *cp = out_addr.isoa_genaddr; - char *cplim = cp + sizeof(out_addr.isoa_genaddr); - register int byte = 0, state = VIRGIN, new; - - bzero((char *)&out_addr, sizeof(out_addr)); - do { - if ((*addr >= '0') && (*addr <= '9')) { - new = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - new = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - new = *addr - 'A' + 10; - } else if (*addr == 0) - state |= END; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case GOTTWO | DIGIT: - *cp++ = byte; /*FALLTHROUGH*/ - case VIRGIN | DIGIT: - state = GOTONE; byte = new; continue; - case GOTONE | DIGIT: - state = GOTTWO; byte = new + (byte << 4); continue; - default: /* | DELIM */ - state = VIRGIN; *cp++ = byte; byte = 0; continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; /* FALLTHROUGH */ - case VIRGIN | END: - break; - } - break; - } while (cp < cplim); - out_addr.isoa_len = cp - out_addr.isoa_genaddr; - return (&out_addr); -} - -static char hexlist[] = "0123456789abcdef"; - -char * -iso_ntoa(isoa) - const struct iso_addr *isoa; -{ - static char tmpbuf[sizeof(isoa->isoa_genaddr)*3]; - const u_char *binary; - char *cp; - int i; - - binary = isoa->isoa_genaddr; - cp = tmpbuf; - - for (i = 0; i < isoa->isoa_len; i++) { - *cp++ = hexlist[*binary >> 4]; - *cp++ = hexlist[*binary++ & 0xf]; - - if ((((i % 2) == 0) && ((i + 1) < isoa->isoa_len))) - *cp++ = '.'; - } - *cp = '\0'; - return tmpbuf; -} diff --git a/lib/libc/net/linkaddr.3 b/lib/libc/net/linkaddr.3 deleted file mode 100644 index 6999add..0000000 --- a/lib/libc/net/linkaddr.3 +++ /dev/null @@ -1,138 +0,0 @@ -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" From: @(#)linkaddr.3 8.1 (Berkeley) 7/28/93 -.\" $Id$ -.\" -.Dd June 17, 1996 -.Dt LINK_ADDR 3 -.Os BSD 4.4 -.Sh NAME -.Nm link_addr , -.Nm link_ntoa -.Nd elementary address specification routines for link level access -.Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/socket.h> -.Fd #include <net/if_dl.h> -.Ft void -.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl" -.Ft char * -.Fn link_ntoa "const struct sockaddr_dl *sdl" -.Sh DESCRIPTION -The routine -.Fn link_addr -interprets character strings representing -link-level addresses, returning binary information suitable -for use in system calls. -The routine -.Fn link_ntoa -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. -.Pp -For -.Fn link_addr , -the string -.Fa addr -may contain -an optional network interface identifier of the form -.Dq "name unit-number" , -suitable for the first argument to -.Xr ifconfig 8 , -followed in all cases by a colon and -an interface address in the form of -groups of hexadecimal digits -separated by periods. -Each group represents a byte of address; -address bytes are filled left to right from -low order bytes through high order bytes. -.Pp -.\" A regular expression may make this format clearer: -.\" .Bd -literal -offset indent -.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)* -.\" .Ed -.\" .Pp -Thus -.Li le0:8.0.9.13.d.30 -represents an ethernet address -to be transmitted on the first Lance ethernet interface. -.Pp -The direct use of these functions is deprecated in favor of the -.Xr addr2ascii 3 -interface; however, portable programs cannot rely on the latter as it is -not yet widely implemented. -.Sh RETURN VALUES -.Fn link_ntoa -always returns a null terminated string. -.Fn link_addr -has no return value. -(See -.Sx BUGS . ) -.Sh SEE ALSO -.Xr addr2ascii 3 -.\" .Xr iso 4 -.Sh HISTORY -The -.Fn link_addr -and -.Fn link_ntoa -functions appeared in -.Bx 4.3 Reno . -.Sh BUGS -The returned values for link_ntoa -reside in a static memory area. -.Pp -The function -.Fn link_addr -should diagnose improperly formed input, and there should be an unambiguous -way to recognize this. -.Pp -If the -.Va 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. -If this translated address is given to -.Fn link_addr -without inserting an initial colon, -the latter will not interpret it correctly. diff --git a/lib/libc/net/linkaddr.c b/lib/libc/net/linkaddr.c deleted file mode 100644 index 68eed3d..0000000 --- a/lib/libc/net/linkaddr.c +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <net/if_dl.h> -#include <string.h> - -/* States*/ -#define NAMING 0 -#define GOTONE 1 -#define GOTTWO 2 -#define RESET 3 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) -#define LETTER (4*3) - -void -link_addr(addr, sdl) - register const char *addr; - register struct sockaddr_dl *sdl; -{ - register char *cp = sdl->sdl_data; - char *cplim = sdl->sdl_len + (char *)sdl; - register int byte = 0, state = NAMING, new; - - bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); - sdl->sdl_family = AF_LINK; - do { - state &= ~LETTER; - if ((*addr >= '0') && (*addr <= '9')) { - new = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - new = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - new = *addr - 'A' + 10; - } else if (*addr == 0) { - state |= END; - } else if (state == NAMING && - (((*addr >= 'A') && (*addr <= 'Z')) || - ((*addr >= 'a') && (*addr <= 'z')))) - state |= LETTER; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case NAMING | DIGIT: - case NAMING | LETTER: - *cp++ = addr[-1]; - continue; - case NAMING | DELIM: - state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; - continue; - case GOTTWO | DIGIT: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | DIGIT: - state = GOTONE; - byte = new; - continue; - case GOTONE | DIGIT: - state = GOTTWO; - byte = new + (byte << 4); - continue; - default: /* | DELIM */ - state = RESET; - *cp++ = byte; - byte = 0; - continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | END: - break; - } - break; - } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); - new = cp - (char *)sdl; - if (new > sizeof(*sdl)) - sdl->sdl_len = new; - return; -} - -static char hexlist[] = "0123456789abcdef"; - -char * -link_ntoa(sdl) - register const struct sockaddr_dl *sdl; -{ - static char obuf[64]; - register char *out = obuf; - register int i; - register u_char *in = (u_char *)LLADDR(sdl); - u_char *inlim = in + sdl->sdl_alen; - int firsttime = 1; - - if (sdl->sdl_nlen) { - bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen); - out += sdl->sdl_nlen; - if (sdl->sdl_alen) - *out++ = ':'; - } - while (in < inlim) { - if (firsttime) - firsttime = 0; - else - *out++ = '.'; - i = *in++; - if (i > 0xf) { - out[1] = hexlist[i & 0xf]; - i >>= 4; - out[0] = hexlist[i]; - out += 2; - } else - *out++ = hexlist[i]; - } - *out = 0; - return (obuf); -} diff --git a/lib/libc/net/map_v4v6.c b/lib/libc/net/map_v4v6.c deleted file mode 100644 index 0f8658e..0000000 --- a/lib/libc/net/map_v4v6.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * ++Copyright++ 1985, 1988, 1993 - * - - * Copyright (c) 1985, 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> - -#include <stdio.h> -#include <string.h> -#include <netdb.h> -#include <resolv.h> -#include <ctype.h> -#include <errno.h> -#include <syslog.h> - -typedef union { - int32_t al; - char ac; -} align; - -void -_map_v4v6_address(src, dst) - const char *src; - char *dst; -{ - u_char *p = (u_char *)dst; - char tmp[INADDRSZ]; - int i; - - /* Stash a temporary copy so our caller can update in place. */ - bcopy(src, tmp, INADDRSZ); - /* Mark this ipv6 addr as a mapped ipv4. */ - for (i = 0; i < 10; i++) - *p++ = 0x00; - *p++ = 0xff; - *p++ = 0xff; - /* Retrieve the saved copy and we're done. */ - bcopy(tmp, (void*)p, INADDRSZ); -} - -void -_map_v4v6_hostent(hp, bpp, lenp) - struct hostent *hp; - char **bpp; - int *lenp; -{ - char **ap; - - if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ) - return; - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - for (ap = hp->h_addr_list; *ap; ap++) { - int i = sizeof(align) - ((u_long)*bpp % sizeof(align)); - - if (*lenp < (i + IN6ADDRSZ)) { - /* Out of memory. Truncate address list here. XXX */ - *ap = NULL; - return; - } - *bpp += i; - *lenp -= i; - _map_v4v6_address(*ap, *bpp); - *ap = *bpp; - *bpp += IN6ADDRSZ; - *lenp -= IN6ADDRSZ; - } -} diff --git a/lib/libc/net/ns.3 b/lib/libc/net/ns.3 deleted file mode 100644 index e621ad2..0000000 --- a/lib/libc/net/ns.3 +++ /dev/null @@ -1,131 +0,0 @@ -.\" Copyright (c) 1986, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)ns.3 8.1 (Berkeley) 6/4/93 -.\" $Id$ -.\" -.Dd June 4, 1993 -.Dt NS 3 -.Os BSD 4.3 -.Sh NAME -.Nm ns_addr , -.Nm ns_ntoa -.Nd Xerox -.Tn NS Ns (tm) -address conversion routines -.Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <netns/ns.h> -.Ft struct ns_addr -.Fn ns_addr "char *cp" -.Ft char * -.Fn ns_ntoa "struct ns_addr ns" -.Sh DESCRIPTION -The routine -.Fn ns_addr -interprets character strings representing -.Tn XNS -addresses, returning binary information suitable -for use in system calls. -The routine -.Fn ns_ntoa -takes -.Tn XNS -addresses and returns -.Tn ASCII -strings representing the address in a -notation in common use in the Xerox Development Environment: -.Bd -filled -offset indent -<network number>.<host number>.<port number> -.Ed -.Pp -Trailing zero fields are suppressed, and each number is printed in hexadecimal, -in a format suitable for input to -.Fn ns_addr . -Any fields lacking super-decimal digits will have a -trailing -.Ql H -appended. -.Pp -Unfortunately, no universal standard exists for representing -.Tn XNS -addresses. -An effort has been made to insure that -.Fn ns_addr -be compatible with most formats in common use. -It will first separate an address into 1 to 3 fields using a single delimiter -chosen from -period -.Ql \&. , -colon -.Ql \&: -or pound-sign -.Ql \&# . -Each field is then examined for byte separators (colon or period). -If there are byte separators, each subfield separated is taken to be -a small hexadecimal number, and the entirety is taken as a network-byte-ordered -quantity to be zero extended in the high-network-order bytes. -Next, the field is inspected for hyphens, in which case -the field is assumed to be a number in decimal notation -with hyphens separating the millenia. -Next, the field is assumed to be a number: -It is interpreted -as hexadecimal if there is a leading -.Ql 0x -(as in C), -a trailing -.Ql H -(as in Mesa), or there are any super-decimal digits present. -It is interpreted as octal is there is a leading -.Ql 0 -and there are no super-octal digits. -Otherwise, it is converted as a decimal number. -.Sh RETURN VALUES -None. (See -.Sx BUGS . ) -.Sh SEE ALSO -.Xr hosts 5 , -.Xr networks 5 -.Sh HISTORY -The -.Fn ns_addr -and -.Fn ns_toa -functions appeared in -.Bx 4.3 . -.Sh BUGS -The string returned by -.Fn ns_ntoa -resides in a static memory area. -The function -.Fn ns_addr -should diagnose improperly formed input, and there should be an unambiguous -way to recognize this. diff --git a/lib/libc/net/ns_addr.c b/lib/libc/net/ns_addr.c deleted file mode 100644 index 3446e08..0000000 --- a/lib/libc/net/ns_addr.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * J.Q. Johnson. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ns_addr.c 8.1 (Berkeley) 6/7/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <netns/ns.h> -#include <stdio.h> -#include <string.h> - -static struct ns_addr addr, zero_addr; - -static void Field(), cvtbase(); - -struct ns_addr -ns_addr(name) - const char *name; -{ - char separator; - char *hostname, *socketname, *cp; - char buf[50]; - - (void)strncpy(buf, name, sizeof(buf) - 1); - buf[sizeof(buf) - 1] = '\0'; - - /* - * First, figure out what he intends as a field separtor. - * Despite the way this routine is written, the prefered - * form 2-272.AA001234H.01777, i.e. XDE standard. - * Great efforts are made to insure backward compatability. - */ - if ((hostname = strchr(buf, '#')) != NULL) - separator = '#'; - else { - hostname = strchr(buf, '.'); - if ((cp = strchr(buf, ':')) && - ((hostname && cp < hostname) || (hostname == 0))) { - hostname = cp; - separator = ':'; - } else - separator = '.'; - } - if (hostname) - *hostname++ = 0; - - addr = zero_addr; - Field(buf, addr.x_net.c_net, 4); - if (hostname == 0) - return (addr); /* No separator means net only */ - - socketname = strchr(hostname, separator); - if (socketname) { - *socketname++ = 0; - Field(socketname, (u_char *)&addr.x_port, 2); - } - - Field(hostname, addr.x_host.c_host, 6); - - return (addr); -} - -static void -Field(buf, out, len) - char *buf; - u_char *out; - int len; -{ - register char *bp = buf; - int i, ibase, base16 = 0, base10 = 0, clen = 0; - int hb[6], *hp; - char *fmt; - - /* - * first try 2-273#2-852-151-014#socket - */ - if ((*buf != '-') && - (1 < (i = sscanf(buf, "%d-%d-%d-%d-%d", - &hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) { - cvtbase(1000L, 256, hb, i, out, len); - return; - } - /* - * try form 8E1#0.0.AA.0.5E.E6#socket - */ - if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x", - &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { - cvtbase(256L, 256, hb, i, out, len); - return; - } - /* - * try form 8E1#0:0:AA:0:5E:E6#socket - */ - if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x", - &hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) { - cvtbase(256L, 256, hb, i, out, len); - return; - } - /* - * This is REALLY stretching it but there was a - * comma notation separting shorts -- definitely non standard - */ - if (1 < (i = sscanf(buf,"%x,%x,%x", - &hb[0], &hb[1], &hb[2]))) { - hb[0] = htons(hb[0]); hb[1] = htons(hb[1]); - hb[2] = htons(hb[2]); - cvtbase(65536L, 256, hb, i, out, len); - return; - } - - /* Need to decide if base 10, 16 or 8 */ - while (*bp) switch (*bp++) { - - case '0': case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '-': - break; - - case '8': case '9': - base10 = 1; - break; - - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - base16 = 1; - break; - - case 'x': case 'X': - *--bp = '0'; - base16 = 1; - break; - - case 'h': case 'H': - base16 = 1; - /* fall into */ - - default: - *--bp = 0; /* Ends Loop */ - } - if (base16) { - fmt = "%3x"; - ibase = 4096; - } else if (base10 == 0 && *buf == '0') { - fmt = "%3o"; - ibase = 512; - } else { - fmt = "%3d"; - ibase = 1000; - } - - for (bp = buf; *bp++; ) clen++; - if (clen == 0) clen++; - if (clen > 18) clen = 18; - i = ((clen - 1) / 3) + 1; - bp = clen + buf - 3; - hp = hb + i - 1; - - while (hp > hb) { - (void)sscanf(bp, fmt, hp); - bp[0] = 0; - hp--; - bp -= 3; - } - (void)sscanf(buf, fmt, hp); - cvtbase((long)ibase, 256, hb, i, out, len); -} - -static void -cvtbase(oldbase,newbase,input,inlen,result,reslen) - long oldbase; - int newbase; - int input[]; - int inlen; - unsigned char result[]; - int reslen; -{ - int d, e; - long sum; - - e = 1; - while (e > 0 && reslen > 0) { - d = 0; e = 0; sum = 0; - /* long division: input=input/newbase */ - while (d < inlen) { - sum = sum*oldbase + (long) input[d]; - e += (sum > 0); - input[d++] = sum / newbase; - sum %= newbase; - } - result[--reslen] = sum; /* accumulate remainder */ - } - for (d=0; d < reslen; d++) - result[d] = 0; -} diff --git a/lib/libc/net/ns_ntoa.c b/lib/libc/net/ns_ntoa.c deleted file mode 100644 index 0f01f0b..0000000 --- a/lib/libc/net/ns_ntoa.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ns_ntoa.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <netns/ns.h> -#include <stdio.h> - -char * -ns_ntoa(addr) - struct ns_addr addr; -{ - static char obuf[40]; - union { union ns_net net_e; u_long long_e; } net; - u_short port = htons(addr.x_port); - register char *cp; - char *cp2; - register u_char *up = addr.x_host.c_host; - u_char *uplim = up + 6; - static char *spectHex(); - - net.net_e = addr.x_net; - sprintf(obuf, "%lx", ntohl(net.long_e)); - cp = spectHex(obuf); - cp2 = cp + 1; - while (*up==0 && up < uplim) up++; - if (up == uplim) { - if (port) { - sprintf(cp, ".0"); - cp += 2; - } - } else { - sprintf(cp, ".%x", *up++); - while (up < uplim) { - while (*cp) cp++; - sprintf(cp, "%02x", *up++); - } - cp = spectHex(cp2); - } - if (port) { - sprintf(cp, ".%x", port); - spectHex(cp + 1); - } - return (obuf); -} - -static char * -spectHex(p0) - char *p0; -{ - int ok = 0; - int nonzero = 0; - register char *p = p0; - for (; *p; p++) switch (*p) { - - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - *p += ('A' - 'a'); - /* fall into . . . */ - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - ok = 1; - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - nonzero = 1; - } - if (nonzero && !ok) { *p++ = 'H'; *p = 0; } - return (p); -} diff --git a/lib/libc/net/nsap_addr.c b/lib/libc/net/nsap_addr.c deleted file mode 100644 index b0c6433..0000000 --- a/lib/libc/net/nsap_addr.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include <ctype.h> -#include <resolv.h> - -static char -xtob(c) - register int c; -{ - return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); -} - -u_int -inet_nsap_addr(ascii, binary, maxlen) - const char *ascii; - u_char *binary; - int maxlen; -{ - register u_char c, nib; - u_int len = 0; - - while ((c = *ascii++) != '\0' && len < maxlen) { - if (c == '.' || c == '+' || c == '/') - continue; - if (!isascii(c)) - return (0); - if (islower(c)) - c = toupper(c); - if (isxdigit(c)) { - nib = xtob(c); - if ((c = *ascii++) != '\0') { - c = toupper(c); - if (isxdigit(c)) { - *binary++ = (nib << 4) | xtob(c); - len++; - } else - return (0); - } - else - return (0); - } - else - return (0); - } - return (len); -} - -char * -inet_nsap_ntoa(binlen, binary, ascii) - int binlen; - register const u_char *binary; - register char *ascii; -{ - register int nib; - int i; - static char tmpbuf[255*3]; - char *start; - - if (ascii) - start = ascii; - else { - ascii = tmpbuf; - start = tmpbuf; - } - - if (binlen > 255) - binlen = 255; - - for (i = 0; i < binlen; i++) { - nib = *binary >> 4; - *ascii++ = nib + (nib < 10 ? '0' : '7'); - nib = *binary++ & 0x0f; - *ascii++ = nib + (nib < 10 ? '0' : '7'); - if (((i % 2) == 0 && (i + 1) < binlen)) - *ascii++ = '.'; - } - *ascii = '\0'; - return (start); -} diff --git a/lib/libc/net/rcmd.3 b/lib/libc/net/rcmd.3 deleted file mode 100644 index e25057f..0000000 --- a/lib/libc/net/rcmd.3 +++ /dev/null @@ -1,204 +0,0 @@ -.\" 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 -.\" $Id$ -.\" -.Dd February 15, 1996 -.Dt RCMD 3 -.Os BSD 4.2 -.Sh NAME -.Nm rcmd , -.Nm rresvport , -.Nm iruserok , -.Nm ruserok -.Nd routines for returning a stream to a remote command -.Sh SYNOPSIS -.Fd #include <unistd.h> -.Ft int -.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" -.Ft int -.Fn rresvport "int *port" -.Ft int -.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser" -.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 super-user to execute a command on -a remote machine using an authentication scheme based -on reserved port numbers. -The -.Fn rresvport -function -returns 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 . -All three functions are present in the same file and are used -by the -.Xr rshd 8 -server (among others). -.Pp -The -.Fn rcmd -function -looks up the host -.Fa *ahost -using -.Xr gethostbyname 3 , -returning \-1 if the host does not exist. -Otherwise -.Fa *ahost -is set to the standard name of the host -and a connection is established to a server -residing at the well-known Internet port -.Fa inport . -.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 -.Em stdin -and -.Em 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 0, then the -.Em stderr -(unit 2 of the remote -command) will be made the same as the -.Em stdout -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. -.Pp -The protocol is described in detail in -.Xr rshd 8 . -.Pp -The -.Fn rresvport -function is 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 1023. Only the super-user -is allowed to bind an address of this sort to a socket. -.Pp -The -.Fn iruserok -and -.Fn ruserok -functions take a remote host's IP address or name, as returned by the -.Xr gethostbyname 3 -routines, two user names and a flag indicating whether the local user's -name is that of the super-user. -Then, if the user is -.Em NOT -the super-user, 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 super-user, or is writable by anyone other -than the owner, the check automatically fails. -Zero is returned if the machine name is listed in the -.Dq Pa hosts.equiv -file, or the host and remote user name are found in the -.Dq Pa .rhosts -file; otherwise -.Fn iruserok -and -.Fn ruserok -return \-1. -If the local domain (as obtained from -.Xr gethostname 3 ) -is the same as the remote domain, only the machine name need be specified. -.Pp -The -.Fn iruserok -function is strongly preferred for security reasons. -It requires trusting the local DNS at most, while the -.Fn ruserok -function requires trusting the entire DNS, which can be spoofed. -.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 -function -returns 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 -.Dv EAGAIN -is overloaded to mean ``All network ports in use.'' -.Sh SEE ALSO -.Xr rlogin 1 , -.Xr rsh 1 , -.Xr intro 2 , -.Xr rexec 3 , -.Xr rexecd 8 , -.Xr rlogind 8 , -.Xr rshd 8 -.Sh HISTORY -These -functions appeared in -.Bx 4.2 . diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c deleted file mode 100644 index ff108d9..0000000 --- a/lib/libc/net/rcmd.c +++ /dev/null @@ -1,518 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/stat.h> - -#include <netinet/in.h> -#include <arpa/inet.h> - -#include <signal.h> -#include <fcntl.h> -#include <netdb.h> -#include <unistd.h> -#include <pwd.h> -#include <errno.h> -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#ifdef YP -#include <rpc/rpc.h> -#include <rpcsvc/yp_prot.h> -#include <rpcsvc/ypclnt.h> -#endif - -extern int innetgr __P(( const char *, const char *, const char *, const char * )); - -#define max(a, b) ((a > b) ? a : b) - -int __ivaliduser __P((FILE *, u_long, const char *, const char *)); -static int __icheckhost __P((u_long, char *)); - -int -rcmd(ahost, rport, locuser, remuser, cmd, fd2p) - char **ahost; - u_short rport; - const char *locuser, *remuser, *cmd; - int *fd2p; -{ - struct hostent *hp; - struct sockaddr_in sin, from; - fd_set reads; - long oldmask; - pid_t pid; - int s, lport, timo; - char c; - - pid = getpid(); - hp = gethostbyname(*ahost); - if (hp == NULL) { - herror(*ahost); - return (-1); - } - *ahost = hp->h_name; - oldmask = sigblock(sigmask(SIGURG)); - for (timo = 1, lport = IPPORT_RESERVED - 1;;) { - s = rresvport(&lport); - 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)); - sigsetmask(oldmask); - return (-1); - } - fcntl(s, F_SETOWN, pid); - bzero(&sin, sizeof sin); - sin.sin_len = sizeof(struct sockaddr_in); - sin.sin_family = hp->h_addrtype; - sin.sin_port = rport; - bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr)); - if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) - break; - (void)close(s); - if (errno == EADDRINUSE) { - lport--; - continue; - } - if (errno == ECONNREFUSED && timo <= 16) { - (void)sleep(timo); - timo *= 2; - continue; - } - if (hp->h_addr_list[1] != NULL) { - int oerrno = errno; - - (void)fprintf(stderr, "connect to address %s: ", - inet_ntoa(sin.sin_addr)); - errno = oerrno; - perror(0); - hp->h_addr_list++; - bcopy(hp->h_addr_list[0], &sin.sin_addr, MIN(hp->h_length, sizeof sin.sin_addr)); - (void)fprintf(stderr, "Trying %s...\n", - inet_ntoa(sin.sin_addr)); - continue; - } - (void)fprintf(stderr, "%s: %s\n", hp->h_name, strerror(errno)); - sigsetmask(oldmask); - return (-1); - } - lport--; - if (fd2p == 0) { - write(s, "", 1); - lport = 0; - } else { - char num[8]; - int s2 = rresvport(&lport), s3; - int len = sizeof(from); - int nfds; - - 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; - } - nfds = max(s, s2)+1; - if(nfds > FD_SETSIZE) { - fprintf(stderr, "rcmd: too many files\n"); - (void)close(s2); - goto bad; - } -again: - FD_ZERO(&reads); - FD_SET(s, &reads); - FD_SET(s2, &reads); - errno = 0; - if (select(nfds, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)){ - if (errno != 0) - (void)fprintf(stderr, - "rcmd: select (setting up stderr): %s\n", - strerror(errno)); - else - (void)fprintf(stderr, - "select: protocol failure in circuit setup\n"); - (void)close(s2); - goto bad; - } - s3 = accept(s2, (struct sockaddr *)&from, &len); - /* - * XXX careful for ftp bounce attacks. If discovered, shut them - * down and check for the real auxiliary channel to connect. - */ - if (from.sin_family == AF_INET && from.sin_port == htons(20)) { - close(s3); - goto again; - } - (void)close(s2); - if (s3 < 0) { - (void)fprintf(stderr, - "rcmd: accept: %s\n", strerror(errno)); - lport = 0; - goto bad; - } - *fd2p = s3; - from.sin_port = ntohs((u_short)from.sin_port); - if (from.sin_family != AF_INET || - from.sin_port >= IPPORT_RESERVED || - from.sin_port < IPPORT_RESERVED / 2) { - (void)fprintf(stderr, - "socket: protocol failure in circuit setup.\n"); - goto bad2; - } - } - (void)write(s, locuser, strlen(locuser)+1); - (void)write(s, remuser, strlen(remuser)+1); - (void)write(s, cmd, strlen(cmd)+1); - if (read(s, &c, 1) != 1) { - (void)fprintf(stderr, - "rcmd: %s: %s\n", *ahost, strerror(errno)); - goto bad2; - } - if (c != 0) { - while (read(s, &c, 1) == 1) { - (void)write(STDERR_FILENO, &c, 1); - if (c == '\n') - break; - } - goto bad2; - } - sigsetmask(oldmask); - return (s); -bad2: - if (lport) - (void)close(*fd2p); -bad: - (void)close(s); - sigsetmask(oldmask); - return (-1); -} - -int -rresvport(alport) - int *alport; -{ - struct sockaddr_in sin; - int s; - - bzero(&sin, sizeof sin); - sin.sin_len = sizeof(struct sockaddr_in); - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; - s = socket(AF_INET, SOCK_STREAM, 0); - if (s < 0) - return (-1); -#if 0 /* compat_exact_traditional_rresvport_semantics */ - sin.sin_port = htons((u_short)*alport); - if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) - return (s); - if (errno != EADDRINUSE) { - (void)close(s); - return (-1); - } -#endif - sin.sin_port = 0; - if (bindresvport(s, &sin) == -1) { - (void)close(s); - return (-1); - } - *alport = (int)ntohs(sin.sin_port); - return (s); -} - -int __check_rhosts_file = 1; -char *__rcmd_errstr; - -int -ruserok(rhost, superuser, ruser, luser) - const char *rhost, *ruser, *luser; - int superuser; -{ - struct hostent *hp; - u_long addr; - char **ap; - - if ((hp = gethostbyname(rhost)) == NULL) - return (-1); - for (ap = hp->h_addr_list; *ap; ++ap) { - bcopy(*ap, &addr, sizeof(addr)); - if (iruserok(addr, superuser, ruser, luser) == 0) - return (0); - } - return (-1); -} - -/* - * New .rhosts strategy: We are passed an ip address. We spin through - * hosts.equiv and .rhosts looking for a match. When the .rhosts only - * has ip addresses, we don't have to trust a nameserver. When it - * contains hostnames, we spin through the list of addresses the nameserver - * gives us and look for a match. - * - * Returns 0 if ok, -1 if not ok. - */ -int -iruserok(raddr, superuser, ruser, luser) - u_long raddr; - int superuser; - const char *ruser, *luser; -{ - register char *cp; - struct stat sbuf; - struct passwd *pwd; - FILE *hostf; - uid_t uid; - int first; - char pbuf[MAXPATHLEN]; - - first = 1; - hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r"); -again: - if (hostf) { - if (__ivaliduser(hostf, raddr, luser, ruser) == 0) { - (void)fclose(hostf); - return (0); - } - (void)fclose(hostf); - } - if (first == 1 && (__check_rhosts_file || superuser)) { - first = 0; - if ((pwd = getpwnam(luser)) == NULL) - return (-1); - (void)strcpy(pbuf, pwd->pw_dir); - (void)strcat(pbuf, "/.rhosts"); - - /* - * Change effective uid while opening .rhosts. If root and - * reading an NFS mounted file system, can't read files that - * are protected read/write owner only. - */ - uid = geteuid(); - (void)seteuid(pwd->pw_uid); - hostf = fopen(pbuf, "r"); - (void)seteuid(uid); - - if (hostf == NULL) - return (-1); - /* - * If not a regular file, or is owned by someone other than - * user or root or if writeable by anyone but the owner, quit. - */ - cp = NULL; - if (lstat(pbuf, &sbuf) < 0) - cp = ".rhosts lstat failed"; - else if (!S_ISREG(sbuf.st_mode)) - cp = ".rhosts not regular file"; - else if (fstat(fileno(hostf), &sbuf) < 0) - cp = ".rhosts fstat failed"; - else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) - cp = "bad .rhosts owner"; - else if (sbuf.st_mode & (S_IWGRP|S_IWOTH)) - cp = ".rhosts writeable by other than owner"; - /* If there were any problems, quit. */ - if (cp) { - __rcmd_errstr = cp; - (void)fclose(hostf); - return (-1); - } - goto again; - } - return (-1); -} - -/* - * XXX - * Don't make static, used by lpd(8). - * - * Returns 0 if ok, -1 if not ok. - */ -int -__ivaliduser(hostf, raddr, luser, ruser) - FILE *hostf; - u_long raddr; - const char *luser, *ruser; -{ - register char *user, *p; - int ch; - char buf[MAXHOSTNAMELEN + 128]; /* host + login */ - char hname[MAXHOSTNAMELEN]; - struct hostent *hp; - /* Presumed guilty until proven innocent. */ - int userok = 0, hostok = 0; -#ifdef YP - char *ypdomain; - - if (yp_get_default_domain(&ypdomain)) - ypdomain = NULL; -#else -#define ypdomain NULL -#endif - /* We need to get the damn hostname back for netgroup matching. */ - if ((hp = gethostbyaddr((char *)&raddr, sizeof(u_long), - AF_INET)) == NULL) - return (-1); - strncpy(hname, hp->h_name, sizeof(hname)); - hname[sizeof(hname) - 1] = '\0'; - - while (fgets(buf, sizeof(buf), hostf)) { - p = buf; - /* Skip lines that are too long. */ - if (strchr(p, '\n') == NULL) { - while ((ch = getc(hostf)) != '\n' && ch != EOF); - continue; - } - if (*p == '\n' || *p == '#') { - /* comment... */ - continue; - } - while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') { - *p = isupper(*p) ? tolower(*p) : *p; - p++; - } - if (*p == ' ' || *p == '\t') { - *p++ = '\0'; - while (*p == ' ' || *p == '\t') - p++; - user = p; - while (*p != '\n' && *p != ' ' && - *p != '\t' && *p != '\0') - p++; - } else - user = p; - *p = '\0'; - /* - * Do +/- and +@/-@ checking. This looks really nasty, - * but it matches SunOS's behavior so far as I can tell. - */ - switch(buf[0]) { - case '+': - if (!buf[1]) { /* '+' matches all hosts */ - hostok = 1; - break; - } - if (buf[1] == '@') /* match a host by netgroup */ - hostok = innetgr((char *)&buf[2], - (char *)&hname, NULL, ypdomain); - else /* match a host by addr */ - hostok = __icheckhost(raddr,(char *)&buf[1]); - break; - case '-': /* reject '-' hosts and all their users */ - if (buf[1] == '@') { - if (innetgr((char *)&buf[2], - (char *)&hname, NULL, ypdomain)) - return(-1); - } else { - if (__icheckhost(raddr,(char *)&buf[1])) - return(-1); - } - break; - default: /* if no '+' or '-', do a simple match */ - hostok = __icheckhost(raddr, buf); - break; - } - switch(*user) { - case '+': - if (!*(user+1)) { /* '+' matches all users */ - userok = 1; - break; - } - if (*(user+1) == '@') /* match a user by netgroup */ - userok = innetgr(user+2, NULL, ruser, ypdomain); - else /* match a user by direct specification */ - userok = !(strcmp(ruser, user+1)); - break; - case '-': /* if we matched a hostname, */ - if (hostok) { /* check for user field rejections */ - if (!*(user+1)) - return(-1); - if (*(user+1) == '@') { - if (innetgr(user+2, NULL, - ruser, ypdomain)) - return(-1); - } else { - if (!strcmp(ruser, user+1)) - return(-1); - } - } - break; - default: /* no rejections: try to match the user */ - if (hostok) - userok = !(strcmp(ruser,*user ? user : luser)); - break; - } - if (hostok && userok) - return(0); - } - return (-1); -} - -/* - * Returns "true" if match, 0 if no match. - */ -static int -__icheckhost(raddr, lhost) - u_long raddr; - register char *lhost; -{ - register struct hostent *hp; - register u_long laddr; - register char **pp; - - /* Try for raw ip address first. */ - if (isdigit(*lhost) && (long)(laddr = inet_addr(lhost)) != -1) - return (raddr == laddr); - - /* Better be a hostname. */ - if ((hp = gethostbyname(lhost)) == NULL) - return (0); - - /* Spin through ip addresses. */ - for (pp = hp->h_addr_list; *pp; ++pp) - if (!bcmp(&raddr, *pp, sizeof(u_long))) - return (1); - - /* No match. */ - return (0); -} diff --git a/lib/libc/net/recv.c b/lib/libc/net/recv.c deleted file mode 100644 index 65ec9d4..0000000 --- a/lib/libc/net/recv.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)recv.c 8.2 (Berkeley) 2/21/94"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/socket.h> - -#include <stddef.h> - -ssize_t -recv(s, buf, len, flags) - int s, flags; - size_t len; - void *buf; -{ - return (recvfrom(s, buf, len, flags, NULL, 0)); -} diff --git a/lib/libc/net/res_comp.c b/lib/libc/net/res_comp.c deleted file mode 100644 index 86fd4ae..0000000 --- a/lib/libc/net/res_comp.c +++ /dev/null @@ -1,496 +0,0 @@ -/* - * ++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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; -static char orig_rcsid[] = "From: Id: res_comp.c,v 8.12 1997/06/01 20:34:37 vixie Exp"; -static char rcsid[] = "$Id: res_comp.c,v 1.11 1997/06/13 19:21:54 ache Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/nameser.h> - -#include <stdio.h> -#include <resolv.h> -#include <ctype.h> - -#include <unistd.h> -#include <string.h> - -static int dn_find __P((u_char *exp_dn, u_char *msg, - u_char **dnptrs, u_char **lastdnptr)); - -/* - * Expand compressed domain name 'comp_dn' to full domain name. - * 'msg' is a pointer to the begining 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(msg, eomorig, comp_dn, exp_dn, length) - const u_char *msg, *eomorig, *comp_dn; - char *exp_dn; - int length; -{ - register const u_char *cp; - register char *dn; - register int n, c; - char *eom; - int len = -1, checked = 0, octets = 0; - - dn = exp_dn; - cp = comp_dn; - eom = exp_dn + length; - /* - * fetch next label in domain name - */ - while ( (n = *cp++) ) { - /* - * Check for indirection - */ - switch (n & INDIR_MASK) { - case 0: - octets += (n + 1); - if (octets > MAXCDNAME) - return (-1); - 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); -} - -/* - * 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 arrary 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(exp_dn, comp_dn, length, dnptrs, lastdnptr) - const char *exp_dn; - u_char *comp_dn, **dnptrs, **lastdnptr; - int length; -{ - register u_char *cp, *dn; - register int c, l; - u_char **cpp, **lpp, *sp, *eob; - u_char *msg; - - dn = (u_char *)exp_dn; - cp = comp_dn; - if (length > MAXCDNAME) - length = MAXCDNAME; - 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(comp_dn, eom) - const u_char *comp_dn, *eom; -{ - register const u_char *cp; - register 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); -} - -static int -mklower(ch) - register int ch; -{ - if (isascii(ch) && isupper(ch)) - return (tolower(ch)); - return (ch); -} - -/* - * 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(exp_dn, msg, dnptrs, lastdnptr) - u_char *exp_dn, *msg; - u_char **dnptrs, **lastdnptr; -{ - register u_char *dn, *cp, **cpp; - register 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 (mklower(*dn++) != mklower(*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 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)) -#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) - -int -res_hnok(dn) - const char *dn; -{ - int ppch = '\0', pch = PERIOD, ch = *dn++; - - while (ch != '\0') { - int nch = *dn++; - - if (periodchar(ch)) { - NULL; - } 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); - } - ppch = pch, pch = ch, ch = nch; - } - return (1); -} - -/* - * hostname-like (A, MX, WKS) owners can have "*" as their first label - * but must otherwise be as a host name. - */ -int -res_ownok(dn) - 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(dn) - const char *dn; -{ - int ch, escaped = 0; - - /* "." is a valid missing representation */ - if (*dn == '\0') - return(1); - - /* otherwise <label>.<hostname> */ - while ((ch = *dn++) != '\0') { - if (!domainchar(ch)) - return (0); - if (!escaped && periodchar(ch)) - break; - if (escaped) - escaped = 0; - else if (bslashchar(ch)) - escaped = 1; - } - if (periodchar(ch)) - return (res_hnok(dn)); - return(0); -} - -/* - * This function is quite liberal, since RFC 1034's character sets are only - * recommendations. - */ -int -res_dnok(dn) - const char *dn; -{ - int ch; - - while ((ch = *dn++) != '\0') - if (!domainchar(ch)) - return (0); - return (1); -} - -/* - * Routines to insert/extract short/long's. - */ - -u_int16_t -_getshort(msgp) - register const u_char *msgp; -{ - register u_int16_t u; - - GETSHORT(u, msgp); - return (u); -} - -u_int32_t -_getlong(msgp) - register const u_char *msgp; -{ - register u_int32_t u; - - GETLONG(u, msgp); - return (u); -} - -void -#if defined(__STDC__) || defined(__cplusplus) -__putshort(register u_int16_t s, register u_char *msgp) /* must match proto */ -#else -__putshort(s, msgp) - register u_int16_t s; - register u_char *msgp; -#endif -{ - PUTSHORT(s, msgp); -} - -void -__putlong(l, msgp) - register u_int32_t l; - register u_char *msgp; -{ - PUTLONG(l, msgp); -} diff --git a/lib/libc/net/res_config.h b/lib/libc/net/res_config.h deleted file mode 100644 index f29246a..0000000 --- a/lib/libc/net/res_config.h +++ /dev/null @@ -1,8 +0,0 @@ -#define DEBUG 1 /* enable debugging code (needed for dig) */ -#undef ALLOW_T_UNSPEC /* enable the "unspec" RR type for old athena */ -#define RESOLVSORT /* allow sorting of addresses in gethostbyname */ -#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/ -#undef USELOOPBACK /* res_init() bind to localhost */ -#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */ -#define MULTI_PTRS_ARE_ALIASES 1 /* fold multiple PTR records into aliases */ -#define CHECK_SRVR_ADDR 1 /* confirm that the server requested sent the reply */ diff --git a/lib/libc/net/res_data.c b/lib/libc/net/res_data.c deleted file mode 100644 index df0e0dd..0000000 --- a/lib/libc/net/res_data.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * ++Copyright++ 1995 - * - - * Copyright (c) 1995 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> - -#include <stdio.h> -#include <ctype.h> -#include <resolv.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> - -const char *_res_opcodes[] = { - "QUERY", - "IQUERY", - "CQUERYM", - "CQUERYU", /* experimental */ - "NOTIFY", /* experimental */ - "5", - "6", - "7", - "8", - "UPDATEA", - "UPDATED", - "UPDATEDA", - "UPDATEM", - "UPDATEMA", - "ZONEINIT", - "ZONEREF", -}; - -const char *_res_resultcodes[] = { - "NOERROR", - "FORMERR", - "SERVFAIL", - "NXDOMAIN", - "NOTIMP", - "REFUSED", - "6", - "7", - "8", - "9", - "10", - "11", - "12", - "13", - "14", - "NOCHANGE", -}; diff --git a/lib/libc/net/res_debug.c b/lib/libc/net/res_debug.c deleted file mode 100644 index 06b8b42..0000000 --- a/lib/libc/net/res_debug.c +++ /dev/null @@ -1,1520 +0,0 @@ -/* - * ++Copyright++ 1985, 1990, 1993 - * - - * Copyright (c) 1985, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * Portions Copyright (c) 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. - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; -static char orig_rcsid[] = "From: Id: res_debug.c,v 8.20 1997/06/01 20:34:37 vixie Exp"; -static char rcsid[] = "$Id: res_debug.c,v 1.13 1997/02/22 15:00:31 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include "res_config.h" - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/nameser.h> - -#include <ctype.h> -#include <netdb.h> -#include <resolv.h> -#include <stdio.h> -#include <time.h> - -#include <stdlib.h> -#include <string.h> - -extern const char *_res_opcodes[]; -extern const char *_res_resultcodes[]; - -/* XXX: we should use getservbyport() instead. */ -static const char * -dewks(wks) - int wks; -{ - static char nbuf[20]; - - switch (wks) { - case 5: return "rje"; - case 7: return "echo"; - case 9: return "discard"; - case 11: return "systat"; - case 13: return "daytime"; - case 15: return "netstat"; - case 17: return "qotd"; - case 19: return "chargen"; - case 20: return "ftp-data"; - case 21: return "ftp"; - case 23: return "telnet"; - case 25: return "smtp"; - case 37: return "time"; - case 39: return "rlp"; - case 42: return "name"; - case 43: return "whois"; - case 53: return "domain"; - case 57: return "apts"; - case 59: return "apfs"; - case 67: return "bootps"; - case 68: return "bootpc"; - case 69: return "tftp"; - case 77: return "rje"; - case 79: return "finger"; - case 87: return "link"; - case 95: return "supdup"; - case 100: return "newacct"; - case 101: return "hostnames"; - case 102: return "iso-tsap"; - case 103: return "x400"; - case 104: return "x400-snd"; - case 105: return "csnet-ns"; - case 109: return "pop-2"; - case 111: return "sunrpc"; - case 113: return "auth"; - case 115: return "sftp"; - case 117: return "uucp-path"; - case 119: return "nntp"; - case 121: return "erpc"; - case 123: return "ntp"; - case 133: return "statsrv"; - case 136: return "profile"; - case 144: return "NeWS"; - case 161: return "snmp"; - case 162: return "snmp-trap"; - case 170: return "print-srv"; - default: (void) sprintf(nbuf, "%d", wks); return (nbuf); - } -} - -/* XXX: we should use getprotobynumber() instead. */ -static const char * -deproto(protonum) - int protonum; -{ - static char nbuf[20]; - - switch (protonum) { - case 1: return "icmp"; - case 2: return "igmp"; - case 3: return "ggp"; - case 5: return "st"; - case 6: return "tcp"; - case 7: return "ucl"; - case 8: return "egp"; - case 9: return "igp"; - case 11: return "nvp-II"; - case 12: return "pup"; - case 16: return "chaos"; - case 17: return "udp"; - default: (void) sprintf(nbuf, "%d", protonum); return (nbuf); - } -} - -static const u_char * -do_rrset(msg, len, cp, cnt, pflag, file, hs) - int cnt, pflag, len; - const u_char *cp, *msg; - const char *hs; - FILE *file; -{ - int n; - int sflag; - - /* - * Print answer records. - */ - sflag = (_res.pfcode & pflag); - if ((n = ntohs(cnt)) != 0) { - if ((!_res.pfcode) || - ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) - fprintf(file, hs); - while (--n >= 0) { - if ((!_res.pfcode) || sflag) { - cp = p_rr(cp, msg, file); - } else { - unsigned int dlen; - cp += __dn_skipname(cp, cp + MAXCDNAME); - cp += INT16SZ; - cp += INT16SZ; - cp += INT32SZ; - dlen = _getshort((u_char*)cp); - cp += INT16SZ; - cp += dlen; - } - if ((cp - msg) > len) - return (NULL); - } - if ((!_res.pfcode) || - ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) - putc('\n', file); - } - return (cp); -} - -void -__p_query(msg) - const u_char *msg; -{ - __fp_query(msg, stdout); -} - -/* - * Print the current options. - * This is intended to be primarily a debugging routine. - */ -void -__fp_resstat(statp, file) - struct __res_state *statp; - FILE *file; -{ - register u_long mask; - - fprintf(file, ";; res options:"); - if (!statp) - statp = &_res; - for (mask = 1; mask != 0; mask <<= 1) - if (statp->options & mask) - fprintf(file, " %s", p_option(mask)); - putc('\n', file); -} - -/* - * Print the contents of a query. - * This is intended to be primarily a debugging routine. - */ -void -__fp_nquery(msg, len, file) - const u_char *msg; - int len; - FILE *file; -{ - register const u_char *cp, *endMark; - register const HEADER *hp; - register int n; - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) - return; - -#define TruncTest(x) if (x > endMark) goto trunc -#define ErrorTest(x) if (x == NULL) goto error - - /* - * Print header fields. - */ - hp = (HEADER *)msg; - cp = msg + HFIXEDSZ; - endMark = msg + len; - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) { - fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d", - _res_opcodes[hp->opcode], - _res_resultcodes[hp->rcode], - ntohs(hp->id)); - putc('\n', file); - } - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX)) - putc(';', file); - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { - fprintf(file, "; flags:"); - if (hp->qr) - fprintf(file, " qr"); - if (hp->aa) - fprintf(file, " aa"); - if (hp->tc) - fprintf(file, " tc"); - if (hp->rd) - fprintf(file, " rd"); - if (hp->ra) - fprintf(file, " ra"); - if (hp->unused) - fprintf(file, " UNUSED-BIT-ON"); - if (hp->ad) - fprintf(file, " ad"); - if (hp->cd) - fprintf(file, " cd"); - } - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) { - fprintf(file, "; Ques: %d", ntohs(hp->qdcount)); - fprintf(file, ", Ans: %d", ntohs(hp->ancount)); - fprintf(file, ", Auth: %d", ntohs(hp->nscount)); - fprintf(file, ", Addit: %d", ntohs(hp->arcount)); - } - if ((!_res.pfcode) || (_res.pfcode & - (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { - putc('\n',file); - } - /* - * Print question records. - */ - if ((n = ntohs(hp->qdcount)) != 0) { - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - fprintf(file, ";; QUESTIONS:\n"); - while (--n >= 0) { - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - fprintf(file, ";;\t"); - TruncTest(cp); - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - cp = p_cdnname(cp, msg, len, file); - else { - int n; - char name[MAXDNAME]; - - if ((n = dn_expand(msg, msg+len, cp, name, - sizeof name)) < 0) - cp = NULL; - else - cp += n; - } - ErrorTest(cp); - TruncTest(cp); - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - fprintf(file, ", type = %s", - __p_type(_getshort((u_char*)cp))); - cp += INT16SZ; - TruncTest(cp); - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - fprintf(file, ", class = %s\n", - __p_class(_getshort((u_char*)cp))); - cp += INT16SZ; - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - putc('\n', file); - } - } - /* - * Print authoritative answer records - */ - TruncTest(cp); - cp = do_rrset(msg, len, cp, hp->ancount, RES_PRF_ANS, file, - ";; ANSWERS:\n"); - ErrorTest(cp); - - /* - * print name server records - */ - TruncTest(cp); - cp = do_rrset(msg, len, cp, hp->nscount, RES_PRF_AUTH, file, - ";; AUTHORITY RECORDS:\n"); - ErrorTest(cp); - - TruncTest(cp); - /* - * print additional records - */ - cp = do_rrset(msg, len, cp, hp->arcount, RES_PRF_ADD, file, - ";; ADDITIONAL RECORDS:\n"); - ErrorTest(cp); - return; - trunc: - fprintf(file, "\n;; ...truncated\n"); - return; - error: - fprintf(file, "\n;; ...malformed\n"); -} - -void -__fp_query(msg, file) - const u_char *msg; - FILE *file; -{ - fp_nquery(msg, PACKETSZ, file); -} - -const u_char * -__p_cdnname(cp, msg, len, file) - const u_char *cp, *msg; - int len; - FILE *file; -{ - char name[MAXDNAME]; - int n; - - if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0) - return (NULL); - if (name[0] == '\0') - putc('.', file); - else - fputs(name, file); - return (cp + n); -} - -const u_char * -__p_cdname(cp, msg, file) - const u_char *cp, *msg; - FILE *file; -{ - return (p_cdnname(cp, msg, PACKETSZ, file)); -} - - -/* Return a fully-qualified domain name from a compressed name (with - length supplied). */ - -const u_char * -__p_fqnname(cp, msg, msglen, name, namelen) - const u_char *cp, *msg; - int msglen; - char *name; - int namelen; -{ - int n, newlen; - - if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0) - return (NULL); - newlen = strlen (name); - if (newlen == 0 || name[newlen - 1] != '.') - if (newlen+1 >= namelen) /* Lack space for final dot */ - return (NULL); - else - strcpy(name + newlen, "."); - return (cp + n); -} - -/* XXX: the rest of these functions need to become length-limited, too. (vix) - */ - -const u_char * -__p_fqname(cp, msg, file) - const u_char *cp, *msg; - FILE *file; -{ - char name[MAXDNAME]; - const u_char *n; - - n = __p_fqnname(cp, msg, MAXCDNAME, name, sizeof name); - if (n == NULL) - return (NULL); - fputs(name, file); - return (n); -} - -/* - * Print resource record fields in human readable form. - */ -const u_char * -__p_rr(cp, msg, file) - const u_char *cp, *msg; - FILE *file; -{ - int type, class, dlen, n, c; - struct in_addr inaddr; - const u_char *cp1, *cp2; - u_int32_t tmpttl, t; - int lcnt; - u_int16_t keyflags; - char rrname[MAXDNAME]; /* The fqdn of this RR */ - char base64_key[MAX_KEY_BASE64]; - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - cp = __p_fqnname(cp, msg, MAXCDNAME, rrname, sizeof rrname); - if (!cp) - return (NULL); /* compression error */ - fputs(rrname, file); - - type = _getshort((u_char*)cp); - cp += INT16SZ; - class = _getshort((u_char*)cp); - cp += INT16SZ; - tmpttl = _getlong((u_char*)cp); - cp += INT32SZ; - dlen = _getshort((u_char*)cp); - cp += INT16SZ; - cp1 = cp; - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID)) - fprintf(file, "\t%lu", (u_long)tmpttl); - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS)) - fprintf(file, "\t%s", __p_class(class)); - fprintf(file, "\t%s", __p_type(type)); - /* - * Print type specific data, if appropriate - */ - switch (type) { - case T_A: - switch (class) { - case C_IN: - case C_HS: - bcopy(cp, (char *)&inaddr, INADDRSZ); - if (dlen == 4) { - fprintf(file, "\t%s", inet_ntoa(inaddr)); - cp += dlen; - } else if (dlen == 7) { - char *address; - u_char protocol; - u_short port; - - address = inet_ntoa(inaddr); - cp += INADDRSZ; - protocol = *(u_char*)cp; - cp += sizeof (u_char); - port = _getshort((u_char*)cp); - cp += INT16SZ; - fprintf(file, "\t%s\t; proto %d, port %d", - address, protocol, port); - } - break; - default: - cp += dlen; - } - break; - case T_CNAME: - case T_MB: - case T_MG: - case T_MR: - case T_NS: - case T_PTR: - putc('\t', file); - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - break; - - case T_HINFO: - case T_ISDN: - cp2 = cp + dlen; - (void) fputs("\t\"", file); - if ((n = (unsigned char) *cp++) != 0) { - for (c = n; c > 0 && cp < cp2; c--) { - if (strchr("\n\"\\", *cp)) - (void) putc('\\', file); - (void) putc(*cp++, file); - } - } - putc('"', file); - if (cp < cp2 && (n = (unsigned char) *cp++) != 0) { - (void) fputs ("\t\"", file); - for (c = n; c > 0 && cp < cp2; c--) { - if (strchr("\n\"\\", *cp)) - (void) putc('\\', file); - (void) putc(*cp++, file); - } - putc('"', file); - } else if (type == T_HINFO) { - (void) fputs("\"?\"", file); - fprintf(file, "\n;; *** Warning *** OS-type missing"); - } - break; - - case T_SOA: - putc('\t', file); - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - putc(' ', file); - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - fputs(" (\n", file); - t = _getlong((u_char*)cp); cp += INT32SZ; - fprintf(file, "\t\t\t%lu\t; serial\n", (u_long)t); - t = _getlong((u_char*)cp); cp += INT32SZ; - fprintf(file, "\t\t\t%lu\t; refresh (%s)\n", - (u_long)t, __p_time(t)); - t = _getlong((u_char*)cp); cp += INT32SZ; - fprintf(file, "\t\t\t%lu\t; retry (%s)\n", - (u_long)t, __p_time(t)); - t = _getlong((u_char*)cp); cp += INT32SZ; - fprintf(file, "\t\t\t%lu\t; expire (%s)\n", - (u_long)t, __p_time(t)); - t = _getlong((u_char*)cp); cp += INT32SZ; - fprintf(file, "\t\t\t%lu )\t; minimum (%s)", - (u_long)t, __p_time(t)); - break; - - case T_MX: - case T_AFSDB: - case T_RT: - fprintf(file, "\t%d ", _getshort((u_char*)cp)); - cp += INT16SZ; - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - break; - - case T_PX: - fprintf(file, "\t%d ", _getshort((u_char*)cp)); - cp += INT16SZ; - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - putc(' ', file); - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - break; - - case T_X25: - cp2 = cp + dlen; - (void) fputs("\t\"", file); - if ((n = (unsigned char) *cp++) != 0) { - for (c = n; c > 0 && cp < cp2; c--) { - if (strchr("\n\"\\", *cp)) - (void) putc('\\', file); - (void) putc(*cp++, file); - } - } - putc('"', file); - break; - - case T_TXT: - (void) putc('\t', file); - cp2 = cp1 + dlen; - while (cp < cp2) { - putc('"', file); - if ((n = (unsigned char) *cp++) != '\0') { - for (c = n; c > 0 && cp < cp2; c--) { - if (strchr("\n\"\\", *cp)) - (void) putc('\\', file); - (void) putc(*cp++, file); - } - } - putc('"', file); - if (cp < cp2) - putc(' ', file); - } - break; - - case T_NSAP: - (void) fprintf(file, "\t%s", inet_nsap_ntoa(dlen, cp, NULL)); - cp += dlen; - break; - - case T_AAAA: { - char t[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; - - fprintf(file, "\t%s", inet_ntop(AF_INET6, cp, t, sizeof t)); - cp += dlen; - break; - } - - case T_LOC: { - char t[255]; - - fprintf(file, "\t%s", loc_ntoa(cp, t)); - cp += dlen; - break; - } - - case T_NAPTR: { - u_int order, preference; - - order = _getshort(cp); cp += INT16SZ; - preference = _getshort(cp); cp += INT16SZ; - fprintf(file, "\t%u %u ",order, preference); - /* Flags */ - n = *cp++; - fprintf(file,"\"%.*s\" ", (int)n, cp); - cp += n; - /* Service */ - n = *cp++; - fprintf(file,"\"%.*s\" ", (int)n, cp); - cp += n; - /* Regexp */ - n = *cp++; - fprintf(file,"\"%.*s\" ", (int)n, cp); - cp += n; - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - break; - } - - case T_SRV: { - u_int priority, weight, port; - - priority = _getshort(cp); cp += INT16SZ; - weight = _getshort(cp); cp += INT16SZ; - port = _getshort(cp); cp += INT16SZ; - fprintf(file, "\t%u %u %u ", priority, weight, port); - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - break; - } - - case T_MINFO: - case T_RP: - putc('\t', file); - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - putc(' ', file); - if ((cp = p_fqname(cp, msg, file)) == NULL) - return (NULL); - break; - - case T_UINFO: - putc('\t', file); - fputs((char *)cp, file); - cp += dlen; - break; - - case T_UID: - case T_GID: - if (dlen == 4) { - fprintf(file, "\t%u", _getlong((u_char*)cp)); - cp += INT32SZ; - } - break; - - case T_WKS: - if (dlen < INT32SZ + 1) - break; - bcopy(cp, (char *)&inaddr, INADDRSZ); - cp += INT32SZ; - fprintf(file, "\t%s %s ( ", - inet_ntoa(inaddr), - deproto((int) *cp)); - cp += sizeof (u_char); - n = 0; - lcnt = 0; - while (cp < cp1 + dlen) { - c = *cp++; - do { - if (c & 0200) { - if (lcnt == 0) { - fputs("\n\t\t\t", file); - lcnt = 5; - } - fputs(dewks(n), file); - putc(' ', file); - lcnt--; - } - c <<= 1; - } while (++n & 07); - } - putc(')', file); - break; - - case T_KEY: - putc('\t', file); - keyflags = _getshort(cp); - cp += 2; - fprintf(file,"0x%04x", keyflags ); /* flags */ - fprintf(file," %u", *cp++); /* protocol */ - fprintf(file," %u (", *cp++); /* algorithm */ - - n = b64_ntop(cp, (cp1 + dlen) - cp, - base64_key, sizeof base64_key); - for (c = 0; c < n; ++c) { - if (0 == (c & 0x3F)) - fprintf(file, "\n\t"); - putc(base64_key[c], file); /* public key data */ - } - - fprintf(file, " )"); - if (n < 0) - fprintf(file, "\t; BAD BASE64"); - fflush(file); - cp = cp1 + dlen; - break; - - case T_SIG: - type = _getshort((u_char*)cp); - cp += INT16SZ; - fprintf(file, " %s", p_type(type)); - fprintf(file, "\t%d", *cp++); /* algorithm */ - /* Check label value and print error if wrong. */ - n = *cp++; - c = dn_count_labels (rrname); - if (n != c) - fprintf(file, "\t; LABELS WRONG (%d should be %d)\n\t", - n, c); - /* orig ttl */ - n = _getlong((u_char*)cp); - if (n != tmpttl) - fprintf(file, " %u", n); - cp += INT32SZ; - /* sig expire */ - fprintf(file, " (\n\t%s", - __p_secstodate(_getlong((u_char*)cp))); - cp += INT32SZ; - /* time signed */ - fprintf(file, " %s", __p_secstodate(_getlong((u_char*)cp))); - cp += INT32SZ; - /* sig footprint */ - fprintf(file," %u ", _getshort((u_char*)cp)); - cp += INT16SZ; - /* signer's name */ - cp = p_fqname(cp, msg, file); - n = b64_ntop(cp, (cp1 + dlen) - cp, - base64_key, sizeof base64_key); - for (c = 0; c < n; c++) { - if (0 == (c & 0x3F)) - fprintf (file, "\n\t"); - putc(base64_key[c], file); /* signature */ - } - /* Clean up... */ - fprintf(file, " )"); - if (n < 0) - fprintf(file, "\t; BAD BASE64"); - fflush(file); - cp = cp1+dlen; - break; - -#ifdef ALLOW_T_UNSPEC - case T_UNSPEC: - { - int NumBytes = 8; - u_char *DataPtr; - int i; - - if (dlen < NumBytes) NumBytes = dlen; - fprintf(file, "\tFirst %d bytes of hex data:", - NumBytes); - for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++) - fprintf(file, " %x", *DataPtr); - cp += dlen; - } - break; -#endif /* ALLOW_T_UNSPEC */ - - default: - fprintf(file, "\t?%d?", type); - cp += dlen; - } -#if 0 - fprintf(file, "\t; dlen=%d, ttl %s\n", dlen, __p_time(tmpttl)); -#else - putc('\n', file); -#endif - if (cp - cp1 != dlen) { - fprintf(file, ";; packet size error (found %d, dlen was %d)\n", - cp - cp1, dlen); - cp = NULL; - } - return (cp); -} - -/* - * Names of RR classes and qclasses. Classes and qclasses are the same, except - * that C_ANY is a qclass but not a class. (You can ask for records of class - * C_ANY, but you can't have any records of that class in the database.) - */ -const struct res_sym __p_class_syms[] = { - {C_IN, "IN"}, - {C_CHAOS, "CHAOS"}, - {C_HS, "HS"}, - {C_HS, "HESIOD"}, - {C_ANY, "ANY"}, - {C_IN, (char *)0} -}; - -/* - * Names of RR types and qtypes. Types and qtypes are the same, except - * that T_ANY is a qtype but not a type. (You can ask for records of type - * T_ANY, but you can't have any records of that type in the database.) - */ -const struct res_sym __p_type_syms[] = { - {T_A, "A", "address"}, - {T_NS, "NS", "name server"}, - {T_MD, "MD", "mail destination (deprecated)"}, - {T_MF, "MF", "mail forwarder (deprecated)"}, - {T_CNAME, "CNAME", "canonical name"}, - {T_SOA, "SOA", "start of authority"}, - {T_MB, "MB", "mailbox"}, - {T_MG, "MG", "mail group member"}, - {T_MR, "MR", "mail rename"}, - {T_NULL, "NULL", "null"}, - {T_WKS, "WKS", "well-known service (deprecated)"}, - {T_PTR, "PTR", "domain name pointer"}, - {T_HINFO, "HINFO", "host information"}, - {T_MINFO, "MINFO", "mailbox information"}, - {T_MX, "MX", "mail exchanger"}, - {T_TXT, "TXT", "text"}, - {T_RP, "RP", "responsible person"}, - {T_AFSDB, "AFSDB", "DCE or AFS server"}, - {T_X25, "X25", "X25 address"}, - {T_ISDN, "ISDN", "ISDN address"}, - {T_RT, "RT", "router"}, - {T_NSAP, "NSAP", "nsap address"}, - {T_NSAP_PTR, "NSAP_PTR", "domain name pointer"}, - {T_SIG, "SIG", "signature"}, - {T_KEY, "KEY", "key"}, - {T_PX, "PX", "mapping information"}, - {T_GPOS, "GPOS", "geographical position (withdrawn)"}, - {T_AAAA, "AAAA", "IPv6 address"}, - {T_LOC, "LOC", "location"}, - {T_NXT, "NXT", "next valid name (unimplemented)"}, - {T_EID, "EID", "endpoint identifier (unimplemented)"}, - {T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"}, - {T_SRV, "SRV", "server selection"}, - {T_ATMA, "ATMA", "ATM address (unimplemented)"}, - {T_IXFR, "IXFR", "incremental zone transfer"}, - {T_AXFR, "AXFR", "zone transfer"}, - {T_MAILB, "MAILB", "mailbox-related data (deprecated)"}, - {T_MAILA, "MAILA", "mail agent (deprecated)"}, - {T_UINFO, "UINFO", "user information (nonstandard)"}, - {T_UID, "UID", "user ID (nonstandard)"}, - {T_GID, "GID", "group ID (nonstandard)"}, - {T_NAPTR, "NAPTR", "URN Naming Authority"}, -#ifdef ALLOW_T_UNSPEC - {T_UNSPEC, "UNSPEC", "unspecified data (nonstandard)"}, -#endif /* ALLOW_T_UNSPEC */ - {T_ANY, "ANY", "\"any\""}, - {0, NULL, NULL} -}; - -int -__sym_ston(syms, name, success) - const struct res_sym *syms; - char *name; - int *success; -{ - for (NULL; syms->name != 0; syms++) { - if (strcasecmp (name, syms->name) == 0) { - if (success) - *success = 1; - return (syms->number); - } - } - if (success) - *success = 0; - return (syms->number); /* The default value. */ -} - -const char * -__sym_ntos(syms, number, success) - const struct res_sym *syms; - int number; - int *success; -{ - static char unname[20]; - - for (NULL; syms->name != 0; syms++) { - if (number == syms->number) { - if (success) - *success = 1; - return (syms->name); - } - } - - sprintf (unname, "%d", number); - if (success) - *success = 0; - return (unname); -} - - -const char * -__sym_ntop(syms, number, success) - const struct res_sym *syms; - int number; - int *success; -{ - static char unname[20]; - - for (NULL; syms->name != 0; syms++) { - if (number == syms->number) { - if (success) - *success = 1; - return (syms->humanname); - } - } - sprintf(unname, "%d", number); - if (success) - *success = 0; - return (unname); -} - -/* - * Return a string for the type - */ -const char * -__p_type(type) - int type; -{ - return (__sym_ntos (__p_type_syms, type, (int *)0)); -} - -/* - * Return a mnemonic for class - */ -const char * -__p_class(class) - int class; -{ - return (__sym_ntos (__p_class_syms, class, (int *)0)); -} - -/* - * Return a mnemonic for an option - */ -const char * -__p_option(option) - u_long option; -{ - static char nbuf[40]; - - switch (option) { - case RES_INIT: return "init"; - case RES_DEBUG: return "debug"; - case RES_AAONLY: return "aaonly(unimpl)"; - case RES_USEVC: return "usevc"; - case RES_PRIMARY: return "primry(unimpl)"; - case RES_IGNTC: return "igntc"; - case RES_RECURSE: return "recurs"; - case RES_DEFNAMES: return "defnam"; - case RES_STAYOPEN: return "styopn"; - case RES_DNSRCH: return "dnsrch"; - case RES_INSECURE1: return "insecure1"; - case RES_INSECURE2: return "insecure2"; - default: sprintf(nbuf, "?0x%lx?", (u_long)option); - return (nbuf); - } -} - -/* - * Return a mnemonic for a time to live - */ -const char * -p_time(value) - u_int32_t value; -{ - static char nbuf[40]; - int secs, mins, hours, days; - register char *p; - - if (value == 0) { - strcpy(nbuf, "0 secs"); - return (nbuf); - } - - secs = value % 60; - value /= 60; - mins = value % 60; - value /= 60; - hours = value % 24; - value /= 24; - days = value; - value = 0; - -#define PLURALIZE(x) x, (x == 1) ? "" : "s" - p = nbuf; - if (days) { - (void)sprintf(p, "%d day%s", PLURALIZE(days)); - while (*++p); - } - if (hours) { - if (days) - *p++ = ' '; - (void)sprintf(p, "%d hour%s", PLURALIZE(hours)); - while (*++p); - } - if (mins) { - if (days || hours) - *p++ = ' '; - (void)sprintf(p, "%d min%s", PLURALIZE(mins)); - while (*++p); - } - if (secs || ! (days || hours || mins)) { - if (days || hours || mins) - *p++ = ' '; - (void)sprintf(p, "%d sec%s", PLURALIZE(secs)); - } - return (nbuf); -} - -/* - * routines to convert between on-the-wire RR format and zone file format. - * Does not contain conversion to/from decimal degrees; divide or multiply - * by 60*60*1000 for that. - */ - -static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000, - 1000000,10000000,100000000,1000000000}; - -/* takes an XeY precision/size value, returns a string representation. */ -static const char * -precsize_ntoa(prec) - u_int8_t prec; -{ - static char retbuf[sizeof "90000000.00"]; - unsigned long val; - int mantissa, exponent; - - mantissa = (int)((prec >> 4) & 0x0f) % 10; - exponent = (int)((prec >> 0) & 0x0f) % 10; - - val = mantissa * poweroften[exponent]; - - (void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100); - return (retbuf); -} - -/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */ -static u_int8_t -precsize_aton(strptr) - char **strptr; -{ - u_int8_t retval = 0; - char *cp; - int exponent = 0; - int mantissa = 0; - - cp = *strptr; - while (isdigit(*cp)) { - if (mantissa == 0) - mantissa = *cp - '0'; - else - exponent++; - cp++; - } - - if (*cp == '.') { - cp++; - if (isdigit(*cp)) { - if (mantissa == 0) - mantissa = *cp - '0'; - else - exponent++; - cp++; - - if (isdigit(*cp)) { - if (mantissa == 0) - mantissa = *cp - '0'; - else - exponent++; - cp++; - } - else - exponent++; - } - } - else - exponent += 2; - - if (mantissa == 0) - exponent = 0; - retval = (mantissa << 4) | exponent; - *strptr = cp; - return (retval); -} - -/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */ -static u_int32_t -latlon2ul(latlonstrptr,which) - char **latlonstrptr; - int *which; -{ - register char *cp; - u_int32_t retval; - int deg = 0, min = 0, secs = 0, secsfrac = 0; - - cp = *latlonstrptr; - - while (isdigit(*cp)) - deg = deg * 10 + (*cp++ - '0'); - - while (isspace(*cp)) - cp++; - - if (!(isdigit(*cp))) - goto fndhemi; - - while (isdigit(*cp)) - min = min * 10 + (*cp++ - '0'); - - while (isspace(*cp)) - cp++; - - if (!(isdigit(*cp))) - goto fndhemi; - - while (isdigit(*cp)) - secs = secs * 10 + (*cp++ - '0'); - - if (*cp == '.') { /* decimal seconds */ - cp++; - if (isdigit(*cp)) { - secsfrac = (*cp++ - '0') * 100; - if (isdigit(*cp)) { - secsfrac += (*cp++ - '0') * 10; - if (isdigit(*cp)) { - secsfrac += (*cp++ - '0'); - } - } - } - } - - while (!isspace(*cp)) /* if any trailing garbage */ - cp++; - - while (isspace(*cp)) - cp++; - - fndhemi: - switch (*cp) { - case 'N': case 'n': - case 'E': case 'e': - retval = ((unsigned)1<<31) - + (((((deg * 60) + min) * 60) + secs) * 1000) - + secsfrac; - break; - case 'S': case 's': - case 'W': case 'w': - retval = ((unsigned)1<<31) - - (((((deg * 60) + min) * 60) + secs) * 1000) - - secsfrac; - break; - default: - retval = 0; /* invalid value -- indicates error */ - break; - } - - switch (*cp) { - case 'N': case 'n': - case 'S': case 's': - *which = 1; /* latitude */ - break; - case 'E': case 'e': - case 'W': case 'w': - *which = 2; /* longitude */ - break; - default: - *which = 0; /* error */ - break; - } - - cp++; /* skip the hemisphere */ - - while (!isspace(*cp)) /* if any trailing garbage */ - cp++; - - while (isspace(*cp)) /* move to next field */ - cp++; - - *latlonstrptr = cp; - - return (retval); -} - -/* converts a zone file representation in a string to an RDATA on-the-wire - * representation. */ -int -loc_aton(ascii, binary) - const char *ascii; - u_char *binary; -{ - const char *cp, *maxcp; - u_char *bcp; - - u_int32_t latit = 0, longit = 0, alt = 0; - u_int32_t lltemp1 = 0, lltemp2 = 0; - int altmeters = 0, altfrac = 0, altsign = 1; - u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */ - u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */ - u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */ - int which1 = 0, which2 = 0; - - cp = ascii; - maxcp = cp + strlen(ascii); - - lltemp1 = latlon2ul(&cp, &which1); - - lltemp2 = latlon2ul(&cp, &which2); - - switch (which1 + which2) { - case 3: /* 1 + 2, the only valid combination */ - if ((which1 == 1) && (which2 == 2)) { /* normal case */ - latit = lltemp1; - longit = lltemp2; - } else if ((which1 == 2) && (which2 == 1)) { /* reversed */ - longit = lltemp1; - latit = lltemp2; - } else { /* some kind of brokenness */ - return (0); - } - break; - default: /* we didn't get one of each */ - return (0); - } - - /* altitude */ - if (*cp == '-') { - altsign = -1; - cp++; - } - - if (*cp == '+') - cp++; - - while (isdigit(*cp)) - altmeters = altmeters * 10 + (*cp++ - '0'); - - if (*cp == '.') { /* decimal meters */ - cp++; - if (isdigit(*cp)) { - altfrac = (*cp++ - '0') * 10; - if (isdigit(*cp)) { - altfrac += (*cp++ - '0'); - } - } - } - - alt = (10000000 + (altsign * (altmeters * 100 + altfrac))); - - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ - cp++; - - while (isspace(*cp) && (cp < maxcp)) - cp++; - - if (cp >= maxcp) - goto defaults; - - siz = precsize_aton(&cp); - - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ - cp++; - - while (isspace(*cp) && (cp < maxcp)) - cp++; - - if (cp >= maxcp) - goto defaults; - - hp = precsize_aton(&cp); - - while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */ - cp++; - - while (isspace(*cp) && (cp < maxcp)) - cp++; - - if (cp >= maxcp) - goto defaults; - - vp = precsize_aton(&cp); - - defaults: - - bcp = binary; - *bcp++ = (u_int8_t) 0; /* version byte */ - *bcp++ = siz; - *bcp++ = hp; - *bcp++ = vp; - PUTLONG(latit,bcp); - PUTLONG(longit,bcp); - PUTLONG(alt,bcp); - - return (16); /* size of RR in octets */ -} - -/* takes an on-the-wire LOC RR and formats it in a human readable format. */ -const char * -loc_ntoa(binary, ascii) - const u_char *binary; - char *ascii; -{ - static char *error = "?"; - register const u_char *cp = binary; - - int latdeg, latmin, latsec, latsecfrac; - int longdeg, longmin, longsec, longsecfrac; - char northsouth, eastwest; - int altmeters, altfrac, altsign; - - const int referencealt = 100000 * 100; - - int32_t latval, longval, altval; - u_int32_t templ; - u_int8_t sizeval, hpval, vpval, versionval; - - char *sizestr, *hpstr, *vpstr; - - versionval = *cp++; - - if (versionval) { - sprintf(ascii, "; error: unknown LOC RR version"); - return (ascii); - } - - sizeval = *cp++; - - hpval = *cp++; - vpval = *cp++; - - GETLONG(templ, cp); - latval = (templ - ((unsigned)1<<31)); - - GETLONG(templ, cp); - longval = (templ - ((unsigned)1<<31)); - - GETLONG(templ, cp); - if (templ < referencealt) { /* below WGS 84 spheroid */ - altval = referencealt - templ; - altsign = -1; - } else { - altval = templ - referencealt; - altsign = 1; - } - - if (latval < 0) { - northsouth = 'S'; - latval = -latval; - } else - northsouth = 'N'; - - latsecfrac = latval % 1000; - latval = latval / 1000; - latsec = latval % 60; - latval = latval / 60; - latmin = latval % 60; - latval = latval / 60; - latdeg = latval; - - if (longval < 0) { - eastwest = 'W'; - longval = -longval; - } else - eastwest = 'E'; - - longsecfrac = longval % 1000; - longval = longval / 1000; - longsec = longval % 60; - longval = longval / 60; - longmin = longval % 60; - longval = longval / 60; - longdeg = longval; - - altfrac = altval % 100; - altmeters = (altval / 100) * altsign; - - if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL) - sizestr = error; - if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL) - hpstr = error; - if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL) - vpstr = error; - - sprintf(ascii, - "%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm", - latdeg, latmin, latsec, latsecfrac, northsouth, - longdeg, longmin, longsec, longsecfrac, eastwest, - altmeters, altfrac, sizestr, hpstr, vpstr); - - if (sizestr != error) - free(sizestr); - if (hpstr != error) - free(hpstr); - if (vpstr != error) - free(vpstr); - - return (ascii); -} - - -/* Return the number of DNS hierarchy levels in the name. */ -int -__dn_count_labels(name) - char *name; -{ - int i, len, count; - - len = strlen(name); - - for(i = 0, count = 0; i < len; i++) { - if (name[i] == '.') - count++; - } - - /* don't count initial wildcard */ - if (name[0] == '*') - if (count) - count--; - - /* don't count the null label for root. */ - /* if terminating '.' not found, must adjust */ - /* count to include last label */ - if (len > 0 && name[len-1] != '.') - count++; - return (count); -} - - -/* - * Make dates expressed in seconds-since-Jan-1-1970 easy to read. - * SIG records are required to be printed like this, by the Secure DNS RFC. - */ -char * -__p_secstodate (secs) - unsigned long secs; -{ - static char output[15]; /* YYYYMMDDHHMMSS and null */ - time_t clock = secs; - struct tm *time; - - time = gmtime(&clock); - time->tm_year += 1900; - time->tm_mon += 1; - sprintf(output, "%04d%02d%02d%02d%02d%02d", - time->tm_year, time->tm_mon, time->tm_mday, - time->tm_hour, time->tm_min, time->tm_sec); - return (output); -} diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c deleted file mode 100644 index bf12280..0000000 --- a/lib/libc/net/res_init.c +++ /dev/null @@ -1,461 +0,0 @@ -/* - * ++Copyright++ 1985, 1989, 1993 - * - - * Copyright (c) 1985, 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static char orig_rcsid[] = "From: Id: res_init.c,v 8.8 1997/06/01 20:34:37 vixie Exp"; -static char rcsid[] = "$Id: res_init.c,v 1.13 1997/06/27 08:22:03 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#include "res_config.h" -#include <arpa/nameser.h> - -#include <stdio.h> -#include <ctype.h> -#include <resolv.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> - -static void res_setoptions __P((char *, char *)); - -#ifdef RESOLVSORT -static const char sort_mask[] = "/&"; -#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL) -static u_int32_t net_mask __P((struct in_addr)); -#endif - -/* - * Resolver state default settings. - */ - -struct __res_state _res -# if defined(__BIND_RES_TEXT) - = { RES_TIMEOUT, } /* Motorola, et al. */ -# endif - ; - -/* - * Set up default settings. If the configuration file exist, the values - * there will have precedence. Otherwise, the server address is set to - * INADDR_ANY and the default domain name comes from the gethostname(). - * - * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1 - * rather than INADDR_ANY ("0.0.0.0") as the default name server address - * since it was noted that INADDR_ANY actually meant ``the first interface - * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface, - * it had to be "up" in order for you to reach your own name server. It - * was later decided that since the recommended practice is to always - * install local static routes through 127.0.0.1 for all your network - * interfaces, that we could solve this problem without a code change. - * - * The configuration file should always be used, since it is the only way - * to specify a default domain. If you are running a server on your local - * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1" - * in the configuration file. - * - * Return 0 if completes successfully, -1 on error - */ -int -res_init() -{ - register FILE *fp; - register char *cp, **pp; - register int n; - char buf[MAXDNAME]; - int nserv = 0; /* number of nameserver records read from file */ - int haveenv = 0; - int havesearch = 0; -#ifdef RESOLVSORT - int nsort = 0; - char *net; -#endif -#ifndef RFC1535 - int dots; -#endif - - /* - * These three fields used to be statically initialized. This made - * it hard to use this code in a shared library. It is necessary, - * now that we're doing dynamic initialization here, that we preserve - * the old semantics: if an application modifies one of these three - * fields of _res before res_init() is called, res_init() will not - * alter them. Of course, if an application is setting them to - * _zero_ before calling res_init(), hoping to override what used - * to be the static default, we can't detect it and unexpected results - * will follow. Zero for any of these fields would make no sense, - * so one can safely assume that the applications were already getting - * unexpected results. - * - * _res.options is tricky since some apps were known to diddle the bits - * before res_init() was first called. We can't replicate that semantic - * with dynamic initialization (they may have turned bits off that are - * set in RES_DEFAULT). Our solution is to declare such applications - * "broken". They could fool us by setting RES_INIT but none do (yet). - */ - if (!_res.retrans) - _res.retrans = RES_TIMEOUT; - if (!_res.retry) - _res.retry = 4; - if (!(_res.options & RES_INIT)) - _res.options = RES_DEFAULT; - - /* - * This one used to initialize implicitly to zero, so unless the app - * has set it to something in particular, we can randomize it now. - */ - if (!_res.id) - _res.id = res_randomid(); - -#ifdef USELOOPBACK - _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); -#else - _res.nsaddr.sin_addr.s_addr = INADDR_ANY; -#endif - _res.nsaddr.sin_family = AF_INET; - _res.nsaddr.sin_port = htons(NAMESERVER_PORT); - _res.nscount = 1; - _res.ndots = 1; - _res.pfcode = 0; - - /* Allow user to override the local domain definition */ - if ((cp = getenv("LOCALDOMAIN")) != NULL) { - (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); - haveenv++; - - /* - * Set search list to be blank-separated strings - * from rest of env value. Permits users of LOCALDOMAIN - * to still have a search list, and anyone to set the - * one that they want to use as an individual (even more - * important now that the rfc1535 stuff restricts searches) - */ - cp = _res.defdname; - pp = _res.dnsrch; - *pp++ = cp; - for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { - if (*cp == '\n') /* silly backwards compat */ - break; - else if (*cp == ' ' || *cp == '\t') { - *cp = 0; - n = 1; - } else if (n) { - *pp++ = cp; - n = 0; - havesearch = 1; - } - } - /* null terminate last domain if there are excess */ - while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n') - cp++; - *cp = '\0'; - *pp++ = 0; - } - -#define MATCH(line, name) \ - (!strncmp(line, name, sizeof(name) - 1) && \ - (line[sizeof(name) - 1] == ' ' || \ - line[sizeof(name) - 1] == '\t')) - - if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { - /* read the config file */ - while (fgets(buf, sizeof(buf), fp) != NULL) { - /* skip comments */ - if (*buf == ';' || *buf == '#') - continue; - /* read default domain name */ - if (MATCH(buf, "domain")) { - if (haveenv) /* skip if have from environ */ - continue; - cp = buf + sizeof("domain") - 1; - while (*cp == ' ' || *cp == '\t') - cp++; - if ((*cp == '\0') || (*cp == '\n')) - continue; - strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); - if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) - *cp = '\0'; - havesearch = 0; - continue; - } - /* set search list */ - if (MATCH(buf, "search")) { - if (haveenv) /* skip if have from environ */ - continue; - cp = buf + sizeof("search") - 1; - while (*cp == ' ' || *cp == '\t') - cp++; - if ((*cp == '\0') || (*cp == '\n')) - continue; - strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); - if ((cp = strchr(_res.defdname, '\n')) != NULL) - *cp = '\0'; - /* - * Set search list to be blank-separated strings - * on rest of line. - */ - cp = _res.defdname; - pp = _res.dnsrch; - *pp++ = cp; - for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { - if (*cp == ' ' || *cp == '\t') { - *cp = 0; - n = 1; - } else if (n) { - *pp++ = cp; - n = 0; - } - } - /* null terminate last domain if there are excess */ - while (*cp != '\0' && *cp != ' ' && *cp != '\t') - cp++; - *cp = '\0'; - *pp++ = 0; - havesearch = 1; - continue; - } - /* read nameservers to query */ - if (MATCH(buf, "nameserver") && nserv < MAXNS) { - struct in_addr a; - - cp = buf + sizeof("nameserver") - 1; - while (*cp == ' ' || *cp == '\t') - cp++; - if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { - _res.nsaddr_list[nserv].sin_addr = a; - _res.nsaddr_list[nserv].sin_family = AF_INET; - _res.nsaddr_list[nserv].sin_port = - htons(NAMESERVER_PORT); - nserv++; - } - continue; - } -#ifdef RESOLVSORT - if (MATCH(buf, "sortlist")) { - struct in_addr a; - - cp = buf + sizeof("sortlist") - 1; - while (nsort < MAXRESOLVSORT) { - while (*cp == ' ' || *cp == '\t') - cp++; - if (*cp == '\0' || *cp == '\n' || *cp == ';') - break; - net = cp; - while (*cp && !ISSORTMASK(*cp) && *cp != ';' && - isascii(*cp) && !isspace(*cp)) - cp++; - n = *cp; - *cp = 0; - if (inet_aton(net, &a)) { - _res.sort_list[nsort].addr = a; - if (ISSORTMASK(n)) { - *cp++ = n; - net = cp; - while (*cp && *cp != ';' && - isascii(*cp) && !isspace(*cp)) - cp++; - n = *cp; - *cp = 0; - if (inet_aton(net, &a)) { - _res.sort_list[nsort].mask = a.s_addr; - } else { - _res.sort_list[nsort].mask = - net_mask(_res.sort_list[nsort].addr); - } - } else { - _res.sort_list[nsort].mask = - net_mask(_res.sort_list[nsort].addr); - } - nsort++; - } - *cp = n; - } - continue; - } -#endif - if (MATCH(buf, "options")) { - res_setoptions(buf + sizeof("options") - 1, "conf"); - continue; - } - } - if (nserv > 1) - _res.nscount = nserv; -#ifdef RESOLVSORT - _res.nsort = nsort; -#endif - (void) fclose(fp); - } - if (_res.defdname[0] == 0 && - gethostname(buf, sizeof(_res.defdname) - 1) == 0 && - (cp = strchr(buf, '.')) != NULL) - strcpy(_res.defdname, cp + 1); - - /* find components of local domain that might be searched */ - if (havesearch == 0) { - pp = _res.dnsrch; - *pp++ = _res.defdname; - *pp = NULL; - -#ifndef RFC1535 - dots = 0; - for (cp = _res.defdname; *cp; cp++) - dots += (*cp == '.'); - - cp = _res.defdname; - while (pp < _res.dnsrch + MAXDFLSRCH) { - if (dots < LOCALDOMAINPARTS) - break; - cp = strchr(cp, '.') + 1; /* we know there is one */ - *pp++ = cp; - dots--; - } - *pp = NULL; -#ifdef DEBUG - if (_res.options & RES_DEBUG) { - printf(";; res_init()... default dnsrch list:\n"); - for (pp = _res.dnsrch; *pp; pp++) - printf(";;\t%s\n", *pp); - printf(";;\t..END..\n"); - } -#endif /* DEBUG */ -#endif /* !RFC1535 */ - } - - if ((cp = getenv("RES_OPTIONS")) != NULL) - res_setoptions(cp, "env"); - _res.options |= RES_INIT; - return (0); -} - -static void -res_setoptions(options, source) - char *options, *source; -{ - char *cp = options; - int i; - -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf(";; res_setoptions(\"%s\", \"%s\")...\n", - options, source); -#endif - while (*cp) { - /* skip leading and inner runs of spaces */ - while (*cp == ' ' || *cp == '\t') - cp++; - /* search for and process individual options */ - if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) { - i = atoi(cp + sizeof("ndots:") - 1); - if (i <= RES_MAXNDOTS) - _res.ndots = i; - else - _res.ndots = RES_MAXNDOTS; -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf(";;\tndots=%d\n", _res.ndots); -#endif - } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { -#ifdef DEBUG - if (!(_res.options & RES_DEBUG)) { - printf(";; res_setoptions(\"%s\", \"%s\")..\n", - options, source); - _res.options |= RES_DEBUG; - } - printf(";;\tdebug\n"); -#endif - } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { - _res.options |= RES_USE_INET6; - } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1)) { - _res.options |= RES_NOTLDQUERY; - } else { - /* XXX - print a warning here? */ - } - /* skip to next run of spaces */ - while (*cp && *cp != ' ' && *cp != '\t') - cp++; - } -} - -#ifdef RESOLVSORT -/* XXX - should really support CIDR which means explicit masks always. */ -static u_int32_t -net_mask(in) /* XXX - should really use system's version of this */ - struct in_addr in; -{ - register u_int32_t i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return (htonl(IN_CLASSA_NET)); - else if (IN_CLASSB(i)) - return (htonl(IN_CLASSB_NET)); - return (htonl(IN_CLASSC_NET)); -} -#endif - -u_int -res_randomid() -{ - struct timeval now; - - gettimeofday(&now, NULL); - return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid())); -} diff --git a/lib/libc/net/res_mkquery.c b/lib/libc/net/res_mkquery.c deleted file mode 100644 index cfc9d33..0000000 --- a/lib/libc/net/res_mkquery.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * ++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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; -static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp "; -static char rcsid[] = "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/param.h> -#include <netinet/in.h> - -#include "res_config.h" -#include <arpa/nameser.h> - -#include <stdio.h> -#include <netdb.h> -#include <resolv.h> -#include <string.h> - - -/* - * Form all types of queries. - * Returns the size of the result or -1. - */ -int -res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) - int op; /* opcode of query */ - const char *dname; /* domain name */ - int class, type; /* class and type of query */ - const u_char *data; /* resource record data */ - int datalen; /* length of data */ - const u_char *newrr_in; /* new rr for modify or append */ - u_char *buf; /* buffer to put query */ - int buflen; /* size of buffer */ -{ - register HEADER *hp; - register u_char *cp; - register int n; - u_char *dnptrs[20], **dpp, **lastdnptr; - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (-1); - } -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf(";; res_mkquery(%d, %s, %d, %d)\n", - op, dname, class, type); -#endif - /* - * Initialize header fields. - */ - if ((buf == NULL) || (buflen < HFIXEDSZ)) - return (-1); - bzero(buf, HFIXEDSZ); - hp = (HEADER *) buf; - hp->id = htons(++_res.id); - hp->opcode = op; - hp->rd = (_res.options & RES_RECURSE) != 0; - hp->rcode = NOERROR; - cp = buf + HFIXEDSZ; - buflen -= HFIXEDSZ; - dpp = dnptrs; - *dpp++ = buf; - *dpp++ = NULL; - lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0]; - /* - * perform opcode specific processing - */ - switch (op) { - case QUERY: /*FALLTHROUGH*/ - case NS_NOTIFY_OP: - if ((buflen -= QFIXEDSZ) < 0) - return (-1); - if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) - return (-1); - cp += n; - buflen -= n; - __putshort(type, cp); - cp += INT16SZ; - __putshort(class, cp); - cp += INT16SZ; - hp->qdcount = htons(1); - if (op == QUERY || data == NULL) - break; - /* - * Make an additional record for completion domain. - */ - buflen -= RRFIXEDSZ; - n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr); - if (n < 0) - return (-1); - cp += n; - buflen -= n; - __putshort(T_NULL, cp); - cp += INT16SZ; - __putshort(class, cp); - cp += INT16SZ; - __putlong(0, cp); - cp += INT32SZ; - __putshort(0, cp); - cp += INT16SZ; - hp->arcount = htons(1); - break; - - case IQUERY: - /* - * Initialize answer section - */ - if (buflen < 1 + RRFIXEDSZ + datalen) - return (-1); - *cp++ = '\0'; /* no domain name */ - __putshort(type, cp); - cp += INT16SZ; - __putshort(class, cp); - cp += INT16SZ; - __putlong(0, cp); - cp += INT32SZ; - __putshort(datalen, cp); - cp += INT16SZ; - if (datalen) { - bcopy(data, cp, datalen); - cp += datalen; - } - hp->ancount = htons(1); - break; - - default: - return (-1); - } - return (cp - buf); -} diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c deleted file mode 100644 index 3716e63..0000000 --- a/lib/libc/net/res_query.c +++ /dev/null @@ -1,401 +0,0 @@ -/* - * ++Copyright++ 1988, 1993 - * - - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; -static char orig_rcsid = "From: Id: res_query.c,v 8.10 1997/06/01 20:34:37 vixie Exp"; -static char rcsid[] = "$Id: res_query.c,v 1.14 1997/06/27 08:22:03 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/param.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#include "res_config.h" -#include <arpa/nameser.h> - -#include <stdio.h> -#include <netdb.h> -#include <resolv.h> -#include <ctype.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> - -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif - -const char *hostalias __P((const char *)); -int h_errno; - -/* - * Formulate a normal query, send, and await answer. - * Returned answer is placed in supplied buffer "answer". - * Perform preliminary check of answer, returning success only - * if no error is indicated and the answer count is nonzero. - * Return the size of the response on success, -1 on error. - * Error number is left in h_errno. - * - * Caller must parse answer and determine whether it answers the question. - */ -int -res_query(name, class, type, answer, anslen) - const char *name; /* domain name */ - int class, type; /* class and type of query */ - u_char *answer; /* buffer to put answer */ - int anslen; /* size of answer buffer */ -{ - u_char buf[MAXPACKET]; - register HEADER *hp = (HEADER *) answer; - int n; - - hp->rcode = NOERROR; /* default */ - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (-1); - } -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf(";; res_query(%s, %d, %d)\n", name, class, type); -#endif - - n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, - buf, sizeof(buf)); - if (n <= 0) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf(";; res_query: mkquery failed\n"); -#endif - h_errno = NO_RECOVERY; - return (n); - } - n = res_send(buf, n, answer, anslen); - if (n < 0) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf(";; res_query: send error\n"); -#endif - h_errno = TRY_AGAIN; - return (n); - } - - if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf(";; rcode = %d, ancount=%d\n", hp->rcode, - ntohs(hp->ancount)); -#endif - switch (hp->rcode) { - case NXDOMAIN: - h_errno = HOST_NOT_FOUND; - break; - case SERVFAIL: - h_errno = TRY_AGAIN; - break; - case NOERROR: - h_errno = NO_DATA; - break; - case FORMERR: - case NOTIMP: - case REFUSED: - default: - h_errno = NO_RECOVERY; - break; - } - return (-1); - } - return (n); -} - -/* - * Formulate a normal query, send, and retrieve answer in supplied buffer. - * Return the size of the response on success, -1 on error. - * If enabled, implement search rules until answer or unrecoverable failure - * is detected. Error code, if any, is left in h_errno. - */ -int -res_search(name, class, type, answer, anslen) - const char *name; /* domain name */ - int class, type; /* class and type of query */ - u_char *answer; /* buffer to put answer */ - int anslen; /* size of answer */ -{ - register const char *cp, * const *domain; - HEADER *hp = (HEADER *) answer; - u_int dots; - int trailing_dot, ret, saved_herrno; - int got_nodata = 0, got_servfail = 0, tried_as_is = 0; - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (-1); - } - errno = 0; - h_errno = HOST_NOT_FOUND; /* default, if we never query */ - dots = 0; - for (cp = name; *cp; cp++) - dots += (*cp == '.'); - trailing_dot = 0; - if (cp > name && *--cp == '.') - trailing_dot++; - - /* - * if there aren't any dots, it could be a user-level alias - */ - if (!dots && (cp = __hostalias(name)) != NULL) - return (res_query(cp, class, type, answer, anslen)); - - /* - * If there are dots in the name already, let's just give it a try - * 'as is'. The threshold can be set with the "ndots" option. - */ - saved_herrno = -1; - if (dots >= _res.ndots) { - ret = res_querydomain(name, NULL, class, type, answer, anslen); - if (ret > 0) - return (ret); - saved_herrno = h_errno; - tried_as_is++; - } - - /* - * We do at least one level of search if - * - there is no dot and RES_DEFNAME is set, or - * - there is at least one dot, there is no trailing dot, - * and RES_DNSRCH is set. - */ - if ((!dots && (_res.options & RES_DEFNAMES)) || - (dots && !trailing_dot && (_res.options & RES_DNSRCH))) { - int done = 0; - - for (domain = (const char * const *)_res.dnsrch; - *domain && !done; - domain++) { - - ret = res_querydomain(name, *domain, class, type, - answer, anslen); - if (ret > 0) - return (ret); - - /* - * If no server present, give up. - * If name isn't found in this domain, - * keep trying higher domains in the search list - * (if that's enabled). - * On a NO_DATA error, keep trying, otherwise - * a wildcard entry of another type could keep us - * from finding this entry higher in the domain. - * If we get some other error (negative answer or - * server failure), then stop searching up, - * but try the input name below in case it's - * fully-qualified. - */ - if (errno == ECONNREFUSED) { - h_errno = TRY_AGAIN; - return (-1); - } - - switch (h_errno) { - case NO_DATA: - got_nodata++; - /* FALLTHROUGH */ - case HOST_NOT_FOUND: - /* keep trying */ - break; - case TRY_AGAIN: - if (hp->rcode == SERVFAIL) { - /* try next search element, if any */ - got_servfail++; - break; - } - /* FALLTHROUGH */ - default: - /* anything else implies that we're done */ - done++; - } - - /* if we got here for some reason other than DNSRCH, - * we only wanted one iteration of the loop, so stop. - */ - if (!(_res.options & RES_DNSRCH)) - done++; - } - } - - /* if we have not already tried the name "as is", do that now. - * note that we do this regardless of how many dots were in the - * name or whether it ends with a dot unless NOTLDQUERY is set. - */ - if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) { - ret = res_querydomain(name, NULL, class, type, answer, anslen); - if (ret > 0) - return (ret); - } - - /* if we got here, we didn't satisfy the search. - * if we did an initial full query, return that query's h_errno - * (note that we wouldn't be here if that query had succeeded). - * else if we ever got a nodata, send that back as the reason. - * else send back meaningless h_errno, that being the one from - * the last DNSRCH we did. - */ - if (saved_herrno != -1) - h_errno = saved_herrno; - else if (got_nodata) - h_errno = NO_DATA; - else if (got_servfail) - h_errno = TRY_AGAIN; - return (-1); -} - -/* - * Perform a call on res_query on the concatenation of name and domain, - * removing a trailing dot from name if domain is NULL. - */ -int -res_querydomain(name, domain, class, type, answer, anslen) - const char *name, *domain; - int class, type; /* class and type of query */ - u_char *answer; /* buffer to put answer */ - int anslen; /* size of answer */ -{ - char nbuf[MAXDNAME]; - const char *longname = nbuf; - int n, d; - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (-1); - } -#ifdef DEBUG - if (_res.options & RES_DEBUG) - printf(";; res_querydomain(%s, %s, %d, %d)\n", - name, domain?domain:"<Nil>", class, type); -#endif - if (domain == NULL) { - /* - * Check for trailing '.'; - * copy without '.' if present. - */ - n = strlen(name); - if (n >= MAXDNAME) { - h_errno = NO_RECOVERY; - return (-1); - } - n--; - if (n >= 0 && name[n] == '.') { - strncpy(nbuf, name, n); - nbuf[n] = '\0'; - } else - longname = name; - } else { - n = strlen(name); - d = strlen(domain); - if (n + d + 1 >= MAXDNAME) { - h_errno = NO_RECOVERY; - return (-1); - } - sprintf(nbuf, "%s.%s", name, domain); - } - return (res_query(longname, class, type, answer, anslen)); -} - -const char * -hostalias(name) - register const char *name; -{ - register char *cp1, *cp2; - FILE *fp; - char *file; - char buf[BUFSIZ]; - static char abuf[MAXDNAME]; - - if (_res.options & RES_NOALIASES) - return (NULL); - /* XXX issetguid() would be better here, but we don't have that. */ - if (getuid() != geteuid() || getgid() != getegid()) - return (NULL); - file = getenv("HOSTALIASES"); - if (file == NULL || (fp = fopen(file, "r")) == NULL) - return (NULL); - setbuf(fp, NULL); - buf[sizeof(buf) - 1] = '\0'; - while (fgets(buf, sizeof(buf), fp)) { - for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1) - ; - if (!*cp1) - break; - *cp1 = '\0'; - if (!strcasecmp(buf, name)) { - while (isspace(*++cp1)) - ; - if (!*cp1) - break; - for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2) - ; - abuf[sizeof(abuf) - 1] = *cp2 = '\0'; - strncpy(abuf, cp1, sizeof(abuf) - 1); - fclose(fp); - return (abuf); - } - } - fclose(fp); - return (NULL); -} diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c deleted file mode 100644 index 70a5c17..0000000 --- a/lib/libc/net/res_send.c +++ /dev/null @@ -1,810 +0,0 @@ -/* - * ++Copyright++ 1985, 1989, 1993 - * - - * Copyright (c) 1985, 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; -static char orig_rcsid[] = "From: Id: res_send.c,v 8.13 1997/06/01 20:34:37 vixie Exp"; -static char rcsid[] = "$Id: res_send.c,v 1.19 1997/09/14 09:44:34 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -/* - * Send query to name server and wait for reply. - */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <sys/uio.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -#include "res_config.h" -#include <arpa/nameser.h> - -#include <stdio.h> -#include <netdb.h> -#include <errno.h> -#include <resolv.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <poll.h> - -static int use_poll = 1; /* adapt to poll() syscall availability */ - /* 0 = not present, 1 = try it, 2 = exists */ - -static int s = -1; /* socket used for communications */ -static int connected = 0; /* is the socket connected */ -static int vc = 0; /* is the socket a virtual ciruit? */ - -#define CAN_RECONNECT 1 - -#ifndef DEBUG -# define Dprint(cond, args) /*empty*/ -# define DprintQ(cond, args, query, size) /*empty*/ -# define Aerror(file, string, error, address) /*empty*/ -# define Perror(file, string, error) /*empty*/ -#else -# define Dprint(cond, args) if (cond) {fprintf args;} else {} -# define DprintQ(cond, args, query, size) if (cond) {\ - fprintf args;\ - __fp_nquery(query, size, stdout);\ - } else {} - static void - Aerror(file, string, error, address) - FILE *file; - char *string; - int error; - struct sockaddr_in address; - { - int save = errno; - - if (_res.options & RES_DEBUG) { - fprintf(file, "res_send: %s ([%s].%u): %s\n", - string, - inet_ntoa(address.sin_addr), - ntohs(address.sin_port), - strerror(error)); - } - errno = save; - } - static void - Perror(file, string, error) - FILE *file; - char *string; - int error; - { - int save = errno; - - if (_res.options & RES_DEBUG) { - fprintf(file, "res_send: %s: %s\n", - string, strerror(error)); - } - errno = save; - } -#endif - -static res_send_qhook Qhook = NULL; -static res_send_rhook Rhook = NULL; - -void -res_send_setqhook(hook) - res_send_qhook hook; -{ - - Qhook = hook; -} - -void -res_send_setrhook(hook) - res_send_rhook hook; -{ - - Rhook = hook; -} - -/* int - * res_isourserver(ina) - * looks up "ina" in _res.ns_addr_list[] - * returns: - * 0 : not found - * >0 : found - * author: - * paul vixie, 29may94 - */ -int -res_isourserver(inp) - const struct sockaddr_in *inp; -{ - struct sockaddr_in ina; - register int ns, ret; - - ina = *inp; - ret = 0; - for (ns = 0; ns < _res.nscount; ns++) { - register const struct sockaddr_in *srv = &_res.nsaddr_list[ns]; - - if (srv->sin_family == ina.sin_family && - srv->sin_port == ina.sin_port && - (srv->sin_addr.s_addr == INADDR_ANY || - srv->sin_addr.s_addr == ina.sin_addr.s_addr)) { - ret++; - break; - } - } - return (ret); -} - -/* int - * res_nameinquery(name, type, class, buf, eom) - * look for (name,type,class) in the query section of packet (buf,eom) - * returns: - * -1 : format error - * 0 : not found - * >0 : found - * author: - * paul vixie, 29may94 - */ -int -res_nameinquery(name, type, class, buf, eom) - const char *name; - register int type, class; - const u_char *buf, *eom; -{ - register const u_char *cp = buf + HFIXEDSZ; - int qdcount = ntohs(((HEADER*)buf)->qdcount); - - while (qdcount-- > 0) { - char tname[MAXDNAME+1]; - register int n, ttype, tclass; - - n = dn_expand(buf, eom, cp, tname, sizeof tname); - if (n < 0) - return (-1); - cp += n; - ttype = _getshort(cp); cp += INT16SZ; - tclass = _getshort(cp); cp += INT16SZ; - if (ttype == type && - tclass == class && - strcasecmp(tname, name) == 0) - return (1); - } - return (0); -} - -/* int - * res_queriesmatch(buf1, eom1, buf2, eom2) - * is there a 1:1 mapping of (name,type,class) - * in (buf1,eom1) and (buf2,eom2)? - * returns: - * -1 : format error - * 0 : not a 1:1 mapping - * >0 : is a 1:1 mapping - * author: - * paul vixie, 29may94 - */ -int -res_queriesmatch(buf1, eom1, buf2, eom2) - const u_char *buf1, *eom1; - const u_char *buf2, *eom2; -{ - register const u_char *cp = buf1 + HFIXEDSZ; - int qdcount = ntohs(((HEADER*)buf1)->qdcount); - - if (qdcount != ntohs(((HEADER*)buf2)->qdcount)) - return (0); - while (qdcount-- > 0) { - char tname[MAXDNAME+1]; - register int n, ttype, tclass; - - n = dn_expand(buf1, eom1, cp, tname, sizeof tname); - if (n < 0) - return (-1); - cp += n; - ttype = _getshort(cp); cp += INT16SZ; - tclass = _getshort(cp); cp += INT16SZ; - if (!res_nameinquery(tname, ttype, tclass, buf2, eom2)) - return (0); - } - return (1); -} - -int -res_send(buf, buflen, ans, anssiz) - const u_char *buf; - int buflen; - u_char *ans; - int anssiz; -{ - HEADER *hp = (HEADER *) buf; - HEADER *anhp = (HEADER *) ans; - int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns; - register int n; - u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ - - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - /* errno should have been set by res_init() in this case. */ - return (-1); - } - DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY), - (stdout, ";; res_send()\n"), buf, buflen); - v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ; - gotsomewhere = 0; - connreset = 0; - terrno = ETIMEDOUT; - badns = 0; - - /* - * Send request, RETRY times, or until successful - */ - for (try = 0; try < _res.retry; try++) { - for (ns = 0; ns < _res.nscount; ns++) { - struct sockaddr_in *nsap = &_res.nsaddr_list[ns]; - same_ns: - if (badns & (1 << ns)) { - res_close(); - goto next_ns; - } - - if (Qhook) { - int done = 0, loops = 0; - - do { - res_sendhookact act; - - act = (*Qhook)(&nsap, &buf, &buflen, - ans, anssiz, &resplen); - switch (act) { - case res_goahead: - done = 1; - break; - case res_nextns: - res_close(); - goto next_ns; - case res_done: - return (resplen); - case res_modified: - /* give the hook another try */ - if (++loops < 42) /*doug adams*/ - break; - /*FALLTHROUGH*/ - case res_error: - /*FALLTHROUGH*/ - default: - return (-1); - } - } while (!done); - } - - Dprint(_res.options & RES_DEBUG, - (stdout, ";; Querying server (# %d) address = %s\n", - ns + 1, inet_ntoa(nsap->sin_addr))); - - if (v_circuit) { - int truncated; - struct iovec iov[2]; - u_short len; - u_char *cp; - - /* - * Use virtual circuit; - * at most one attempt per server. - */ - try = _res.retry; - truncated = 0; - if ((s < 0) || (!vc)) { - if (s >= 0) - res_close(); - - s = socket(PF_INET, SOCK_STREAM, 0); - if (s < 0) { - terrno = errno; - Perror(stderr, "socket(vc)", errno); - return (-1); - } - errno = 0; - if (connect(s, (struct sockaddr *)nsap, - sizeof(struct sockaddr)) < 0) { - terrno = errno; - Aerror(stderr, "connect/vc", - errno, *nsap); - badns |= (1 << ns); - res_close(); - goto next_ns; - } - vc = 1; - } - /* - * Send length & message - */ - putshort((u_short)buflen, (u_char*)&len); - iov[0].iov_base = (caddr_t)&len; - iov[0].iov_len = INT16SZ; - iov[1].iov_base = (caddr_t)buf; - iov[1].iov_len = buflen; - if (writev(s, iov, 2) != (INT16SZ + buflen)) { - terrno = errno; - Perror(stderr, "write failed", errno); - badns |= (1 << ns); - res_close(); - goto next_ns; - } - /* - * Receive length & response - */ -read_len: - cp = ans; - len = INT16SZ; - while ((n = read(s, (char *)cp, (int)len)) > 0) { - cp += n; - if ((len -= n) <= 0) - break; - } - if (n <= 0) { - terrno = errno; - Perror(stderr, "read failed", errno); - res_close(); - /* - * A long running process might get its TCP - * connection reset if the remote server was - * restarted. Requery the server instead of - * trying a new one. When there is only one - * server, this means that a query might work - * instead of failing. We only allow one reset - * per query to prevent looping. - */ - if (terrno == ECONNRESET && !connreset) { - connreset = 1; - res_close(); - goto same_ns; - } - res_close(); - goto next_ns; - } - resplen = _getshort(ans); - if (resplen > anssiz) { - Dprint(_res.options & RES_DEBUG, - (stdout, ";; response truncated\n") - ); - truncated = 1; - len = anssiz; - } else - len = resplen; - cp = ans; - while (len != 0 && - (n = read(s, (char *)cp, (int)len)) > 0) { - cp += n; - len -= n; - } - if (n <= 0) { - terrno = errno; - Perror(stderr, "read(vc)", errno); - res_close(); - goto next_ns; - } - if (truncated) { - /* - * Flush rest of answer - * so connection stays in synch. - */ - anhp->tc = 1; - len = resplen - anssiz; - while (len != 0) { - char junk[PACKETSZ]; - - n = (len > sizeof(junk) - ? sizeof(junk) - : len); - if ((n = read(s, junk, n)) > 0) - len -= n; - else - break; - } - } - /* - * The calling applicating has bailed out of - * a previous call and failed to arrange to have - * the circuit closed or the server has got - * itself confused. Anyway drop the packet and - * wait for the correct one. - */ - if (hp->id != anhp->id) { - DprintQ((_res.options & RES_DEBUG) || - (_res.pfcode & RES_PRF_REPLY), - (stdout, ";; old answer (unexpected):\n"), - ans, (resplen>anssiz)?anssiz:resplen); - goto read_len; - } - } else { - /* - * Use datagrams. - */ - struct pollfd pfd; - int msec; - struct timeval timeout; - fd_set dsmask, *dsmaskp; - int dsmasklen; - struct sockaddr_in from; - int fromlen; - - if ((s < 0) || vc) { - if (vc) - res_close(); - s = socket(PF_INET, SOCK_DGRAM, 0); - if (s < 0) { -#if !CAN_RECONNECT - bad_dg_sock: -#endif - terrno = errno; - Perror(stderr, "socket(dg)", errno); - return (-1); - } - connected = 0; - } - /* - * On a 4.3BSD+ machine (client and server, - * actually), sending to a nameserver datagram - * port with no nameserver will cause an - * ICMP port unreachable message to be returned. - * If our datagram socket is "connected" to the - * server, we get an ECONNREFUSED error on the next - * socket operation, and select returns if the - * error message is received. We can thus detect - * the absence of a nameserver without timing out. - * If we have sent queries to at least two servers, - * however, we don't want to remain connected, - * as we wish to receive answers from the first - * server to respond. - */ - if (_res.nscount == 1 || (try == 0 && ns == 0)) { - /* - * Connect only if we are sure we won't - * receive a response from another server. - */ - if (!connected) { - if (connect(s, (struct sockaddr *)nsap, - sizeof(struct sockaddr) - ) < 0) { - Aerror(stderr, - "connect(dg)", - errno, *nsap); - badns |= (1 << ns); - res_close(); - goto next_ns; - } - connected = 1; - } - if (send(s, (char*)buf, buflen, 0) != buflen) { - Perror(stderr, "send", errno); - badns |= (1 << ns); - res_close(); - goto next_ns; - } - } else { - /* - * Disconnect if we want to listen - * for responses from more than one server. - */ - if (connected) { -#if CAN_RECONNECT - struct sockaddr_in no_addr; - - no_addr.sin_family = AF_INET; - no_addr.sin_addr.s_addr = INADDR_ANY; - no_addr.sin_port = 0; - (void) connect(s, - (struct sockaddr *) - &no_addr, - sizeof(no_addr)); -#else - int s1 = socket(PF_INET, SOCK_DGRAM,0); - if (s1 < 0) - goto bad_dg_sock; - (void) dup2(s1, s); - (void) close(s1); - Dprint(_res.options & RES_DEBUG, - (stdout, ";; new DG socket\n")) -#endif - connected = 0; - errno = 0; - } - if (sendto(s, (char*)buf, buflen, 0, - (struct sockaddr *)nsap, - sizeof(struct sockaddr)) - != buflen) { - Aerror(stderr, "sendto", errno, *nsap); - badns |= (1 << ns); - res_close(); - goto next_ns; - } - } - - /* - * Wait for reply - */ - othersyscall: - if (use_poll) { - msec = (_res.retrans << try) * 1000; - if (try > 0) - msec /= _res.nscount; - if (msec <= 0) - msec = 1000; - } else { - timeout.tv_sec = (_res.retrans << try); - if (try > 0) - timeout.tv_sec /= _res.nscount; - if ((long) timeout.tv_sec <= 0) - timeout.tv_sec = 1; - } - wait: - if (use_poll) { - struct sigaction sa, osa; - int sigsys_installed = 0; - - pfd.fd = s; - pfd.events = POLLIN; - if (use_poll == 1) { - bzero(&sa, sizeof(sa)); - sa.sa_handler = SIG_IGN; - if (sigaction(SIGSYS, &sa, &osa) >= 0) - sigsys_installed = 1; - } - n = poll(&pfd, 1, msec); - if (sigsys_installed == 1) { - int oerrno = errno; - sigaction(SIGSYS, &osa, NULL); - errno = oerrno; - } - /* XXX why does nosys() return EINVAL? */ - if (n < 0 && (errno == ENOSYS || - errno == EINVAL)) { - use_poll = 0; - goto othersyscall; - } else if (use_poll == 1) - use_poll = 2; - if (n < 0) { - if (errno == EINTR) - goto wait; - Perror(stderr, "poll", errno); - res_close(); - goto next_ns; - } - } else { - dsmasklen = howmany(s + 1, NFDBITS) * - sizeof(fd_mask); - if (dsmasklen > sizeof(fd_set)) { - dsmaskp = (fd_set *)malloc(dsmasklen); - if (dsmaskp == NULL) { - res_close(); - goto next_ns; - } - } else - dsmaskp = &dsmask; - /* only zero what we need */ - bzero((char *)dsmaskp, dsmasklen); - FD_SET(s, dsmaskp); - n = select(s + 1, dsmaskp, (fd_set *)NULL, - (fd_set *)NULL, &timeout); - if (dsmaskp != &dsmask) - free(dsmaskp); - } - - if (n == 0) { - /* - * timeout - */ - Dprint(_res.options & RES_DEBUG, - (stdout, ";; timeout\n")); - gotsomewhere = 1; - res_close(); - goto next_ns; - } - errno = 0; - fromlen = sizeof(struct sockaddr_in); - resplen = recvfrom(s, (char*)ans, anssiz, 0, - (struct sockaddr *)&from, &fromlen); - if (resplen <= 0) { - Perror(stderr, "recvfrom", errno); - res_close(); - goto next_ns; - } - gotsomewhere = 1; - if (hp->id != anhp->id) { - /* - * response from old query, ignore it. - * XXX - potential security hazard could - * be detected here. - */ - DprintQ((_res.options & RES_DEBUG) || - (_res.pfcode & RES_PRF_REPLY), - (stdout, ";; old answer:\n"), - ans, (resplen>anssiz)?anssiz:resplen); - goto wait; - } -#if CHECK_SRVR_ADDR - if (!(_res.options & RES_INSECURE1) && - !res_isourserver(&from)) { - /* - * response from wrong server? ignore it. - * XXX - potential security hazard could - * be detected here. - */ - DprintQ((_res.options & RES_DEBUG) || - (_res.pfcode & RES_PRF_REPLY), - (stdout, ";; not our server:\n"), - ans, (resplen>anssiz)?anssiz:resplen); - goto wait; - } -#endif - if (!(_res.options & RES_INSECURE2) && - !res_queriesmatch(buf, buf + buflen, - ans, ans + anssiz)) { - /* - * response contains wrong query? ignore it. - * XXX - potential security hazard could - * be detected here. - */ - DprintQ((_res.options & RES_DEBUG) || - (_res.pfcode & RES_PRF_REPLY), - (stdout, ";; wrong query name:\n"), - ans, (resplen>anssiz)?anssiz:resplen); - goto wait; - } - if (anhp->rcode == SERVFAIL || - anhp->rcode == NOTIMP || - anhp->rcode == REFUSED) { - DprintQ(_res.options & RES_DEBUG, - (stdout, "server rejected query:\n"), - ans, (resplen>anssiz)?anssiz:resplen); - badns |= (1 << ns); - res_close(); - /* don't retry if called from dig */ - if (!_res.pfcode) - goto next_ns; - } - if (!(_res.options & RES_IGNTC) && anhp->tc) { - /* - * get rest of answer; - * use TCP with same server. - */ - Dprint(_res.options & RES_DEBUG, - (stdout, ";; truncated answer\n")); - v_circuit = 1; - res_close(); - goto same_ns; - } - } /*if vc/dg*/ - Dprint((_res.options & RES_DEBUG) || - ((_res.pfcode & RES_PRF_REPLY) && - (_res.pfcode & RES_PRF_HEAD1)), - (stdout, ";; got answer:\n")); - DprintQ((_res.options & RES_DEBUG) || - (_res.pfcode & RES_PRF_REPLY), - (stdout, ""), - ans, (resplen>anssiz)?anssiz:resplen); - /* - * If using virtual circuits, we assume that the first server - * is preferred over the rest (i.e. it is on the local - * machine) and only keep that one open. - * If we have temporarily opened a virtual circuit, - * or if we haven't been asked to keep a socket open, - * close the socket. - */ - if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) || - !(_res.options & RES_STAYOPEN)) { - res_close(); - } - if (Rhook) { - int done = 0, loops = 0; - - do { - res_sendhookact act; - - act = (*Rhook)(nsap, buf, buflen, - ans, anssiz, &resplen); - switch (act) { - case res_goahead: - case res_done: - done = 1; - break; - case res_nextns: - res_close(); - goto next_ns; - case res_modified: - /* give the hook another try */ - if (++loops < 42) /*doug adams*/ - break; - /*FALLTHROUGH*/ - case res_error: - /*FALLTHROUGH*/ - default: - return (-1); - } - } while (!done); - - } - return (resplen); - next_ns: ; - } /*foreach ns*/ - } /*foreach retry*/ - res_close(); - if (!v_circuit) - if (!gotsomewhere) - errno = ECONNREFUSED; /* no nameservers found */ - else - errno = ETIMEDOUT; /* no answer obtained */ - else - errno = terrno; - return (-1); -} - -/* - * This routine is for closing the socket if a virtual circuit is used and - * the program wants to close it. This provides support for endhostent() - * which expects to close the socket. - * - * This routine is not expected to be user visible. - */ -void -res_close() -{ - if (s >= 0) { - (void) close(s); - s = -1; - connected = 0; - vc = 0; - } -} diff --git a/lib/libc/net/res_stubs.c b/lib/libc/net/res_stubs.c deleted file mode 100644 index e156608..0000000 --- a/lib/libc/net/res_stubs.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 1996 Peter Wemm <peter@freebsd.org>. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - * - * $Id: res_stubs.c,v 1.5 1997/02/22 15:00:36 peter Exp $ - */ - -/* - * This file is for FreeBSD-3.0 that has a bind-4.9.5-P1 derived - * resolver in the libc. It provides aliases for functions that - * have moved since 4.9.4-P1. - * - * I'll save everybody the trouble and say it now: *THIS IS A HACK*! - * - * Yes, many of these are private functions to the resolver, but some are - * needed as there is no other way to provide the functionality and they've - * turned up all over the place. :-( - */ - -#include <sys/types.h> -#include <sys/cdefs.h> - -__weak_reference(__sym_ston, sym_ston); -__weak_reference(__sym_ntos, sym_ntos); -__weak_reference(__sym_ntop, sym_ntop); -__weak_reference(__fp_resstat, fp_resstat); -__weak_reference(__p_query, p_query); -__weak_reference(__p_fqnname, p_fqnname); -__weak_reference(__p_secstodate, p_secstodate); -__weak_reference(__dn_count_labels, dn_count_labels); -__weak_reference(__dn_comp, dn_comp); -__weak_reference(__res_close, _res_close); -#ifdef BIND_RES_POSIX3 -__weak_reference(__dn_expand, dn_expand); -__weak_reference(__res_init, res_init); -__weak_reference(__res_query, res_query); -__weak_reference(__res_search, res_search); -__weak_reference(__res_querydomain, res_querydomain); -__weak_reference(__res_mkquery, res_mkquery); -__weak_reference(__res_send, res_send); -#else -__weak_reference(res_send, __res_send); -#endif diff --git a/lib/libc/net/resolver.3 b/lib/libc/net/resolver.3 deleted file mode 100644 index 6d210c3..0000000 --- a/lib/libc/net/resolver.3 +++ /dev/null @@ -1,351 +0,0 @@ -.\" Copyright (c) 1985, 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. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)resolver.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt RESOLVER 3 -.Os BSD 4.3 -.Sh NAME -.Nm res_query , -.Nm res_search , -.Nm res_mkquery , -.Nm res_send , -.Nm res_init , -.Nm dn_comp , -.Nm dn_expand -.Nd resolver routines -.Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <netinet/in.h> -.Fd #include <arpa/nameser.h> -.Fd #include <resolv.h> -.Ft int -.Fo res_query -.Fa "const char *dname" -.Fa "int class" -.Fa "int type" -.Fa "u_char *answer" -.Fa "int anslen" -.Fc -.Ft int -.Fo res_search -.Fa "const char *dname" -.Fa "int class" -.Fa "int type" -.Fa "u_char *answer" -.Fa "int anslen" -.Fc -.Ft int -.Fo res_mkquery -.Fa "int op" -.Fa "const char *dname" -.Fa "int class" -.Fa "int type" -.Fa "const u_char *data" -.Fa "int datalen" -.Fa "const u_char *newrr_in" -.Fa "u_char *buf" -.Fa "int buflen" -.Fc -.Ft int -.Fo res_send -.Fa "const char *msg" -.Fa "int msglen" -.Fa "char *answer" -.Fa "int anslen" -.Fc -.Ft int -.Fn res_init -.Fo dn_comp -.Fa "const char *exp_dn" -.Fa "char *comp_dn" -.Fa "int length" -.Fa "char **dnptrs" -.Fa "char **lastdnptr" -.Fc -.Ft int -.Fo dn_expand -.Fa "const u_char *msg" -.Fa "const u_char *eomorig" -.Fa "const u_char *comp_dn" -.Fa "char *exp_dn" -.Fa "int length" -.Fc -.Sh DESCRIPTION -These routines are used for making, sending and interpreting -query and reply messages with Internet domain name servers. -.Pp -Global configuration and state information that is used by the -resolver routines is kept in the structure -.Em _res . -Most of the values have reasonable defaults and can be ignored. -Options -stored in -.Em _res.options -are defined in -.Pa resolv.h -and are as follows. -Options are stored as a simple bit mask containing the bitwise ``or'' -of the options enabled. -.Bl -tag -width RES_DEFNAMES -.It Dv RES_INIT -True if the initial name server address and default domain name are -initialized (i.e., -.Fn res_init -has been called). -.It Dv RES_DEBUG -Print debugging messages. -.It Dv RES_AAONLY -Accept authoritative answers only. -With this option, -.Fn res_send -should continue until it finds an authoritative answer or finds an error. -Currently this is not implemented. -.It Dv RES_USEVC -Use -.Tn TCP -connections for queries instead of -.Tn UDP -datagrams. -.It Dv RES_STAYOPEN -Used with -.Dv RES_USEVC -to keep the -.Tn TCP -connection open between -queries. -This is useful only in programs that regularly do many queries. -.Tn UDP -should be the normal mode used. -.It Dv RES_IGNTC -Unused currently (ignore truncation errors, i.e., don't retry with -.Tn TCP ) . -.It Dv RES_RECURSE -Set the recursion-desired bit in queries. -This is the default. -.Pf ( Fn res_send -does not do iterative queries and expects the name server -to handle recursion.) -.It Dv RES_DEFNAMES -If set, -.Fn res_search -will append the default domain name to single-component names -(those that do not contain a dot). -This option is enabled by default. -.It Dv RES_DNSRCH -If this option is set, -.Fn res_search -will search for host names in the current domain and in parent domains; see -.Xr hostname 7 . -This is used by the standard host lookup routine -.Xr gethostbyname 3 . -This option is enabled by default. -.It Dv RES_NOALIASES -This option turns off the user level aliasing feature controlled by the -.Dq Ev HOSTALIASES -environment variable. Network daemons should set this option. -.El -.Pp -The -.Fn res_init -routine -reads the configuration file (if any; see -.Xr resolver 5 ) -to get the default domain name, -search list and -the Internet address of the local name server(s). -If no server is configured, the host running -the resolver is tried. -The current domain name is defined by the hostname -if not specified in the configuration file; -it can be overridden by the environment variable -.Ev LOCALDOMAIN . -This environment variable may contain several blank-separated -tokens if you wish to override the -.Em "search list" -on a per-process basis. This is similar to the -.Em search -command in the configuration file. -Another environment variable ( -.Dq Ev RES_OPTIONS -can be set to -override certain internal resolver options which are otherwise -set by changing fields in the -.Em _res -structure or are inherited from the configuration file's -.Em options -command. The syntax of the -.Dq Ev RES_OPTIONS -environment variable is explained in -.Xr resolver 5 . -Initialization normally occurs on the first call -to one of the following routines. -.Pp -The -.Fn res_query -function provides an interface to the server query mechanism. -It constructs a query, sends it to the local server, -awaits a response, and makes preliminary checks on the reply. -The query requests information of the specified -.Fa type -and -.Fa class -for the specified fully-qualified domain name -.Fa dname . -The reply message is left in the -.Fa answer -buffer with length -.Fa anslen -supplied by the caller. -.Pp -The -.Fn res_search -routine makes a query and awaits a response like -.Fn res_query , -but in addition, it implements the default and search rules -controlled by the -.Dv RES_DEFNAMES -and -.Dv RES_DNSRCH -options. -It returns the first successful reply. -.Pp -The remaining routines are lower-level routines used by -.Fn res_query . -The -.Fn res_mkquery -function -constructs a standard query message and places it in -.Fa buf . -It returns the size of the query, or \-1 if the query is -larger than -.Fa buflen . -The query type -.Fa op -is usually -.Dv QUERY , -but can be any of the query types defined in -.Aq Pa arpa/nameser.h . -The domain name for the query is given by -.Fa dname . -.Fa Newrr -is currently unused but is intended for making update messages. -.Pp -The -.Fn res_send -routine -sends a pre-formatted query and returns an answer. -It will call -.Fn res_init -if -.Dv RES_INIT -is not set, send the query to the local name server, and -handle timeouts and retries. -The length of the reply message is returned, or -\-1 if there were errors. -.Pp -The -.Fn dn_comp -function -compresses the domain name -.Fa exp_dn -and stores it in -.Fa comp_dn . -The size of the compressed name is returned or \-1 if there were errors. -The size of the array pointed to by -.Fa comp_dn -is given by -.Fa length . -The compression uses -an array of pointers -.Fa dnptrs -to previously-compressed names in the current message. -The first pointer points to -to the beginning of the message and the list ends with -.Dv NULL . -The limit to the array is specified by -.Fa lastdnptr . -A side effect of -.Fn dn_comp -is to update the list of pointers for -labels inserted into the message -as the name is compressed. -If -.Em dnptr -is -.Dv NULL, names are not compressed. -If -.Fa lastdnptr -is -.Dv NULL , -the list of labels is not updated. -.Pp -The -.Fn dn_expand -entry -expands the compressed domain name -.Fa comp_dn -to a full domain name -The compressed name is contained in a query or reply message; -.Fa msg -is a pointer to the beginning of the message. -The uncompressed name is placed in the buffer indicated by -.Fa exp_dn -which is of size -.Fa length . -The size of compressed name is returned or \-1 if there was an error. -.Sh FILES -.Bl -tag -width Pa -/etc/resolv.conf -The configuration file -see -.Xr resolver 5 . -.El -.Sh SEE ALSO -.Xr gethostbyname 3 , -.Xr resolver 5 , -.Xr hostname 7 , -.Xr named 8 -.Pp -.%T RFC1032 , -.%T RFC1033 , -.%T RFC1034 , -.%T RFC1035 , -.%T RFC974 -.Rs -.%T "Name Server Operations Guide for BIND" -.Re -.Sh HISTORY -The -.Nm -function appeared in -.Bx 4.3 . diff --git a/lib/libc/net/send.c b/lib/libc/net/send.c deleted file mode 100644 index 81151c4..0000000 --- a/lib/libc/net/send.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)send.c 8.2 (Berkeley) 2/21/94"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/socket.h> - -#include <stddef.h> - -ssize_t -send(s, msg, len, flags) - int s, flags; - size_t len; - const void *msg; -{ - return (sendto(s, msg, len, flags, NULL, 0)); -} |