From 12b71966523767edac25f6eae662fc718114c28b Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Mon, 2 Feb 2009 02:19:33 -0500 Subject: [PATCH] Sync lib/net with FreeBSD: * Add a byteorder.9 manual page. * Remove the addr2ascii and ascii2addr functions. They aren't used in the tree, and there's other functions that are more generic and appropriate. * Fix a few style issues. * Add and document ether_ntoa_r() and ether_aton_r() functions, which accept passed storage buffers rather than using static storage. Reimplement ether_ntoa() and ether_aton() in terms of these functions. These variants are thread-safe. * Document that AI_ALL and AI_V4MAPPED flags are currently not supported. * Add a SIOCGIFINDEX ioctl, which returns the index of a named interface. Use this ioctl in if_nametoindex(3) to use network aliases. * Add restrict qualifier where needed. * Add inet_ntoa_r() - a re-entrant function of inet_ntoa. * Note that inet6_option_space.3 and inet6_rthdr_space.3 functions are deprecated in favor of inet6_opt_init.3 and inet6_rth_space.3. * Remove NS and ISO stuff. * Sync map_v4v6.c with BIND9. * Instead of re-implementing hton[ls] and friends for each arch, add a new MI file, net/ntoh.c, which just implement them using the inline functions from . * Fix some namespace issues in . --- Makefile_upgrade.inc | 4 + contrib/bind-9.3/lib/bind/inet/nsap_addr.c | 2 +- include/arpa/inet.h | 4 +- include/netdb.h | 86 ++-- lib/libc/amd64/net/Makefile.inc | 5 - lib/libc/amd64/net/htonl.S | 50 --- lib/libc/amd64/net/htons.S | 50 --- lib/libc/amd64/net/ntohl.S | 50 --- lib/libc/amd64/net/ntohs.S | 52 --- lib/libc/i386/net/Makefile.inc | 5 - lib/libc/i386/net/htonl.S | 49 --- lib/libc/i386/net/ntohl.S | 49 --- lib/libc/i386/net/ntohs.S | 47 -- lib/libc/net/Makefile.inc | 43 +- lib/libc/net/addr2ascii.3 | 223 ---------- lib/libc/net/addr2ascii.c | 92 ---- lib/libc/net/ascii2addr.c | 70 --- lib/libc/net/byteorder.3 | 23 +- lib/libc/net/ether_addr.c | 120 +++--- lib/libc/net/ethers.3 | 86 ++-- lib/libc/net/eui64.3 | 2 +- lib/libc/net/getaddrinfo.3 | 59 +-- lib/libc/net/getifaddrs.3 | 9 +- lib/libc/net/getifaddrs.c | 2 +- lib/libc/net/getipnodebyname.3 | 105 +++-- lib/libc/net/getnetent.3 | 23 +- lib/libc/net/getprotoent.3 | 11 +- lib/libc/net/getservent.3 | 11 +- lib/libc/net/if_indextoname.3 | 62 ++- lib/libc/net/if_nametoindex.c | 19 +- lib/libc/net/inet.3 | 88 ++-- lib/libc/net/inet6_option_space.3 | 401 +----------------- lib/libc/net/inet6_rthdr_space.3 | 272 +----------- lib/libc/net/inet_net.3 | 24 +- lib/libc/net/ip6opt.c | 72 ++-- lib/libc/net/iso_addr.3 | 114 ----- lib/libc/net/iso_addr.c | 112 ----- lib/libc/net/linkaddr.3 | 22 +- lib/libc/net/linkaddr.c | 1 + lib/libc/net/map_v4v6.c | 22 +- lib/libc/net/ns.3 | 134 ------ lib/libc/net/ns_addr.c | 215 ---------- lib/libc/net/ns_ntoa.c | 104 ----- lib/libc/net/nsap_addr.c | 106 ----- lib/libc/net/ntoh.c | 53 +++ lib/libc/net/rcmd.3 | 29 +- lib/libc/net/rcmd.c | 55 +-- lib/libc/net/rcmdsh.3 | 14 +- lib/libc/net/rcmdsh.c | 5 +- lib/libc/net/recv.c | 5 +- lib/libc/net/resolver.3 | 115 ++++- lib/libc/net/send.c | 5 +- lib/libc/net/sockatmark.3 | 124 ++++++ .../{i386/net/htons.S => net/sockatmark.c} | 34 +- lib/libc/net/vars.c | 2 +- sbin/route/Makefile | 2 +- sbin/route/show.c | 2 + share/man/man9/Makefile | 28 ++ share/man/man9/byteorder.9 | 169 ++++++++ sys/net/ethernet.h | 2 + sys/net/if.c | 4 + sys/net/if.h | 2 + sys/sys/sockio.h | 1 + 63 files changed, 1042 insertions(+), 2709 deletions(-) delete mode 100644 lib/libc/amd64/net/Makefile.inc delete mode 100644 lib/libc/amd64/net/htonl.S delete mode 100644 lib/libc/amd64/net/htons.S delete mode 100644 lib/libc/amd64/net/ntohl.S delete mode 100644 lib/libc/amd64/net/ntohs.S delete mode 100644 lib/libc/i386/net/Makefile.inc delete mode 100644 lib/libc/i386/net/htonl.S delete mode 100644 lib/libc/i386/net/ntohl.S delete mode 100644 lib/libc/i386/net/ntohs.S delete mode 100644 lib/libc/net/addr2ascii.3 delete mode 100644 lib/libc/net/addr2ascii.c delete mode 100644 lib/libc/net/ascii2addr.c delete mode 100644 lib/libc/net/iso_addr.3 delete mode 100644 lib/libc/net/iso_addr.c delete mode 100644 lib/libc/net/ns.3 delete mode 100644 lib/libc/net/ns_addr.c delete mode 100644 lib/libc/net/ns_ntoa.c delete mode 100644 lib/libc/net/nsap_addr.c create mode 100644 lib/libc/net/ntoh.c create mode 100644 lib/libc/net/sockatmark.3 rename lib/libc/{i386/net/htons.S => net/sockatmark.c} (55%) create mode 100644 share/man/man9/byteorder.9 diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc index 38904dca19..3abf00907d 100644 --- a/Makefile_upgrade.inc +++ b/Makefile_upgrade.inc @@ -1064,3 +1064,7 @@ TO_REMOVE+=/usr/share/man/man9/objcache_reclaim_list.9.gz TO_REMOVE+=/usr/share/man/cat9/objcache_reclaim_list.9.gz TO_REMOVE+=/usr/share/man/cat3/timezone.3.gz TO_REMOVE+=/usr/share/man/man3/timezone.3.gz +TO_REMOVE+=/usr/share/man/cat3/addr2ascii.3.gz +TO_REMOVE+=/usr/share/man/man3/addr2ascii.3.gz +TO_REMOVE+=/usr/share/man/cat3/ascii2addr.3.gz +TO_REMOVE+=/usr/share/man/man3/ascii2addr.3.gz diff --git a/contrib/bind-9.3/lib/bind/inet/nsap_addr.c b/contrib/bind-9.3/lib/bind/inet/nsap_addr.c index eacd733269..5730fa4835 100644 --- a/contrib/bind-9.3/lib/bind/inet/nsap_addr.c +++ b/contrib/bind-9.3/lib/bind/inet/nsap_addr.c @@ -31,7 +31,7 @@ static const char rcsid[] = "$Id: nsap_addr.c,v 1.2.206.2 2005/07/28 07:43:18 ma #include #include -#include +#include "resolv_mt.h" #include "port_after.h" diff --git a/include/arpa/inet.h b/include/arpa/inet.h index 3f697165f8..bd8a71d56d 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -61,7 +61,7 @@ #ifndef _ARPA_INET_H_ #define _ARPA_INET_H_ -/* External definitions for functions in inet(3), addr2ascii(3) */ +/* External definitions for functions in inet(3) */ #include #include @@ -118,8 +118,6 @@ const char *inet_ntop(int, const void * __restrict, char * __restrict, int inet_pton(int, const char * __restrict, void * __restrict); #if __BSD_VISIBLE -int ascii2addr (int, const char *, void *); -char *addr2ascii (int, const void *, int, char *); int inet_aton(const char *, struct in_addr *); in_addr_t inet_lnaof(struct in_addr); struct in_addr inet_makeaddr(in_addr_t, in_addr_t); diff --git a/include/netdb.h b/include/netdb.h index 0f91f9c8ca..1f7e5fafe0 100644 --- a/include/netdb.h +++ b/include/netdb.h @@ -55,7 +55,7 @@ /* * @(#)netdb.h 8.1 (Berkeley) 6/2/93 * From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $ - * $FreeBSD: src/include/netdb.h,v 1.44 2006/05/21 11:27:28 ume Exp $ + * $FreeBSD: src/include/netdb.h,v 1.45 2009/03/14 20:04:28 das Exp $ * $DragonFly: src/include/netdb.h,v 1.7 2008/10/04 22:09:16 swildner Exp $ */ @@ -146,12 +146,14 @@ struct addrinfo { /* * Error return codes from getaddrinfo() */ +/* XXX deprecated */ #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ #define EAI_AGAIN 2 /* temporary failure in name resolution */ #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ #define EAI_FAMILY 5 /* ai_family not supported */ #define EAI_MEMORY 6 /* memory allocation failure */ +/* XXX deprecated */ #define EAI_NODATA 7 /* no address associated with hostname */ #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ @@ -195,8 +197,10 @@ struct addrinfo { #define NI_NAMEREQD 0x00000004 #define NI_NUMERICSERV 0x00000008 #define NI_DGRAM 0x00000010 +/* XXX deprecated */ #define NI_WITHSCOPEID 0x00000020 + /* * Scope delimit character */ @@ -205,93 +209,73 @@ struct addrinfo { __BEGIN_DECLS void endhostent(void); void endnetent(void); -void endnetgrent(void); void endprotoent(void); void endservent(void); -void freehostent(struct hostent *); +#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112) struct hostent *gethostbyaddr(const void *, socklen_t, int); -#if 0 +struct hostent *gethostbyname(const char *); +#endif +struct hostent *gethostent(void); +struct netent *getnetbyaddr(uint32_t, int); +struct netent *getnetbyname(const char *); +struct netent *getnetent(void); +struct protoent *getprotobyname(const char *); +struct protoent *getprotobynumber(int); +struct protoent *getprotoent(void); +struct servent *getservbyname(const char *, const char *); +struct servent *getservbyport(int, const char *); +struct servent *getservent(void); +void sethostent(int); +/* void sethostfile(const char *); */ +void setnetent(int); +void setprotoent(int); +int getaddrinfo(const char *, const char *, + const struct addrinfo *, struct addrinfo **); +int getnameinfo(const struct sockaddr *, socklen_t, char *, + size_t, char *, size_t, int); +void freeaddrinfo(struct addrinfo *); +const char *gai_strerror(int); +void setservent(int); + +#if __BSD_VISIBLE +void endnetgrent(void); +void freehostent(struct hostent *); int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); -#endif -struct hostent *gethostbyname(const char *); -#if 0 int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); -#endif struct hostent *gethostbyname2(const char *, int); -#if 0 int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); -#endif -struct hostent *gethostent(void); -#if 0 int gethostent_r(struct hostent *, char *, size_t, struct hostent **, int *); -#endif struct hostent *getipnodebyaddr(const void *, size_t, int, int *); struct hostent *getipnodebyname(const char *, int, int, int *); -struct netent *getnetbyaddr(uint32_t, int); -#if 0 int getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t, struct netent**, int *); -#endif -struct netent *getnetbyname(const char *); -#if 0 int getnetbyname_r(const char *, struct netent *, char *, size_t, struct netent **, int *); -#endif -struct netent *getnetent(void); -#if 0 int getnetent_r(struct netent *, char *, size_t, struct netent **, int *); -#endif int getnetgrent(char **, char **, char **); -struct protoent *getprotobyname(const char *); -#if 0 int getprotobyname_r(const char *, struct protoent *, char *, size_t, struct protoent **); -#endif -struct protoent *getprotobynumber(int); -#if 0 int getprotobynumber_r(int, struct protoent *, char *, size_t, struct protoent **); -#endif -struct protoent *getprotoent(void); -#if 0 int getprotoent_r(struct protoent *, char *, size_t, struct protoent **); -#endif -struct servent *getservbyname(const char *, const char *); -#if 0 int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); -#endif -struct servent *getservbyport(int, const char *); -#if 0 int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); -#endif -struct servent *getservent(void); -#if 0 int getservent_r(struct servent *, char *, size_t, struct servent **); -#endif void herror(const char *); __const char *hstrerror(int); int innetgr(const char *, const char *, const char *, const char *); -void sethostent(int); -/* void sethostfile(const char *); */ -void setnetent(int); -void setprotoent(int); -int getaddrinfo(const char *, const char *, - const struct addrinfo *, struct addrinfo **); -int getnameinfo(const struct sockaddr *, socklen_t, char *, - size_t, char *, size_t, int); -void freeaddrinfo(struct addrinfo *); -const char *gai_strerror(int); void setnetgrent(const char *); -void setservent(int); +#endif + /* * PRIVATE functions specific to the FreeBSD implementation diff --git a/lib/libc/amd64/net/Makefile.inc b/lib/libc/amd64/net/Makefile.inc deleted file mode 100644 index f830b82f3c..0000000000 --- a/lib/libc/amd64/net/Makefile.inc +++ /dev/null @@ -1,5 +0,0 @@ -# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $FreeBSD: src/lib/libc/amd64/net/Makefile.inc,v 1.6 1999/08/27 23:59:24 peter Exp $ -# $DragonFly: src/lib/libc/amd64/net/Makefile.inc,v 1.1 2004/02/02 05:43:14 dillon Exp $ - -SRCS+= htonl.S htons.S ntohl.S ntohs.S diff --git a/lib/libc/amd64/net/htonl.S b/lib/libc/amd64/net/htonl.S deleted file mode 100644 index 9d4503b608..0000000000 --- a/lib/libc/amd64/net/htonl.S +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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. - * - * @(#)htonl.s 5.3 (Berkeley) 12/17/90 - * $FreeBSD: src/lib/libc/amd64/net/htonl.S,v 1.10 2003/04/30 18:07:23 peter Exp $ - * $DragonFly: src/lib/libc/amd64/net/htonl.S,v 1.1 2004/02/02 05:43:14 dillon Exp $ - */ - -#include - -/* netorder = htonl(hostorder) */ - - .weak CNAME(htonl) - .set CNAME(htonl),CNAME(__htonl) -ENTRY(__htonl) - movl %edi,%eax - bswap %eax - ret diff --git a/lib/libc/amd64/net/htons.S b/lib/libc/amd64/net/htons.S deleted file mode 100644 index fdba2ec58f..0000000000 --- a/lib/libc/amd64/net/htons.S +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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. - * - * @(#)htons.s 5.2 (Berkeley) 12/17/90 - * $FreeBSD: src/lib/libc/amd64/net/htons.S,v 1.10 2003/04/30 18:07:23 peter Exp $ - * $DragonFly: src/lib/libc/amd64/net/htons.S,v 1.1 2004/02/02 05:43:14 dillon Exp $ - */ - -#include - -/* netorder = htons(hostorder) */ - - .weak CNAME(htons) - .set CNAME(htons),CNAME(__htons) -ENTRY(__htons) - movl %edi,%eax - xchgb %al,%ah - ret diff --git a/lib/libc/amd64/net/ntohl.S b/lib/libc/amd64/net/ntohl.S deleted file mode 100644 index a806a356fb..0000000000 --- a/lib/libc/amd64/net/ntohl.S +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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. - * - * @(#)ntohl.s 5.2 (Berkeley) 12/17/90 - * $FreeBSD: src/lib/libc/amd64/net/ntohl.S,v 1.10 2003/04/30 18:07:23 peter Exp $ - * $DragonFly: src/lib/libc/amd64/net/ntohl.S,v 1.1 2004/02/02 05:43:14 dillon Exp $ - */ - -#include - -/* hostorder = ntohl(netorder) */ - - .weak CNAME(ntohl) - .set CNAME(ntohl),CNAME(__ntohl) -ENTRY(__ntohl) - movl %edi,%eax - bswap %eax - ret diff --git a/lib/libc/amd64/net/ntohs.S b/lib/libc/amd64/net/ntohs.S deleted file mode 100644 index 60115ac3fc..0000000000 --- a/lib/libc/amd64/net/ntohs.S +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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. - * - * @(#)ntohs.s 5.2 (Berkeley) 12/17/90 - * $FreeBSD: src/lib/libc/amd64/net/ntohs.S,v 1.10 2003/04/30 18:07:23 peter Exp $ - * $DragonFly: src/lib/libc/amd64/net/ntohs.S,v 1.1 2004/02/02 05:43:14 dillon Exp $ - */ - -#include - -/* hostorder = ntohs(netorder) */ - -#include - - .weak CNAME(ntohs) - .set CNAME(ntohs),CNAME(__ntohs) -ENTRY(__ntohs) - movl %edi,%eax - xchgb %al,%ah - ret diff --git a/lib/libc/i386/net/Makefile.inc b/lib/libc/i386/net/Makefile.inc deleted file mode 100644 index e4e5ff4a8e..0000000000 --- a/lib/libc/i386/net/Makefile.inc +++ /dev/null @@ -1,5 +0,0 @@ -# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $FreeBSD: src/lib/libc/i386/net/Makefile.inc,v 1.6 1999/08/27 23:59:24 peter Exp $ -# $DragonFly: src/lib/libc/i386/net/Makefile.inc,v 1.2 2003/06/17 04:26:43 dillon Exp $ - -SRCS+= htonl.S htons.S ntohl.S ntohs.S diff --git a/lib/libc/i386/net/htonl.S b/lib/libc/i386/net/htonl.S deleted file mode 100644 index 8f24e96320..0000000000 --- a/lib/libc/i386/net/htonl.S +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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. - * - * $FreeBSD: src/lib/libc/i386/net/htonl.S,v 1.5 1999/08/27 23:59:25 peter Exp $ - * $DragonFly: src/lib/libc/i386/net/htonl.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ - */ - -/* netorder = htonl(hostorder) */ - -#include "DEFS.h" - -ENTRY(htonl) - movl 4(%esp),%eax - xchgb %al,%ah - roll $16,%eax - xchgb %al,%ah - ret diff --git a/lib/libc/i386/net/ntohl.S b/lib/libc/i386/net/ntohl.S deleted file mode 100644 index 16e1ac9c25..0000000000 --- a/lib/libc/i386/net/ntohl.S +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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. - * - * $FreeBSD: src/lib/libc/i386/net/ntohl.S,v 1.5 1999/08/27 23:59:25 peter Exp $ - * $DragonFly: src/lib/libc/i386/net/ntohl.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ - */ - -/* hostorder = ntohl(netorder) */ - -#include "DEFS.h" - -ENTRY(ntohl) - movl 4(%esp),%eax - xchgb %al,%ah - roll $16,%eax - xchgb %al,%ah - ret diff --git a/lib/libc/i386/net/ntohs.S b/lib/libc/i386/net/ntohs.S deleted file mode 100644 index 270618de17..0000000000 --- a/lib/libc/i386/net/ntohs.S +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * 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. - * - * $FreeBSD: src/lib/libc/i386/net/ntohs.S,v 1.5 1999/08/27 23:59:25 peter Exp $ - * $DragonFly: src/lib/libc/i386/net/ntohs.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ - */ - -/* hostorder = ntohs(netorder) */ - -#include "DEFS.h" - -ENTRY(ntohs) - movzwl 4(%esp),%eax - xchgb %al,%ah - ret diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 1f40fc590a..e7a6b05723 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -3,9 +3,9 @@ # $DragonFly: src/lib/libc/net/Makefile.inc,v 1.6 2008/10/04 22:09:17 swildner Exp $ # machine-independent net sources -.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/net ${.CURDIR}/../libc/net +.PATH: ${.CURDIR}/../libc/net -SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c eui64.c \ +SRCS+= base64.c ether_addr.c eui64.c \ gai_strerror.c getaddrinfo.c \ gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \ getifaddrs.c getnameinfo.c \ @@ -13,14 +13,11 @@ SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c eui64.c \ getproto.c getprotoent.c getprotoname.c \ getservent.c \ if_indextoname.c if_nameindex.c if_nametoindex.c \ - ip6opt.c linkaddr.c map_v4v6.c name6.c ns_addr.c \ - ns_name.c ns_netint.c \ - ns_ntoa.c ns_parse.c ns_print.c ns_ttl.c nsap_addr.c \ - nsdispatch.c nslexer.c nsparser.y nss_compat.c \ + ip6opt.c linkaddr.c map_v4v6.c name6.c \ + nsdispatch.c nslexer.c nsparser.y nss_compat.c ntoh.c \ rcmd.c rcmdsh.c recv.c res_comp.c res_data.c res_debug.c \ res_init.c res_mkquery.c res_query.c res_send.c \ - rthdr.c send.c vars.c -# not supported: iso_addr.c + rthdr.c sockatmark.c send.c vars.c .if !defined(NO_NS_CACHING) SRCS+= nscache.c nscachedcli.c @@ -28,15 +25,6 @@ SRCS+= nscache.c nscachedcli.c CFLAGS+=-DINET6 -I${.OBJDIR} -# Temporary hack to fix 3rd party programs -CFLAGS+=-Dgethostbyaddr_r=GETHOSTBYADDR_R -Dgethostbyname_r=GETHOSTBYNAME_R \ - -Dgethostbyname2_r=GETHOSTBYNAME2_R -Dgethostent_r=GETHOSTENT_R \ - -Dgetnetbyaddr_r=GETNETBYADDR_R -Dgetnetbyname_r=GETNETBYNAME_R \ - -Dgetnetent_r=GETNETENT_R -Dgetprotobyname_r=GETPROTOBYNAME_R \ - -Dgetprotobynumber_r=GETPROTOBYNUMBER_R -Dgetprotoent_r=GETPROTOENT_R \ - -Dgetservbyname_r=GETSERVBYNAME_R -Dgetservbyport_r=GETSERVBYPORT_R \ - -Dgetservent_r=GETSERVENT_R - YFLAGS+=-p_nsyy LFLAGS+=-P_nsyy @@ -46,25 +34,21 @@ nslexer.c: nslexer.l ${LEX} ${LFLAGS} -o/dev/stdout ${.IMPSRC} | \ sed -e '/YY_BUF_SIZE/s/16384/1024/' >${.TARGET} -# machine-dependent net sources -.include "${.CURDIR}/../libc/${MACHINE_ARCH}/net/Makefile.inc" - .if ${LIB} == "c" -MAN+= addr2ascii.3 byteorder.3 ethers.3 eui64.3 \ +MAN+= byteorder.3 ethers.3 eui64.3 \ gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ getifaddrs.3 getipnodebyname.3 \ getnameinfo.3 getnetent.3 getprotoent.3 getservent.3 if_indextoname.3 \ inet.3 inet_net.3 \ inet6_opt_init.3 inet6_option_space.3 inet6_rth_space.3 \ inet6_rthdr_space.3 linkaddr.3 nsdispatch.3 \ - rcmd.3 rcmdsh.3 resolver.3 -# not installed: iso_addr.3 ns.3 + rcmd.3 rcmdsh.3 resolver.3 sockatmark.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+=ethers.3 ether_aton.3 ethers.3 ether_aton_r.3 ethers.3 ether_hostton.3 \ + ethers.3 ether_line.3 ethers.3 ether_ntoa.3 ethers.3 ether_ntoa_r.3 \ + ethers.3 ether_ntohost.3 MLINKS+=eui64.3 eui64_aton.3 eui64.3 eui64_hostton.3 eui64.3 eui64_ntoa.3 \ eui64.3 eui64_ntohost.3 MLINKS+=getaddrinfo.3 freeaddrinfo.3 @@ -84,7 +68,7 @@ MLINKS+=if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ if_indextoname.3 if_freenameindex.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 inet_network.3 inet.3 inet_ntoa.3 inet.3 inet_ntoa_r.3 \ inet.3 inet_ntop.3 inet.3 inet_pton.3 \ inet.3 network.3 inet.3 ntoa.3 MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 @@ -112,12 +96,13 @@ MLINKS+=inet6_opt_init.3 inet6_opt_append.3 \ inet6_rthdr_space.3 inet6_rthdr_reverse.3 \ inet6_rthdr_space.3 inet6_rthdr_segments.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 iruserok_sa.3 \ rcmd.3 rcmd_af.3 \ rcmd.3 rresvport.3 rcmd.3 rresvport_af.3 \ rcmd.3 ruserok.3 -MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ +MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 dn_skipname.3 \ + resolver.3 ns_get16.3 resolver.3 ns_get32.3 resolver.3 ns_put16.3 \ + resolver.3 ns_put32.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 4fe7637213..0000000000 --- a/lib/libc/net/addr2ascii.3 +++ /dev/null @@ -1,223 +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 $ -.\" $FreeBSD: src/lib/libc/net/addr2ascii.3,v 1.7.2.5 2001/12/14 18:33:55 ru Exp $ -.\" $DragonFly: src/lib/libc/net/addr2ascii.3,v 1.4 2007/06/30 19:03:52 swildner Exp $ -.\" -.Dd June 13, 1996 -.Dt ADDR2ASCII 3 -.Os -.Sh NAME -.Nm addr2ascii , -.Nm ascii2addr -.Nd Generic address formatting routines -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In sys/types.h -.In netinet/in.h -.In 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 -(in -.In netinet/in.h ) -.It Dv AF_LINK -.Li struct sockaddr_dl -(in -.In net/if_dl.h ) -.\" .It Dv AF_INET6 -.\" .Li struct in6_addr -.\" (in -.\" .In 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 -#include -#include -#include - -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, -.Va errno -is set to one of the following values: -.Bl -tag -width Er -.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 appeared in the -.Tn INRIA -.Tn IPv6 -implementation. -.Sh AUTHORS -Code and documentation by -.An 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 3cb8c3104d..0000000000 --- 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 $ - * $DragonFly: src/lib/libc/net/addr2ascii.c,v 1.2 2005/11/13 02:04:47 swildner Exp $ - */ - -#include -#include - -#include -#include - -#include -#include -#include - -/*- - * 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(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 c95ac1f418..0000000000 --- a/lib/libc/net/ascii2addr.c +++ /dev/null @@ -1,70 +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 $ - * $DragonFly: src/lib/libc/net/ascii2addr.c,v 1.2 2005/11/13 02:04:47 swildner Exp $ - */ - -#include -#include - -#include -#include - -#include -#include -#include - -int -ascii2addr(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/byteorder.3 b/lib/libc/net/byteorder.3 index eb0fa98c17..b3244a3bf5 100644 --- a/lib/libc/net/byteorder.3 +++ b/lib/libc/net/byteorder.3 @@ -9,10 +9,6 @@ .\" 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. @@ -30,10 +26,10 @@ .\" SUCH DAMAGE. .\" .\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/net/byteorder.3,v 1.3.2.4 2001/12/14 18:33:55 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/byteorder.3,v 1.13 2007/01/09 00:28:01 imp Exp $ .\" $DragonFly: src/lib/libc/net/byteorder.3,v 1.3 2004/09/15 15:04:31 joerg Exp $ .\" -.Dd June 4, 1993 +.Dd March 20, 2005 .Dt BYTEORDER 3 .Os .Sh NAME @@ -46,6 +42,10 @@ .Lb libc .Sh SYNOPSIS .In arpa/inet.h +.Pp +or +.Pp +.In netinet/in.h .Ft uint32_t .Fn htonl "uint32_t hostlong" .Ft uint16_t @@ -67,7 +67,13 @@ and .Xr getservent 3 . .Sh SEE ALSO .Xr gethostbyname 3 , -.Xr getservent 3 +.Xr getservent 3 , +.Xr byteorder 9 +.Sh STANDARDS +The +.Nm byteorder +functions conform to +.St -p1003.1-2001 . .Sh HISTORY The .Nm byteorder @@ -77,4 +83,5 @@ functions appeared in 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. +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 index ac64691411..66fda2130d 100644 --- a/lib/libc/net/ether_addr.c +++ b/lib/libc/net/ether_addr.c @@ -1,6 +1,7 @@ /* - * Copyright (c) 1995 - * Bill Paul . All rights reserved. + * Copyright (c) 1995 Bill Paul . + * Copyright (c) 2007 Robert N. M. Watson + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,95 +36,103 @@ * Center for Telecommunications Research * Columbia University, New York City * - * $FreeBSD: src/lib/libc/net/ether_addr.c,v 1.10.2.5 2002/04/08 08:01:50 ru Exp $ + * $FreeBSD: src/lib/libc/net/ether_addr.c,v 1.17 2007/05/13 13:57:44 rwatson Exp $ * $DragonFly: src/lib/libc/net/ether_addr.c,v 1.4 2005/11/13 02:04:47 swildner Exp $ */ -#include -#include #include -#include -#include #include #include + #include + #ifdef YP #include #include #include #endif +#include +#include +#include +#include + #ifndef _PATH_ETHERS -#define _PATH_ETHERS "/etc/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. + * Parse a string of text containing an ethernet address and hostname and + * separate it into its component parts. */ int ether_line(const char *l, struct ether_addr *e, char *hostname) { - int i, o[6]; + 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); + 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); + 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. + * Convert an ASCII representation of an ethernet address to binary form. */ struct ether_addr * -ether_aton(const char *a) +ether_aton_r(const char *a, struct ether_addr *e) { - int i; - static struct ether_addr o; + int i; 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); + i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5); + if (i != 6) + return (NULL); + e->octet[0]=o0; + e->octet[1]=o1; + e->octet[2]=o2; + e->octet[3]=o3; + e->octet[4]=o4; + e->octet[5]=o5; + return (e); +} - o.octet[0]=o0; - o.octet[1]=o1; - o.octet[2]=o2; - o.octet[3]=o3; - o.octet[4]=o4; - o.octet[5]=o5; +struct ether_addr * +ether_aton(const char *a) +{ + static struct ether_addr e; - return ((struct ether_addr *)&o); + return (ether_aton_r(a, &e)); } /* - * Convert a binary representation of an ethernet address to - * an ASCII string. + * Convert a binary representation of an ethernet address to an ASCII string. */ +char * +ether_ntoa_r(const struct ether_addr *n, char *a) +{ + int i; + + i = sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x", n->octet[0], + n->octet[1], n->octet[2], n->octet[3], n->octet[4], n->octet[5]); + if (i < 17) + return (NULL); + return (a); +} + char * ether_ntoa(const struct ether_addr *n) { - int i; static char a[18]; - i = sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x", - n->octet[0], n->octet[1], n->octet[2], - n->octet[3], n->octet[4], n->octet[5]); - if (i < 17) - return (NULL); - return ((char *)&a); + return (ether_ntoa_r(n, a)); } /* - * Map an ethernet address to a hostname. Use either /etc/ethers or - * NIS/YP. + * Map an ethernet address to a hostname. Use either /etc/ethers or NIS/YP. */ int ether_ntohost(char *hostname, const struct ether_addr *e) @@ -138,9 +147,9 @@ ether_ntohost(char *hostname, const struct ether_addr *e) 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; @@ -150,7 +159,7 @@ ether_ntohost(char *hostname, const struct ether_addr *e) continue; ether_a = ether_ntoa(e); if (yp_match(yp_domain, "ethers.byaddr", ether_a, - strlen(ether_a), &result, &resultlen)) { + strlen(ether_a), &result, &resultlen)) { continue; } strncpy(buf, result, resultlen); @@ -160,8 +169,8 @@ ether_ntohost(char *hostname, const struct ether_addr *e) #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 */ + (char *)&e->octet[0], 6)) { + /* We have a match. */ strcpy(hostname, local_host); fclose(fp); return(0); @@ -173,8 +182,7 @@ ether_ntohost(char *hostname, const struct ether_addr *e) } /* - * Map a hostname to an ethernet address using /etc/ethers or - * NIS/YP. + * Map a hostname to an ethernet address using /etc/ethers or NIS/YP. */ int ether_hostton(const char *hostname, struct ether_addr *e) @@ -188,9 +196,9 @@ ether_hostton(const char *hostname, struct ether_addr *e) int resultlen; char *yp_domain; #endif + if ((fp = fopen(_PATH_ETHERS, "r")) == NULL) return (1); - while (fgets(buf,BUFSIZ,fp)) { if (buf[0] == '#') continue; @@ -199,7 +207,7 @@ ether_hostton(const char *hostname, struct ether_addr *e) if (yp_get_default_domain(&yp_domain)) continue; if (yp_match(yp_domain, "ethers.byname", hostname, - strlen(hostname), &result, &resultlen)) { + strlen(hostname), &result, &resultlen)) { continue; } strncpy(buf, result, resultlen); @@ -209,9 +217,9 @@ ether_hostton(const char *hostname, struct ether_addr *e) #endif if (!ether_line(buf, &local_ether, local_host)) { if (!strcmp(hostname, local_host)) { - /* We have a match */ + /* We have a match. */ bcopy((char *)&local_ether.octet[0], - (char *)&e->octet[0], 6); + (char *)&e->octet[0], 6); fclose(fp); return(0); } diff --git a/lib/libc/net/ethers.3 b/lib/libc/net/ethers.3 index 5a0f98f7d5..831a3f048c 100644 --- a/lib/libc/net/ethers.3 +++ b/lib/libc/net/ethers.3 @@ -1,5 +1,6 @@ -.\" Copyright (c) 1995 -.\" Bill Paul . All rights reserved. +.\" Copyright (c) 1995 Bill Paul . +.\" Copyright (c) 2007 Robert N. M. Watson +.\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -28,17 +29,19 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/net/ethers.3,v 1.10.2.11 2002/02/01 15:51:17 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/ethers.3,v 1.25 2007/10/30 15:31:41 keramida Exp $ .\" $DragonFly: src/lib/libc/net/ethers.3,v 1.4 2006/05/26 19:39:37 swildner Exp $ .\" -.Dd April 12, 1995 +.Dd October 30, 2007 .Dt ETHERS 3 .Os .Sh NAME .Nm ethers , .Nm ether_line , .Nm ether_aton , +.Nm ether_aton_r , .Nm ether_ntoa , +.Nm ether_ntoa_r , .Nm ether_ntohost , .Nm ether_hostton .Nd Ethernet address conversion and lookup routines @@ -52,15 +55,19 @@ .Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname" .Ft struct ether_addr * .Fn ether_aton "const char *a" +.Ft struct ether_addr * +.Fn ether_aton_r "const char *a" "struct ether_addr *e" .Ft char * .Fn ether_ntoa "const struct ether_addr *n" +.Ft char * +.Fn ether_ntoa_r "const struct ether_addr *n" "char *buf" .Ft int .Fn ether_ntohost "char *hostname" "const struct ether_addr *e" .Ft int .Fn ether_hostton "const char *hostname" "struct ether_addr *e" .Sh DESCRIPTION These functions operate on ethernet addresses using an -.Ar ether_addr +.Vt ether_addr structure, which is defined in the header file .In netinet/if_ether.h : .Bd -literal -offset indent @@ -80,15 +87,15 @@ struct ether_addr { The function .Fn ether_line scans -.Ar l , +.Fa l , an .Tn ASCII string in .Xr ethers 5 format and sets -.Ar e +.Fa e to the ethernet address specified in the string and -.Ar h +.Fa h to the hostname. This function is used to parse lines from .Pa /etc/ethers @@ -96,18 +103,23 @@ into their component parts. .Pp The .Fn ether_aton -function converts an +and +.Fn ether_aton_r +functions convert .Tn ASCII -representation of an ethernet address into an -.Ar ether_addr -structure. -Likewise, +representation of ethernet addresses into +.Vt ether_addr +structures. +Likewise, the .Fn ether_ntoa -converts an ethernet address specified as an -.Ar ether_addr -structure into an +and +.Fn ether_ntoa_r +functions +convert ethernet addresses specified as +.Vt ether_addr +structures into .Tn ASCII -string. +strings. .Pp The .Fn ether_ntohost @@ -117,40 +129,57 @@ functions map ethernet addresses to their corresponding hostnames as specified in the .Pa /etc/ethers database. +The .Fn ether_ntohost +function converts from ethernet address to hostname, and .Fn ether_hostton converts from hostname to ethernet address. .Sh RETURN VALUES +The .Fn ether_line +function returns zero on success and non-zero if it was unable to parse any part of the supplied line -.Ar l . +.Fa l . It returns the extracted ethernet address in the supplied -.Ar ether_addr +.Vt ether_addr structure -.Ar e +.Fa e and the hostname in the supplied string -.Ar h . +.Fa h . .Pp On success, .Fn ether_ntoa -returns a pointer to a string containing an +and +.Fn ether_ntoa_r +functions return 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 +.Vt ether_addr structure, it returns a .Dv NULL pointer. +.Fn ether_ntoa +stores the result in a static buffer; +.Fn ether_ntoa_r +stores the result in a user-passed buffer. +.Pp Likewise, .Fn ether_aton -returns a pointer to an -.Ar ether_addr +and +.Fn ether_aton_r +return a pointer to an +.Vt ether_addr structure on success and a .Dv NULL pointer on failure. +.Fn ether_aton +stores the result in a static buffer; +.Fn ether_aton_r +stores the result in a user-passed buffer. .Pp The .Fn ether_ntohost @@ -189,6 +218,8 @@ This particular implementation of the .Nm library functions were written for and first appeared in .Fx 2.1 . +Thread-safe function variants first appeared in +.Fx 7.0 . .Sh BUGS The .Fn ether_aton @@ -196,3 +227,8 @@ and .Fn ether_ntoa functions returns values that are stored in static memory areas which may be overwritten the next time they are called. +.Pp +.Fn ether_ntoa_r +accepts a character buffer pointer, but not a buffer length. +The caller must ensure adequate space is available in the buffer in order to +avoid a buffer overflow. diff --git a/lib/libc/net/eui64.3 b/lib/libc/net/eui64.3 index 77c4956883..4d8db4a40b 100644 --- a/lib/libc/net/eui64.3 +++ b/lib/libc/net/eui64.3 @@ -54,7 +54,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/net/eui64.3,v 1.3 2004/07/07 20:15:31 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/eui64.3,v 1.4 2005/01/20 09:17:03 ru Exp $ .\" $DragonFly: src/lib/libc/net/eui64.3,v 1.4 2006/05/26 19:39:37 swildner Exp $ .\" .Dd March 4, 2004 diff --git a/lib/libc/net/getaddrinfo.3 b/lib/libc/net/getaddrinfo.3 index b7ada3b5c0..c15b01ca74 100644 --- a/lib/libc/net/getaddrinfo.3 +++ b/lib/libc/net/getaddrinfo.3 @@ -16,10 +16,10 @@ .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR .\" PERFORMANCE OF THIS SOFTWARE. .\" -.\" $FreeBSD: src/lib/libc/net/getaddrinfo.3,v 1.34 2008/07/01 22:59:20 danger Exp $ +.\" $FreeBSD: src/lib/libc/net/getaddrinfo.3,v 1.36 2009/01/06 13:10:15 danger Exp $ .\" $DragonFly: src/lib/libc/net/getaddrinfo.3,v 1.7 2008/05/22 06:50:14 hasso Exp $ .\" -.Dd July 1, 2008 +.Dd January 6, 2009 .Dt GETADDRINFO 3 .Os .Sh NAME @@ -129,13 +129,11 @@ field to which the parameter points shall be set to zero or be the bitwise-inclusive OR of one or more of the values .Dv AI_ADDRCONFIG , -.Dv AI_ALL , .Dv AI_CANONNAME , .Dv AI_NUMERICHOST , -.Dv AI_NUMERICSERV , -.Dv AI_PASSIVE , +.Dv AI_NUMERICSERV and -.Dv AI_V4MAPPED . +.Dv AI_PASSIVE . .Bl -tag -width "AI_CANONNAMEXX" .It Dv AI_ADDRCONFIG If the @@ -144,19 +142,6 @@ bit is set, IPv4 addresses shall be returned only if an IPv4 address is configured on the local system, and IPv6 addresses shall be returned only if an IPv6 address is configured on the local system. -.It Dv AI_ALL -If the -.Dv AI_ALL -bit is set with the -.Dv AI_V4MAPPED -bit, then -.Fn getaddrinfo -shall return all matching IPv6 and IPv4 addresses. -The -.Dv AI_ALL -bit without the -.Dv AI_V4MAPPED -bit is ignored. .It Dv AI_CANONNAME If the .Dv AI_CANONNAME @@ -221,30 +206,6 @@ loopback address if is the null pointer and .Dv AI_PASSIVE is not set. -.It Dv AI_V4MAPPED -If the -.Dv AI_V4MAPPED -flag is specified along with an -.Fa ai_family -of -.Dv AF_INET6 , -then -.Fn getaddrinfo -shall return IPv4-mapped IPv6 addresses -on finding no matching IPv6 addresses ( -.Fa ai_addrlen -shall be 16). -The -.Dv AI_V4MAPPED -flag shall be ignored unless -.Fa ai_family -equals -.Dv AF_INET6 . -Note: this flag is currently -.Em not -supported, see the -.Sx BUGS -section. .El .El .Pp @@ -493,18 +454,6 @@ freeaddrinfo(res0); .%B "Proceedings of the freenix track: 2000 USENIX annual technical conference" .%D June 2000 .Re -.Sh BUGS -The -.Nm -function as implemented in -.Dx -currently does not support -.Dv AI_ALL -and -.Dv AI_V4MAPPED -flags and returns -.Dv EAI_BADFLAGS -if one of them is specified. .Sh STANDARDS The .Fn getaddrinfo diff --git a/lib/libc/net/getifaddrs.3 b/lib/libc/net/getifaddrs.3 index 930dc9f51d..54adbbb844 100644 --- a/lib/libc/net/getifaddrs.3 +++ b/lib/libc/net/getifaddrs.3 @@ -1,5 +1,3 @@ -.\" $FreeBSD: src/lib/libc/net/getifaddrs.3,v 1.1.2.5 2001/12/14 18:33:55 ru Exp $ -.\" $DragonFly: src/lib/libc/net/getifaddrs.3,v 1.5 2007/08/18 20:48:47 swildner Exp $ .\" $KAME: getifaddrs.3,v 1.4 2000/05/17 14:13:14 itojun Exp $ .\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp .\" @@ -23,6 +21,10 @@ .\" 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. +.\" +.\" $FreeBSD: src/lib/libc/net/getifaddrs.3,v 1.10 2005/02/09 18:03:13 ru Exp $ +.\" $DragonFly: src/lib/libc/net/getifaddrs.3,v 1.5 2007/08/18 20:48:47 swildner Exp $ +.\" .Dd October 12, 1995 .Dt GETIFADDRS 3 .Os @@ -113,7 +115,8 @@ if one exists, otherwise it is NULL. .Pp The .Li ifa_data -field references address family specific data. For +field references address family specific data. +For .Dv AF_LINK addresses it contains a pointer to the .Fa struct if_data diff --git a/lib/libc/net/getifaddrs.c b/lib/libc/net/getifaddrs.c index 3a96bbf1a9..fecb73c42b 100644 --- a/lib/libc/net/getifaddrs.c +++ b/lib/libc/net/getifaddrs.c @@ -1,4 +1,4 @@ -/* $FreeBSD: src/lib/libc/net/getifaddrs.c,v 1.1.2.4 2002/08/01 19:31:06 ume Exp $ */ +/* $FreeBSD: src/lib/libc/net/getifaddrs.c,v 1.6 2002/07/25 08:08:30 ume Exp $ */ /* $DragonFly: src/lib/libc/net/getifaddrs.c,v 1.5 2005/01/31 22:29:33 dillon Exp $ */ /* $KAME: getifaddrs.c,v 1.9 2001/08/20 02:31:20 itojun Exp $ */ diff --git a/lib/libc/net/getipnodebyname.3 b/lib/libc/net/getipnodebyname.3 index c8fbbba86b..686861cb6b 100644 --- a/lib/libc/net/getipnodebyname.3 +++ b/lib/libc/net/getipnodebyname.3 @@ -1,5 +1,3 @@ -.\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.2.2.4 2001/12/14 18:33:55 ru Exp $ -.\" $DragonFly: src/lib/libc/net/getipnodebyname.3,v 1.4 2007/11/23 23:16:36 swildner Exp $ .\" $KAME: getipnodebyname.3,v 1.6 2000/08/09 21:16:17 itojun Exp $ .\" .\" Copyright (c) 1983, 1987, 1991, 1993 @@ -13,10 +11,6 @@ .\" 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. @@ -34,8 +28,10 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95 +.\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.18 2007/01/09 00:28:02 imp Exp $ +.\" $DragonFly: src/lib/libc/net/getipnodebyname.3,v 1.4 2007/11/23 23:16:36 swildner Exp $ .\" -.Dd May 25, 1995 +.Dd August 6, 2004 .Dt GETIPNODEBYNAME 3 .Os .\" @@ -59,6 +55,7 @@ .Fn freehostent "struct hostent *ptr" .\" .Sh DESCRIPTION +The .Fn getipnodebyname and .Fn getipnodebyaddr @@ -70,9 +67,9 @@ and The functions cover all the functionalities provided by the older ones, and provide better interface to programmers. The functions require additional arguments, -.Ar af , +.Fa af , and -.Ar flags , +.Fa flags , for specifying address family and operation mode. The additional arguments allow programmer to get address for a nodename, for specific address family @@ -81,7 +78,7 @@ for specific address family or .Dv AF_INET6 ) . The functions also require an additional pointer argument, -.Ar error_num +.Fa error_num to return the appropriate error code, to support thread safe error code returns. .Pp @@ -93,18 +90,18 @@ is described in For .Fn getipnodebyname , the -.Ar name +.Fa name argument can be either a node name or a numeric address string (i.e., a dotted-decimal IPv4 address or an IPv6 hex address). The -.Ar af +.Fa af argument specifies the address family, either .Dv AF_INET or .Dv AF_INET6 . The -.Ar flags +.Fa flags argument specifies the types of addresses that are searched for, and the types of addresses that are returned. We note that a special flags value of @@ -123,22 +120,22 @@ with .Pp Applications desiring finer control over the types of addresses searched for and returned, can specify other combinations of the -.Ar flags +.Fa flags argument. .Pp A -.Ar flags +.Fa flags of .Li 0 implies a strict interpretation of the -.Ar af +.Fa af argument: .Bl -bullet .It If -.Ar flags +.Fa flags is 0 and -.Ar af +.Fa af is .Dv AF_INET , then the caller wants only IPv4 addresses. @@ -154,9 +151,9 @@ structure will be 4, else the function returns a pointer. .It If -.Ar flags +.Fa flags is 0 and if -.Ar af +.Fa af is .Li AF_INET6 , then the caller wants only IPv6 addresses. @@ -173,14 +170,14 @@ pointer. .El .Pp Other constants can be logically-ORed into the -.Ar flags +.Fa flags argument, to modify the behavior of the function. .Bl -bullet .It If the .Dv AI_V4MAPPED flag is specified along with an -.Ar af +.Fa af of .Dv AF_INET6 , then the caller will accept IPv4-mapped IPv6 addresses. @@ -194,7 +191,7 @@ will be 16). The .Dv AI_V4MAPPED flag is ignored unless -.Ar af +.Fa af equals .Dv AF_INET6 . .It @@ -217,15 +214,19 @@ flag then the caller wants all addresses: IPv6 and IPv4-mapped IPv6. A query is first made for .Li AAAA records and if successful, the -IPv6 addresses are returned. Another query is then made for +IPv6 addresses are returned. +Another query is then made for .Li A records and any found are returned as IPv4-mapped IPv6 addresses. .Li h_length -will be 16. Only if both queries fail does the function +will be 16. +Only if both queries fail does the function return a .Dv NULL -pointer. This flag is ignored unless af equals -AF_INET6. If both +pointer. +This flag is ignored unless af equals +AF_INET6. +If both .Dv AI_ALL and .Dv AI_V4MAPPED @@ -246,7 +247,7 @@ configured. .Pp For example, if the node has no IPv6 source addresses configured, and -.Ar af +.Fa af equals AF_INET6, and the node name being looked up has both .Li AAAA and @@ -277,40 +278,40 @@ is defined as We noted that the .Fn getipnodebyname function must allow the -.Ar name +.Fa name argument to be either a node name or a literal address string (i.e., a dotted-decimal IPv4 address or an IPv6 hex address). This saves applications from having to call .Xr inet_pton 3 to handle literal address strings. When the -.Ar name +.Fa name argument is a literal address string, the -.Ar flags +.Fa flags argument is always ignored. .Pp There are four scenarios based on the type of literal address string and the value of the -.Ar af +.Fa af argument. The two simple cases are when -.Ar name +.Fa name is a dotted-decimal IPv4 address and -.Ar af +.Fa af equals .Dv AF_INET , or when -.Ar name +.Fa name is an IPv6 hex address and -.Ar af +.Fa af equals .Dv AF_INET6 . The members of the returned hostent structure are: .Li h_name points to a copy of the -.Ar name +.Fa name argument, .Li h_aliases is a @@ -318,7 +319,7 @@ is a pointer, .Li h_addrtype is a copy of the -.Ar af +.Fa af argument, .Li h_length is either 4 @@ -336,9 +337,9 @@ is a pointer. .Pp When -.Ar name +.Fa name is a dotted-decimal IPv4 address and -.Ar af +.Fa af equals .Dv AF_INET6 , and @@ -364,30 +365,36 @@ is a pointer. .Pp It is an error when -.Ar name +.Fa name is an IPv6 hex address and -.Ar af +.Fa af equals .Dv AF_INET . The function's return value is a .Dv NULL pointer and the value pointed to by -.Ar error_num +.Fa error_num equals .Dv HOST_NOT_FOUND . .Pp +The .Fn getipnodebyaddr +function takes almost the same argument as .Xr gethostbyaddr 3 , but adds a pointer to return an error number. Additionally it takes care of IPv4-mapped IPv6 addresses, and IPv4-compatible IPv6 addresses. .Pp +The .Fn getipnodebyname and .Fn getipnodebyaddr +functions dynamically allocate the structure to be returned to the caller. +The .Fn freehostent +function reclaims memory region allocated and returned by .Fn getipnodebyname or @@ -401,22 +408,26 @@ or .El .\" .Sh DIAGNOSTICS +The .Fn getipnodebyname and .Fn getipnodebyaddr +functions returns .Dv NULL on errors. The integer values pointed to by -.Ar error_num +.Fa error_num may then be checked to see whether this is a temporary failure or an invalid or unknown host. The meanings of each error code are described in .Xr gethostbyname 3 . .\" .Sh SEE ALSO +.Xr getaddrinfo 3 , .Xr gethostbyaddr 3 , .Xr gethostbyname 3 , +.Xr getnameinfo 3 , .Xr hosts 5 , .Xr nsswitch.conf 5 , .Xr services 5 , @@ -434,9 +445,11 @@ The meanings of each error code are described in .Re .\" .Sh STANDARDS +The .Fn getipnodebyname and .Fn getipnodebyaddr +functions are documented in .Dq Basic Socket Interface Extensions for IPv6 (RFC 2553). @@ -445,9 +458,11 @@ are documented in The implementation first appeared in KAME advanced networking kit. .\" .Sh BUGS +The .Fn getipnodebyname and .Fn getipnodebyaddr +functions do not handle scoped IPv6 address properly. If you use these functions, your program will not be able to handle scoped IPv6 addresses. @@ -457,6 +472,4 @@ and .Fn getnameinfo 3 are recommended. .Pp -The current implementation is not thread-safe. -.Pp The text was shamelessly copied from RFC 2553. diff --git a/lib/libc/net/getnetent.3 b/lib/libc/net/getnetent.3 index 3604e7336a..95d7150318 100644 --- a/lib/libc/net/getnetent.3 +++ b/lib/libc/net/getnetent.3 @@ -9,10 +9,6 @@ .\" 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. @@ -30,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/net/getnetent.3,v 1.11.2.4 2001/12/14 18:33:55 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/getnetent.3,v 1.23 2007/01/09 00:28:02 imp Exp $ .\" $DragonFly: src/lib/libc/net/getnetent.3,v 1.2 2003/06/17 04:26:44 dillon Exp $ .\" .Dd June 4, 1993 @@ -52,7 +48,7 @@ .Ft struct netent * .Fn getnetbyname "const char *name" .Ft struct netent * -.Fn getnetbyaddr "unsigned long net" "int type" +.Fn getnetbyaddr "uint32_t net" "int type" .Ft void .Fn setnetent "int stayopen" .Ft void @@ -73,15 +69,17 @@ broken-out fields of a line in the network data base .Pa /etc/networks , or entries supplied by the .Xr yp 8 -system. The order of the lookups is controlled by the +system. +The order of the lookups is controlled by the `networks' entry in .Xr nsswitch.conf 5 . +.Pp .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 */ + uint32_t n_net; /* net number */ }; .Ed .Pp @@ -94,7 +92,8 @@ 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 +The network number. +Network numbers are returned in machine byte order. .El .Pp @@ -106,7 +105,8 @@ reads the next line of the file, opening the file if necessary. The .Fn setnetent function -opens and rewinds the file. If the +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 @@ -133,6 +133,7 @@ or until is encountered. The .Fa type +argument must be .Dv AF_INET . Network numbers are supplied in host order. @@ -163,7 +164,7 @@ 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 +these functions is thread-specific; 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. diff --git a/lib/libc/net/getprotoent.3 b/lib/libc/net/getprotoent.3 index 8dacc6f6fe..4f16eac5aa 100644 --- a/lib/libc/net/getprotoent.3 +++ b/lib/libc/net/getprotoent.3 @@ -9,10 +9,6 @@ .\" 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. @@ -30,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/net/getprotoent.3,v 1.4.2.4 2001/12/14 18:33:55 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/getprotoent.3,v 1.12 2007/01/09 00:28:02 imp Exp $ .\" $DragonFly: src/lib/libc/net/getprotoent.3,v 1.3 2008/05/01 21:51:43 swildner Exp $ .\" .Dd June 4, 1993 @@ -95,7 +91,8 @@ reads the next line of the file, opening the file if necessary. The .Fn setprotoent function -opens and rewinds the file. If the +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 @@ -142,7 +139,7 @@ and functions appeared in .Bx 4.2 . .Sh BUGS -These functions use a static data space; +These functions use a thread-specific data space; if the data is needed for future use, it should be copied before any subsequent calls overwrite it. Only the Internet diff --git a/lib/libc/net/getservent.3 b/lib/libc/net/getservent.3 index 244c72f13f..24ceb0941b 100644 --- a/lib/libc/net/getservent.3 +++ b/lib/libc/net/getservent.3 @@ -9,10 +9,6 @@ .\" 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. @@ -30,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)getservent.3 8.3 (Berkeley) 1/12/94 -.\" $FreeBSD: src/lib/libc/net/getservent.3,v 1.7.2.5 2001/12/14 18:33:55 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/getservent.3,v 1.15 2007/01/09 00:28:02 imp Exp $ .\" $DragonFly: src/lib/libc/net/getservent.3,v 1.2 2003/06/17 04:26:44 dillon Exp $ .\" .Dd July 9, 1995 @@ -100,7 +96,8 @@ reads the next line of the file, opening the file if necessary. The .Fn setservent function -opens and rewinds the file. If the +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 @@ -152,7 +149,7 @@ and functions appeared in .Bx 4.2 . .Sh BUGS -These functions use static data storage; +These functions use a thread-specific 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 diff --git a/lib/libc/net/if_indextoname.3 b/lib/libc/net/if_indextoname.3 index 4ebd6cae0a..a4d133e27a 100644 --- a/lib/libc/net/if_indextoname.3 +++ b/lib/libc/net/if_indextoname.3 @@ -22,10 +22,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/net/if_indextoname.3,v 1.2.2.6 2002/07/29 18:33:18 ume Exp $ -.\" $DragonFly: src/lib/libc/net/if_indextoname.3,v 1.5 2007/08/18 20:48:47 swildner Exp $ +.\" $FreeBSD: src/lib/libc/net/if_indextoname.3,v 1.11 2005/11/23 10:49:07 ru Exp $ +.\" $DragonFly: src/lib/libc/net/if_indextoname.3,v 1.5 2007/08/18 20:48:47 swildner Exp $ .\" -.Dd "July 11, 1997" +.Dd November 23, 2005 .Dt IF_NAMETOINDEX 3 .Os .Sh NAME @@ -37,12 +37,14 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h .In net/if.h -.Ft unsigned int +.Ft "unsigned int" .Fn if_nametoindex "const char *ifname" -.Ft char * +.Ft "char *" .Fn if_indextoname "unsigned int ifindex" "char *ifname" -.Ft struct if_nameindex * +.Ft "struct if_nameindex *" .Fn if_nameindex "void" .Ft void .Fn if_freenameindex "struct if_nameindex *ptr" @@ -50,31 +52,35 @@ The .Fn if_nametoindex function maps the interface name specified in -.Ar ifname +.Fa ifname to its corresponding index. If the specified interface does not exist, it returns 0. .Pp The .Fn if_indextoname function maps the interface index specified in -.Ar ifindex +.Fa ifindex to it corresponding name, which is copied into the buffer pointed to by -.Ar ifname , -which must be of at least IFNAMSIZ bytes. +.Fa ifname , +which must be of at least +.Dv IFNAMSIZ +bytes. This pointer is also the return value of the function. If there is no interface corresponding to the specified -index, NULL is returned. +index, +.Dv NULL +is returned. .Pp The .Fn if_nameindex function returns an array of -.Nm if_nameindex +.Vt if_nameindex structures, one structure per interface, as defined in the include file .In net/if.h . The -.Nm if_nameindex +.Vt if_nameindex structure contains at least the following entries: .Bd -literal unsigned int if_index; /* 1, 2, ... */ @@ -82,11 +88,14 @@ structure contains at least the following entries: .Ed .Pp The end of the array of structures is indicated by a structure with an -.Nm if_index +.Va if_index of 0 and an -.Nm if_name -of NULL. -A NULL pointer is returned upon an error. +.Va if_name +of +.Dv NULL . +A +.Dv NULL +pointer is returned upon an error. .Pp The .Fn if_freenameindex @@ -108,18 +117,24 @@ occurs while retrieving the list of interfaces via Upon successful completion, .Fn if_indextoname returns -.Ar ifname . -If the interface is not found, a NULL pointer is returned and +.Fa ifname . +If the interface is not found, a +.Dv NULL +pointer is returned and .Va errno is set to .Er ENXIO . -A NULL pointer is also returned if an error +A +.Dv NULL +pointer is also returned if an error occurs while retrieving the list of interfaces via .Xr getifaddrs 3 . .Pp The .Fn if_nameindex -returns a NULL pointer if an error +returns a +.Dv NULL +pointer if an error occurs while retrieving the list of interfaces via .Xr getifaddrs 3 , or if sufficient memory cannot be allocated. @@ -133,7 +148,8 @@ The .Fn if_nameindex , and .Fn if_freenameindex -functions conform to RFC 2553. +functions conform to +.%T "RFC 2553" . .Sh HISTORY -The implementation first appeared in BSDI +The implementation first appeared in BSDi .Bsx . diff --git a/lib/libc/net/if_nametoindex.c b/lib/libc/net/if_nametoindex.c index c40d78dca7..72ca99c0cd 100644 --- a/lib/libc/net/if_nametoindex.c +++ b/lib/libc/net/if_nametoindex.c @@ -23,19 +23,22 @@ * SUCH DAMAGE. * * BSDI Id: if_nametoindex.c,v 2.3 2000/04/17 22:38:05 dab Exp - * - * $FreeBSD: src/lib/libc/net/if_nametoindex.c,v 1.1.2.1 2002/07/29 18:33:18 ume Exp $ + * $FreeBSD: src/lib/libc/net/if_nametoindex.c,v 1.5 2003/05/01 19:03:14 nectar Exp $ * $DragonFly: src/lib/libc/net/if_nametoindex.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ */ +#include "namespace.h" #include #include +#include #include #include #include #include #include #include +#include +#include "un-namespace.h" /* * From RFC 2553: @@ -59,9 +62,21 @@ unsigned int if_nametoindex(const char *ifname) { + int s; + struct ifreq ifr; struct ifaddrs *ifaddrs, *ifa; unsigned int ni; + s = _socket(AF_INET, SOCK_DGRAM, 0); + if (s != -1) { + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + if (_ioctl(s, SIOCGIFINDEX, &ifr) != -1) { + _close(s); + return (ifr.ifr_index); + } + _close(s); + } + if (getifaddrs(&ifaddrs) < 0) return(0); diff --git a/lib/libc/net/inet.3 b/lib/libc/net/inet.3 index 4ee8ea90df..5ceb05e0d0 100644 --- a/lib/libc/net/inet.3 +++ b/lib/libc/net/inet.3 @@ -9,10 +9,6 @@ .\" 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. @@ -30,10 +26,10 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)inet.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.8.2.8 2001/12/01 21:15:38 cjc Exp $ +.\" $FreeBSD: src/lib/libc/net/inet.3,v 1.36 2007/06/14 07:13:28 delphij Exp $ .\" $DragonFly: src/lib/libc/net/inet.3,v 1.2 2003/06/17 04:26:44 dillon Exp $ .\" -.Dd June 17, 1996 +.Dd June 14, 2007 .Dt INET 3 .Os .Sh NAME @@ -41,6 +37,7 @@ .Nm inet_addr , .Nm inet_network , .Nm inet_ntoa , +.Nm inet_ntoa_r , .Nm inet_ntop , .Nm inet_pton , .Nm inet_makeaddr , @@ -62,10 +59,21 @@ .Fn inet_network "const char *cp" .Ft char * .Fn inet_ntoa "struct in_addr in" +.Ft char * +.Fo inet_ntoa_r +.Fa "struct in_addr in" +.Fa "char *buf" +.Fa "socklen_t size" +.Fc .Ft const char * -.Fn inet_ntop "int af" "const void *src" "char *dst" "size_t size" +.Fo inet_ntop +.Fa "int af" +.Fa "const void * restrict src" +.Fa "char * restrict dst" +.Fa "socklen_t size" +.Fc .Ft int -.Fn inet_pton "int af" "const char *src" "void *dst" +.Fn inet_pton "int af" "const char * restrict src" "void * restrict dst" .Ft struct in_addr .Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" .Ft in_addr_t @@ -90,7 +98,7 @@ as held in a character string) to network format (usually a .Ft struct in_addr or some other internal binary representation, in network byte order). It returns 1 if the address was valid for the specified address family, or -0 if the address wasn't parseable in the specified address family, or -1 +0 if the address was not parseable in the specified address family, or -1 if some system error occurred (in which case .Va errno will have been set). @@ -115,10 +123,22 @@ numbers, respectively. .Pp The function .Fn inet_ntop -converts an address from network format (usually a +converts an address +.Fa *src +from network format +(usually a .Ft struct in_addr or some other binary form, in network byte order) to presentation format (suitable for external display purposes). +The +.Fa size +argument specifies the size, in bytes, of the buffer +.Fa *dst . +.Dv INET_ADDRSTRLEN +and +.Dv INET6_ADDRSTRLEN +define the maximum size required to convert an address of the respective +type. It returns NULL if a system error occurs (in which case, .Va errno will have been set), or it returns a pointer to the destination string. @@ -133,11 +153,17 @@ takes an Internet address and returns an .Tn ASCII string representing the address in .Ql .\& -notation. The routine +notation. +The routine +.Fn inet_ntoa_r +is the reentrant version of +.Fn inet_ntoa . +The routine .Fn inet_makeaddr takes an Internet network number and a local network address and constructs an Internet address -from it. The routines +from it. +The routines .Fn inet_netof and .Fn inet_lnaof @@ -163,7 +189,8 @@ a .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 +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 @@ -202,18 +229,6 @@ 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 @@ -222,10 +237,27 @@ is returned by and .Fn inet_network for malformed requests. +.Sh ERRORS +The +.Fn inet_ntop +call fails if: +.Bl -tag -width Er +.It Bq Er ENOSPC +.Fa size +was not large enough to store the presentation form of the address. +.It Bq Er EAFNOSUPPORT +.Fa *src +was not an +.Dv AF_INET +or +.Dv AF_INET6 +family address. +.El .Sh SEE ALSO -.Xr addr2ascii 3 , .Xr byteorder 3 , +.Xr getaddrinfo 3 , .Xr gethostbyname 3 , +.Xr getnameinfo 3 , .Xr getnetent 3 , .Xr inet_net 3 , .Xr hosts 5 , @@ -268,5 +300,7 @@ The string returned by .Fn inet_ntoa resides in a static memory area. .Pp -Inet_addr should return a +The +.Fn inet_addr +function should return a .Fa struct in_addr . diff --git a/lib/libc/net/inet6_option_space.3 b/lib/libc/net/inet6_option_space.3 index 03a094b150..1d66e24719 100644 --- a/lib/libc/net/inet6_option_space.3 +++ b/lib/libc/net/inet6_option_space.3 @@ -1,6 +1,4 @@ .\" $KAME: inet6_option_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $ -.\" $FreeBSD: src/lib/libc/net/inet6_option_space.3,v 1.16 2005/01/23 16:02:48 gnn Exp $ -.\" $DragonFly: src/lib/libc/net/inet6_option_space.3,v 1.8 2008/04/20 22:24:53 swildner Exp $ .\" .\" Copyright (C) 2004 WIDE Project. .\" All rights reserved. @@ -29,7 +27,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 23, 2004 +.\" $FreeBSD: src/lib/libc/net/inet6_option_space.3,v 1.18 2005/01/24 18:14:18 ru Exp $ +.\" $DragonFly: src/lib/libc/net/inet6_option_space.3,v 1.8 2008/04/20 22:24:53 swildner Exp $ +.\" +.Dd January 24, 2005 .Dt INET6_OPTION_SPACE 3 .Os .\" @@ -42,395 +43,13 @@ .Nm inet6_option_find .Nd IPv6 Hop-by-Hop and Destination Option Manipulation .\" -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In sys/types.h -.In netinet/in.h -.Ft "int" -.Fn inet6_option_space "int nbytes" -.Ft "int" -.Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type" -.Ft "int" -.Fn inet6_option_append "struct cmsghdr *cmsg" "const u_int8_t *typep" "int multx" "int plusy" -.Ft "u_int8_t *" -.Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy" -.Ft "int" -.Fn inet6_option_next "const struct cmsghdr *cmsg" "u_int8_t **tptrp" -.Ft "int" -.Fn inet6_option_find "const struct cmsghdr *cmsg" "u_int8_t **tptrp" "int type" -.\" .Sh DESCRIPTION -.\" -Manipulating and parsing IPv6's Hop-by-Hop and Destination options is -complicated by the need to properly align and pad data as well as the -need to manipulate ancillary information that is not part of the data -stream. -RFC 2292 defines a set of functions, which are implemented as -part of the Kame libraries, to support help developers create, change, -and parse Hop-by-Hope and Destination options. -All of the prototypes -for the option functions are defined in the -.In netinet/in.h -header file. -.\" -.Ss inet6_option_space -In order to determine the amount of space necessary to hold any option -the -.Fn inet6_option_space -function is called. -It returns the number of bytes required to hold -an option when it is stored as ancillary data, including the -.Li cmsghdr -structure at the beginning, and any necessary padding at the end. -The -.Li nbytes -argument indicates the size of the structure defining the option, -and must include any pad bytes at the beginning (the value -.Li y -in the alignment term -.Dq Li "xn + y" ) , -the type byte, the length byte, and the option data. -.Pp -Note: If multiple options are stored in a single ancillary data -object, which is the recommended technique, the -.Fn inet6_option_space -function overestimates the amount of space required by the size of -.Li N-1 -.Li cmsghdr -structures, where -.Li N -is the number of options to be stored in the object. -Usually this has -no impact because it is assumed that most Hop-by-Hop and Destination -option headers carry only one option as indicated in appendix B of RFC 2460. -.\" -.Ss inet6_option_init -The -.Fn inet6_option_init -function is called to initialize any ancillary data object that will contain -a Hop-by-Hop or Destination option. -It returns -.Li 0 -on success and -.Li -1 -when an error occurs. -.Pp -The -.Fa bp -argument points to a previously allocated area of memory which must be -large enough to contain all the arguments that the application indents -to add later via -.Fn inet6_option_append -and -.Fn inet6_option_alloc -routines. -.Pp -The -.Fa cmsgp -argument is a pointer to a pointer to a -.Li cmsghdr -structure. -The -.Fa *cmsgp -argument -points to a -.Li cmsghdr -structure which is constructed by this function and stored in the -area of memory pointed to by -.Fa bp . -.Pp -The -.Fa type -is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS -and is stored in the -.Li cmsg_type -member of the -.Li cmsghdr -structure mentioned above. -.\" -.Ss inet6_option_append -This function appends a Hop-by-Hop option or a Destination option into -an ancillary data object previously initialized by a call to -.Fn inet6_option_init . -The -.Fn inet6_option_append -function returns -.Li 0 -if it succeeds or -.Li -1 -when an error occurs. -.Pp -The -.Fa cmsg -argument is a pointer to the -.Li cmsghdr -structure that was initialized by a call to -.Fn inet6_option_init . -.Pp -The -.Fa typep -argument is a pointer to the 8-bit option type. -All options are -encoded as type-length-value tuples and it is assumed that -the -.Fa typep -field is immediately followed by the 8-bit option data length field, -which is then followed by the option data. -.Pp -The option types of -.Li 0 -and -.Li 1 are reserved for the -.Li Pad1 -and -.Li PadN -options respectively. -All other values from -.Li 2 -through -.Li 255 -are available for applications to use. -.Pp -The option data length, since it is stored in 8 bites, must have a -value between -.Li 0 -and -.Li 255 , -inclusive. -.Pp -The -.Fa multx -argument -is the value -.Li x -in the alignment term -.Dq Li xn + y -and indicates the byte alignment necessary for the data. -Alignments may be specified as -.Li 1 , -.Li 2 , -.Li 4 , -or -.Li 8 -bytes, which is no alignment, 16 bit, 32 bit and 64 bit alignments -respectively. -.Pp -The -.Fa plusy -argument -is the value -.Li y -in the alignment term -.Dq Li xn + y -and must have a value between -.Li 0 -and -.Li 7 , -inclusive, indicating the amount of padding that is necessary for an -option. -.\" -.Ss inet6_option_alloc -The -.Fn inet6_option_alloc -function appends a Hop-by-Hop option or a Destination option into an -ancillary data object that has previously been initialized by a call to -.Fn inet6_option_init . -The -.Fn inet6_option_alloc -function returns a pointer to the 8-bit option type field that at the -beginning of the allocated the option on success, or -.Dv NULL -on an error. -.Pp -The difference between the -.Fn inet6_option_alloc -and -.Fn inet6_option_append -functions is that the latter copies the contents of a previously built -option into the ancillary data object while the former returns a -pointer to the place in the data object where the option's TLV must -then be built by the application. -.Pp -The -.Fa cmsg -argument is a pointer to a -.Li cmsghdr -structure that was initialized by -.Fn inet6_option_init . -.Pp -The -.Fa datalen -argument is the value of the option data length byte for this option. -This value is required as an argument to allow the function to -determine if padding must be appended at the end of the option. -(The -.Fn inet6_option_append -function does not need a data length argument -since the option data length must already be stored by the caller) -.Pp -The -.Fa multx -and -.Fa plusy -arguments -are identical to the arguments of the same name described in the -.Fn inet6_option_init -function above. -.\" -.Ss inet6_option_next -The -.Fn inet6_option_next -function is used to process Hop-by-Hop and Destination options that -are present in an ancillary data object. -When an option remains to -be processed, the return value of the -.Fn inet6_option_next -function is -.Li 0 -and the -.Fa *tptrp -argument points to the 8-bit option type field, which is followed by -the 8-bit option data length, and then the option data. -When no more -options remain to be processed, the return value is -.Li -1 -and -.Fa *tptrp -is -.Dv NULL -and when an error occurs, the return value is -.Li -1 -but the -.Fa *tptrp -argument is not -.Dv NULL . -This set of return values allows a program to easily loop through all -the options in an ancillary data object, checking for the error and -end of stream conditions along the way. -.Pp -When a valid option is returned the -.Fa cmsg -argument points to a -.Li cmsghdr -where the -.Li cmsg_level -equals -.Dv IPPROTO_IPV6 -and -.Li cmsg_type -is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS . -.Pp -The -.Fa tptrp -argument is a pointer to a pointer to an 8-bit byte and -.Fa *tptrp -is used by the function to remember its place in the ancillary data -object each time the function is called. -When the -.Fn inet6_option_next -function is called for the first time on a given ancillary data object, -.Fa *tptrp -must be set to -.Dv NULL . -.Pp -Each time the function returns success, -the -.Fa *tptrp -argument points to the 8-bit option type field for the next option to -be processed. -.\" -.Ss inet6_option_find -The -.Fn inet6_option_find -function allows an application to search for a particular option type -in an ancillary data object. -The -.Fa cmsg -argument is a pointer to -.Li cmsghdr -structure in which the -.Li cmsg_level -element equals -.Dv IPPROTO_IPV6 -and the -.Li cmsg_type -element is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS . -.Pp -The -.Fa tptrp -argument is handled exactly as in the -.Fn inet6_option_next -function described above. -.Pp -The -.Fn inet6_option_find -function starts searching for an option of the specified type -beginning after the value of -.Fa *tptrp . -.\" -.Sh EXAMPLES -RFC 2292 gives comprehensive examples in chapter 6. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_option_init -and -.Fn inet6_option_append -functions return -.Li 0 -on success or -.Li -1 -on an error. -.Pp -The -.Fn inet6_option_alloc -function returns -.Dv NULL -on an error. -.Pp -When -.Fn inet6_option_next -or -.Fn inet6_option_find -detect an error they return -.Li -1 -setting -.Fa *tptrp -to non -.Dv NULL -value. -.\" +The functions that were documented in this manual page are now +deprecated in favor of those described in +.Xr inet6_opt_init 3 . +Please refer to that manual page for information on how to manipulate +IPv6 Hop-by-Hop and Destination options. .Sh SEE ALSO -.Rs -.%A W. Stevens -.%A M. Thomas -.%T "Advanced Sockets API for IPv6" -.%N RFC 2292 -.%D February 1998 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.\" -.Sh STANDARDS -The functions are documented in -.Dq Advanced Sockets API for IPv6 -(RFC 2292). +.Xr inet6_opt_init 3 .\" -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. .\" diff --git a/lib/libc/net/inet6_rthdr_space.3 b/lib/libc/net/inet6_rthdr_space.3 index 91f3f293fb..fef67b84b2 100644 --- a/lib/libc/net/inet6_rthdr_space.3 +++ b/lib/libc/net/inet6_rthdr_space.3 @@ -1,6 +1,4 @@ .\" $KAME: inet6_rthdr_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $ -.\" $FreeBSD: src/lib/libc/net/inet6_rthdr_space.3,v 1.14 2005/01/23 16:02:48 gnn Exp $ -.\" $DragonFly: src/lib/libc/net/inet6_rthdr_space.3,v 1.5 2007/11/23 23:16:36 swildner Exp $ .\" .\" Copyright (C) 2004 WIDE Project. .\" All rights reserved. @@ -29,7 +27,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 27, 2004 +.\" $FreeBSD: src/lib/libc/net/inet6_rthdr_space.3,v 1.16 2005/01/24 18:14:18 ru Exp $ +.\" $DragonFly: src/lib/libc/net/inet6_rthdr_space.3,v 1.5 2007/11/23 23:16:36 swildner Exp $ +.\" +.Dd January 24, 2005 .Dt INET6_RTHDR_SPACE 3 .Os .\" @@ -44,263 +45,14 @@ .Nm inet6_rthdr_getflags .Nd IPv6 Routing Header Options Manipulation .\" -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In sys/types.h -.In netinet/in.h -.Ft size_t -.Fn inet6_rthdr_space "int type" "int segments" -.Ft "struct cmsghdr *" -.Fn inet6_rthdr_init "void *bp" "int type" -.Ft int -.Fn inet6_rthdr_add "struct cmsghdr *cmsg" "const struct in6_addr *addr" "unsigned int flags" -.Ft int -.Fn inet6_rthdr_lasthop "struct cmsghdr *cmsg" "unsigned int flags" -.Ft int -.Fn inet6_rthdr_reverse "const struct cmsghdr *in" "struct cmsghdr *out" -.Ft int -.Fn inet6_rthdr_segments "const struct cmsghdr *cmsg" -.Ft "struct in6_addr *" -.Fn inet6_rthdr_getaddr "struct cmsghdr *cmsg" "int index" -.Ft int -.Fn inet6_rthdr_getflags "const struct cmsghdr *cmsg" "int index" -.\" .Sh DESCRIPTION -.\"The RFC 2292 IPv6 Advanced API has been deprecated in favor of the -.\"newer, RFC 3542 APIs. -.\"On platforms that support it, currently only -.\"FreeBSD, please use the newer API to manipulate routing header -.\"options. -.\".Pp -The RFC 2292 IPv6 Advanced API defined eight functions for -applications to use for building and parsing routing headers. -The -eight functions are split into two groups, the first of which builds -the header and the second of which can parse it. -The function prototypes for these functions are all in the -.In netinet/in.h -header. -Although direct manipulation of a routing header is possible -this set of APIs make it unnecessary and such direct manipulation -should be avoided so that changes to the underlying structures do not -break applications. -.Pp -Please note that RFC 2292 uses the term -.Dq segments -instead of the term -.Dq addresses -but they are considered equivalent for this manual page. -.\" -.Ss inet6_rthdr_space -The -.Fn inet6_rthdr_space -function returns the number of bytes required to hold a routing header -of the specified -.Fa type -and containing the specified number of -.Fa segments . -Only one -.Fa type -is supported, -.Dv IPV6_RTHDR_TYPE_0 , -and it can hold from 1 to 23 segments. -The return value includes the -size of the cmsghdr structure that precedes the routing header, and -any required padding. -.Pp -A return value of 0 indicates an error. -Either the type was specified -incorrectly, or the number of segments was less than one or greater -than 23. -.Pp -Note: The -.Fn inet6_rthdr_space -function only returns the size required by the routing header and does -not allocate memory for the caller. -.\" -.Ss inet6_rthdr_init -The -.Fn inet6_rthdr_init -function initializes a buffer, pointed to by -.Fa bp -with an appropriate -.Li cmsghdr -structure followed by a routing header of the specified -.Fa type . -.Pp -The caller must use the -.Fn inet6_rthdr_space -function to determine the size of the buffer, and then allocate that -buffer before calling -.Fn inet6_rthdr_init . -.Pp -The return value is a pointer to a -.Li cmsghdr -structure, which is used as the first argument to the -.Fn inet6_rthdr_add -and -.Fn inet6_rthdr_lasthop -functions in order to construct the routing header. -When an error occurs the return value is -.Dv NULL . -.\" -.Ss inet6_rthdr_add -The -.Fn inet6_rthdr_add -function adds the IPv6 address pointed to by -.Fa addr -to the end of the -routing header being constructed and sets the type of this address to the -value of -.Fa flags . -The -.Fa flags -must be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT -indicating whether loose or strict source routing is required. -.Pp -When the function succeeds it returns 0, otherwise \-1 is returned. -.\" -.Ss inet6_rthdr_lasthop -The -.Fn inet6_rthdr_lasthop -function specifies the strict or loose flag for the final hop of a -routing header. -The -.Fa flags -must be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT . -.Pp -The return value of the function is 0 upon success, and \-1 when an -error has occurred. -.Pp -Please note that a routing header specifying -.Li N -intermediate nodes requires -.Li N+1 -strict or loose flags meaning that -.Fn inet6_rthdr_add -must be called -.Li N -times and then -.Fn inet6_rthdr_lasthop -must be called once. -.\" -.Ss inet6_rthdr_reverse -This function was never implemented. -.Pp -The following four functions provide an API for parsing a received -routing header. -.\" -.Ss inet6_rthdr_segments -The -.Fn inet6_rthdr_segments -function returns the number of segments contained in the Routing -header pointed to by the -.Fa cmsg -argument. -On success the return value is from 1 to 23. -When an error occurs \-1 is returned. -.\" -.Ss inet6_rthdr_getaddr -The -.Fn inet6_rthdr_getaddr -function returns a pointer to the IPv6 address specified by the -.Fa index -argument from the routing header pointed to by -.Fa cmsg . -The index must be between 1 and the number returned by -.Fn inet6_rthdr_segments -described above. -An application must call -.Fn inet6_rthdr_segments -to obtain the number of segments in the routing header. -.Pp -If an error occurs the -.Dv NULL -is returned. -.\" -.Ss inet6_rthdr_getflags -The -.Fn inet6_rthdr_getflags -function returns the flags value of the segment specified by -.Fa index -of the routing header pointed to by -.Fa cmsg . -The -.Fa index -argument must be between 0 and the value returned by -.Fn inet6_rthdr_segments . -The return value will be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT -indicating whether loose or strict source routing was requested for -that segment. -.Pp -When an error occurs \-1 is returned. -.Pp -Note: Flags begin at index 0 while segments begin at index 1, to -maintain consistency with the terminology and figures in RFC 2460. -.\" -.Sh EXAMPLES -RFC 2292 gives comprehensive examples in chapter 8. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_rthdr_space -function returns 0 when an error occurs. -.Pp -The -.Fn inet6_rthdr_add , -.Fn inet6_rthdr_lasthop -functions return 0 on success, and \-1 on error. -.Pp -The -.Fn inet6_rthdr_init -and -.Fn inet6_rthdr_getaddr -functions -return -.Dv NULL -on error. -.Pp -The -.Fn inet6_rthdr_segments -and -.Fn inet6_rthdr_getflags -functions return -1 on error. +The RFC 2292 IPv6 Advanced API has been deprecated in favor of the +newer, RFC 3542 APIs documented in +.Xr inet6_rth_space 3 . +On platforms that support it, currently only +.Fx , +please use the newer API to manipulate routing header +options. .\" .Sh SEE ALSO -.Rs -.%A W. Stevens -.%A M. Thomas -.%T "Advanced Sockets API for IPv6" -.%N RFC 2292 -.%D February 1998 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.\" -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. -.\" -.Sh BUGS -The -.Fn inet6_rthdr_reverse -function was never implemented. -.\".Pp -.\"This API is deprecated in favor of -.\".Xr inet6_rth_space 3 -.\".Sh SEE ALSO -.\".Xr inet6_rth_space 3 +.Xr inet6_rth_space 3 diff --git a/lib/libc/net/inet_net.3 b/lib/libc/net/inet_net.3 index f9ed46e7b1..20a138afb9 100644 --- a/lib/libc/net/inet_net.3 +++ b/lib/libc/net/inet_net.3 @@ -14,10 +14,6 @@ .\" 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 NetBSD -.\" Foundation, Inc. and its contributors. .\" 4. Neither the name of The NetBSD Foundation nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific prior written permission. @@ -34,10 +30,10 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.1.2.1 2001/09/03 08:46:42 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/inet_net.3,v 1.4 2007/01/09 00:28:02 imp Exp $ .\" $DragonFly: src/lib/libc/net/inet_net.3,v 1.3 2006/03/26 22:56:56 swildner Exp $ .\" -.Dd June 18, 1997 +.Dd February 26, 2006 .Dt INET_NET 3 .Os .Sh NAME @@ -62,7 +58,9 @@ function converts an Internet network number from network format (usually a .Vt "struct in_addr" or some other binary form, in network byte order) to CIDR presentation format (suitable for external display purposes). +The .Fa bits +argument is the number of bits in .Fa src that are the network number. @@ -87,11 +85,15 @@ It will be set to .Er ENOENT if the Internet network number was not valid). .Pp -The only value for +The currently supported values for .Fa af -currently supported is -.Dv AF_INET . +are +.Dv AF_INET +and +.Dv AF_INET6 . +The .Fa size +argument is the size of the result buffer .Fa dst . .Sh NETWORK NUMBERS (IP VERSION 4) @@ -145,6 +147,10 @@ may be decimal, octal, or hexadecimal, as specified in the C language (i.e., a leading 0x or 0X implies hexadecimal; otherwise, a leading 0 implies octal; otherwise, the number is interpreted as decimal). +.\" +.\" .Sh NETWORK NUMBERS (IP VERSION 6) +.\" XXX - document this! +.\" .Sh SEE ALSO .Xr byteorder 3 , .Xr inet 3 , diff --git a/lib/libc/net/ip6opt.c b/lib/libc/net/ip6opt.c index 938c73f89e..0615ccfda6 100644 --- a/lib/libc/net/ip6opt.c +++ b/lib/libc/net/ip6opt.c @@ -1,3 +1,5 @@ +/* $KAME: ip6opt.c,v 1.13 2003/06/06 10:08:20 suz Exp $ */ + /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * All rights reserved. @@ -26,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/net/ip6opt.c,v 1.1 1999/12/16 18:32:01 shin Exp $ + * $FreeBSD: src/lib/libc/net/ip6opt.c,v 1.8 2005/07/19 18:13:58 ume Exp $ * $DragonFly: src/lib/libc/net/ip6opt.c,v 1.6 2007/05/29 10:58:11 hasso Exp $ */ @@ -120,6 +122,7 @@ inet6_option_append(struct cmsghdr *cmsg, const u_int8_t *typep, int multx, padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - (off % multx); padlen += plusy; + padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ inet6_insert_padopt(bp, padlen); cmsg->cmsg_len += padlen; @@ -189,6 +192,7 @@ inet6_option_alloc(struct cmsghdr *cmsg, int datalen, int multx, int plusy) padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - (off % multx); padlen += plusy; + padlen %= multx; /* keep the pad as short as possible */ /* insert padding */ inet6_insert_padopt(bp, padlen); cmsg->cmsg_len += padlen; @@ -296,7 +300,7 @@ inet6_option_find(const struct cmsghdr *cmsg, u_int8_t **tptrp, int type) ip6e = (struct ip6_ext *)CMSG_DATA(cmsg); hdrlen = (ip6e->ip6e_len + 1) << 3; if (cmsg->cmsg_len < CMSG_SPACE(hdrlen)) - return(-1); + return(-1); /* * If the caller does not specify the starting point, @@ -354,16 +358,16 @@ static void inet6_insert_padopt(u_char *p, int len) { switch(len) { - case 0: - return; - case 1: - p[0] = IP6OPT_PAD1; - return; - default: - p[0] = IP6OPT_PADN; - p[1] = len - 2; - memset(&p[2], 0, len - 2); - return; + case 0: + return; + case 1: + p[0] = IP6OPT_PAD1; + return; + default: + p[0] = IP6OPT_PADN; + p[1] = len - 2; + memset(&p[2], 0, len - 2); + return; } } @@ -378,15 +382,15 @@ inet6_opt_init(void *extbuf, socklen_t extlen) struct ip6_ext *ext = (struct ip6_ext *)extbuf; if (extlen < 0 || (extlen % 8)) - return (-1); + return(-1); if (ext) { if (extlen == 0) - return (-1); + return(-1); ext->ip6e_len = (extlen >> 3) - 1; } - return (2); /* sizeof the next and the length fields */ + return(2); /* sizeof the next and the length fields */ } int @@ -399,28 +403,24 @@ inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, * The option type must have a value from 2 to 255, inclusive. * (0 and 1 are reserved for the Pad1 and PadN options, respectively.) */ -#if 0 /* always false */ - if (type < 2 || type > 255) -#else if (type < 2) -#endif - return (-1); + return(-1); /* * The option data length must have a value between 0 and 255, * inclusive, and is the length of the option data that follows. */ if (len < 0 || len > 255) - return (-1); + return(-1); /* * The align parameter must have a value of 1, 2, 4, or 8. * The align value can not exceed the value of len. */ if (align != 1 && align != 2 && align != 4 && align != 8) - return (-1); + return(-1); if (align > len) - return (-1); + return(-1); /* Calculate the padding length. */ currentlen += 2 + len; /* 2 means "type + len" */ @@ -431,7 +431,7 @@ inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, currentlen += padlen; if (extlen && /* XXX: right? */ currentlen > extlen) - return (-1); + return(-1); if (extbuf) { u_int8_t *optp = (u_int8_t *)extbuf + offset; @@ -454,7 +454,7 @@ inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, *databufp = optp; } - return (currentlen); + return(currentlen); } int @@ -467,7 +467,7 @@ inet6_opt_finish(void *extbuf, socklen_t extlen, int offset) int padlen = updatelen - offset; if (updatelen > extlen) - return (-1); + return(-1); padp = (u_int8_t *)extbuf + offset; if (padlen == 1) @@ -479,7 +479,7 @@ inet6_opt_finish(void *extbuf, socklen_t extlen, int offset) } } - return (updatelen); + return(updatelen); } int @@ -487,7 +487,7 @@ inet6_opt_set_val(void *databuf, int offset, void *val, socklen_t vallen) { memcpy((u_int8_t *)databuf + offset, val, vallen); - return (offset + vallen); + return(offset + vallen); } int @@ -499,7 +499,7 @@ inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, /* Validate extlen. XXX: is the variable really necessary?? */ if (extlen == 0 || (extlen % 8)) - return (-1); + return(-1); lim = (u_int8_t *)extbuf + extlen; /* @@ -514,7 +514,7 @@ inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, /* Find the next option skipping any padding options. */ while (optp < lim) { - switch(*optp) { + switch (*optp) { case IP6OPT_PAD1: optp++; break; @@ -529,13 +529,13 @@ inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, *typep = *optp; *lenp = optlen - 2; *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); + return(optp + optlen - (u_int8_t *)extbuf); } } optend: *databufp = NULL; /* for safety */ - return (-1); + return(-1); } int @@ -547,7 +547,7 @@ inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, /* Validate extlen. XXX: is the variable really necessary?? */ if (extlen == 0 || (extlen % 8)) - return (-1); + return(-1); lim = (u_int8_t *)extbuf + extlen; /* @@ -568,7 +568,7 @@ inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, if (*optp == type) { /* found */ *lenp = optlen - 2; *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); + return(optp + optlen - (u_int8_t *)extbuf); } optp += optlen; @@ -576,7 +576,7 @@ inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, optend: *databufp = NULL; /* for safety */ - return (-1); + return(-1); } int @@ -586,5 +586,5 @@ inet6_opt_get_val(void *databuf, int offset, void *val, socklen_t vallen) /* we can't assume alignment here */ memcpy(val, (u_int8_t *)databuf + offset, vallen); - return (offset + vallen); + return(offset + vallen); } diff --git a/lib/libc/net/iso_addr.3 b/lib/libc/net/iso_addr.3 deleted file mode 100644 index c578a06831..0000000000 --- a/lib/libc/net/iso_addr.3 +++ /dev/null @@ -1,114 +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 -.\" $FreeBSD: src/lib/libc/net/iso_addr.3,v 1.3.2.4 2001/12/14 18:33:55 ru Exp $ -.\" $DragonFly: src/lib/libc/net/iso_addr.3,v 1.2 2003/06/17 04:26:44 dillon Exp $ -.\" -.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 LIBRARY -.Lb libc -.Sh SYNOPSIS -.In sys/types.h -.In 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 -ragged -offset indent -.. -.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 2019f41030..0000000000 --- a/lib/libc/net/iso_addr.c +++ /dev/null @@ -1,112 +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. 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.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/net/iso_addr.c,v 1.4 2005/09/19 09:34:53 asmodai Exp $ - */ - -#include -#include -#include - -/* 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) - const char *addr; -{ - static struct iso_addr out_addr; - char *cp = out_addr.isoa_genaddr; - char *cplim = cp + sizeof(out_addr.isoa_genaddr); - 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 index 8f969d4b0e..ffe942e2f9 100644 --- a/lib/libc/net/linkaddr.3 +++ b/lib/libc/net/linkaddr.3 @@ -12,10 +12,6 @@ .\" 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. @@ -33,10 +29,10 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)linkaddr.3 8.1 (Berkeley) 7/28/93 -.\" $FreeBSD: src/lib/libc/net/linkaddr.3,v 1.8.2.4 2001/12/14 18:33:55 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/linkaddr.3,v 1.16 2007/02/28 21:18:38 bms Exp $ .\" $DragonFly: src/lib/libc/net/linkaddr.3,v 1.3 2008/11/23 21:55:52 swildner Exp $ .\" -.Dd June 17, 1996 +.Dd February 28, 2007 .Dt LINK_ADDR 3 .Os .Sh NAME @@ -97,28 +93,26 @@ 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 +The .Fn link_ntoa +function always returns a null terminated string. +The .Fn link_addr +function has no return value. (See .Sx BUGS . ) .Sh SEE ALSO -.Xr addr2ascii 3 -.\" .Xr iso 4 +.Xr getnameinfo 3 .Sh HISTORY The .Fn link_addr and .Fn link_ntoa functions appeared in -.Bx 4.3 Reno . +.Bx 4.3 Reno . .Sh BUGS The returned values for .Fn link_ntoa diff --git a/lib/libc/net/linkaddr.c b/lib/libc/net/linkaddr.c index d4193089f5..4c99e9332d 100644 --- a/lib/libc/net/linkaddr.c +++ b/lib/libc/net/linkaddr.c @@ -27,6 +27,7 @@ * SUCH DAMAGE. * * @(#)linkaddr.c 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/lib/libc/net/linkaddr.c,v 1.4 2007/01/09 00:28:02 imp Exp $ * $DragonFly: src/lib/libc/net/linkaddr.c,v 1.5 2005/11/13 02:04:47 swildner Exp $ */ diff --git a/lib/libc/net/map_v4v6.c b/lib/libc/net/map_v4v6.c index 77cbf58b9a..0bad15007f 100644 --- a/lib/libc/net/map_v4v6.c +++ b/lib/libc/net/map_v4v6.c @@ -49,7 +49,7 @@ * --Copyright-- * * @(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93 - * $FreeBSD: src/lib/libc/net/map_v4v6.c,v 1.5.2.1 2001/03/05 10:47:08 obrien Exp $ + * $FreeBSD: src/lib/libc/net/map_v4v6.c,v 1.10 2007/01/09 00:28:02 imp Exp $ * $DragonFly: src/lib/libc/net/map_v4v6.c,v 1.4 2005/11/13 02:04:47 swildner Exp $ */ @@ -76,23 +76,22 @@ void _map_v4v6_address(const char *src, char *dst) { u_char *p = (u_char *)dst; - char tmp[INADDRSZ]; + char tmp[NS_INADDRSZ]; int i; /* Stash a temporary copy so our caller can update in place. */ - bcopy(src, tmp, INADDRSZ); + memcpy(tmp, src, NS_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); + memcpy((void*)p, tmp, NS_INADDRSZ); } void -_map_v4v6_hostent(struct hostent *hp, char **bpp, int *lenp) -{ +_map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) { char **ap; if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ) @@ -100,18 +99,19 @@ _map_v4v6_hostent(struct hostent *hp, char **bpp, int *lenp) 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)); + int i = (u_long)*bpp % sizeof(align); + + if (i != 0) + i = sizeof(align) - i; - if (*lenp < (i + IN6ADDRSZ)) { - /* Out of memory. Truncate address list here. XXX */ + if ((ep - *bpp) < (i + IN6ADDRSZ)) { + /* Out of memory. Truncate address list here. */ *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 3a0ea7b74a..0000000000 --- a/lib/libc/net/ns.3 +++ /dev/null @@ -1,134 +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 -.\" $FreeBSD: src/lib/libc/net/ns.3,v 1.5.2.5 2001/12/14 18:33:55 ru Exp $ -.\" $DragonFly: src/lib/libc/net/ns.3,v 1.2 2003/06/17 04:26:44 dillon Exp $ -.\" -.Dd June 4, 1993 -.Dt NS 3 -.Os -.Sh NAME -.Nm ns_addr , -.Nm ns_ntoa -.Nd Xerox -.Tn NS Ns (tm) -address conversion routines -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.In sys/types.h -.In 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 -ragged -offset indent -.. -.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 e4904a3a46..0000000000 --- a/lib/libc/net/ns_addr.c +++ /dev/null @@ -1,215 +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. 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. - * - * $FreeBSD: src/lib/libc/net/ns_addr.c,v 1.3.6.2 2001/07/04 22:34:51 kris Exp $ - * $DragonFly: src/lib/libc/net/ns_addr.c,v 1.5 2005/11/13 02:04:47 swildner Exp $ - * - * @(#)ns_addr.c 8.1 (Berkeley) 6/7/93 - */ - -#include -#include -#include -#include - -static struct ns_addr addr, zero_addr; - -static void Field(), cvtbase(); - -struct ns_addr -ns_addr(const char *name) -{ - char separator; - char *hostname, *socketname, *cp; - char buf[50]; - - 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 preferred - * form 2-272.AA001234H.01777, i.e. XDE standard. - * Great efforts are made to insure backward compatibility. - */ - 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(char *buf, u_char *out, int len) -{ - 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) { - sscanf(bp, fmt, hp); - bp[0] = 0; - hp--; - bp -= 3; - } - sscanf(buf, fmt, hp); - cvtbase((long)ibase, 256, hb, i, out, len); -} - -static void -cvtbase(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 3e2fc46a57..0000000000 --- a/lib/libc/net/ns_ntoa.c +++ /dev/null @@ -1,104 +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. 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_ntoa.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/net/ns_ntoa.c,v 1.7 2005/09/19 09:34:53 asmodai Exp $ - */ - -#include -#include -#include - - -static char *spectHex(char *); - -char * -ns_ntoa(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); - char *cp; - char *cp2; - u_char *up = addr.x_host.c_host; - u_char *uplim = up + 6; - - net.net_e = addr.x_net; - sprintf(obuf, "%lx", (u_long)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(char *p0) -{ - int ok = 0; - int nonzero = 0; - char *p = p0; - - for (; *p; p++) { - switch (*p) { - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - *p += ('A' - 'a'); - /* FALLTHROUGH */ - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - ok = 1; - /* FALLTHROUGH */ - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - nonzero = 1; - } - } - /* If we hit only digits in [1-9], add `H' to signal hex base */ - 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 ac779db9d0..0000000000 --- a/lib/libc/net/nsap_addr.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 1996, 1998 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. - * - * $FreeBSD: src/lib/libc/net/nsap_addr.c,v 1.7 1999/08/28 00:00:15 peter Exp $ - * $DragonFly: src/lib/libc/net/nsap_addr.c,v 1.4 2005/11/13 02:04:47 swildner Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -static char -xtob(int c) -{ - return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); -} - -u_int -inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) -{ - u_char c, nib; - u_int len = 0; - - while ((c = *ascii++) != '\0' && len < (u_int)maxlen) { - if (c == '.' || c == '+' || c == '/') - continue; - if (!isascii(c)) - return (0); - if (islower(c)) - c = toupper(c); - if (isxdigit(c)) { - nib = xtob(c); - c = *ascii++; - if (c != '\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(int binlen, const u_char *binary, char *ascii) -{ - 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); -} - -/* - * Weak aliases for applications that use certain private entry points, - * and fail to include . - */ -#undef inet_nsap_addr -__weak_reference(__inet_nsap_addr, inet_nsap_addr); -#undef inet_nsap_ntoa -__weak_reference(__inet_nsap_ntoa, inet_nsap_ntoa); diff --git a/lib/libc/net/ntoh.c b/lib/libc/net/ntoh.c new file mode 100644 index 0000000000..be0c51b165 --- /dev/null +++ b/lib/libc/net/ntoh.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2006 Olivier Houchard + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION 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. + * + * $FreeBSD: src/lib/libc/net/ntoh.c,v 1.1 2006/11/06 22:07:47 cognet Exp $ + */ + +#include + +uint32_t +htonl(uint32_t hl) +{ + return (__htonl(hl)); +} + +uint16_t +htons(uint16_t hs) +{ + return (__htons(hs)); +} + +uint32_t +ntohl(uint32_t nl) +{ + return (__ntohl(nl)); +} + +uint16_t +ntohs(uint16_t ns) +{ + return (__ntohs(ns)); +} diff --git a/lib/libc/net/rcmd.3 b/lib/libc/net/rcmd.3 index 035a38ff21..4dcbca73c4 100644 --- a/lib/libc/net/rcmd.3 +++ b/lib/libc/net/rcmd.3 @@ -9,10 +9,6 @@ .\" 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. @@ -30,7 +26,7 @@ .\" SUCH DAMAGE. .\" .\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/net/rcmd.3,v 1.12.2.8 2001/12/14 18:33:55 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/rcmd.3,v 1.27 2008/12/14 22:48:48 murray Exp $ .\" $DragonFly: src/lib/libc/net/rcmd.3,v 1.4 2007/11/23 23:16:36 swildner Exp $ .\" .Dd March 3, 2000 @@ -106,9 +102,9 @@ 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 +.Dv stdin and -.Em stdout . +.Dv stdout . If .Fa fd2p is non-zero, then an auxiliary channel to a control @@ -124,10 +120,10 @@ forwarded to the process group of the command. If .Fa fd2p is 0, then the -.Em stderr +.Dv stderr (unit 2 of the remote command) will be made the same as the -.Em stdout +.Dv 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. @@ -243,6 +239,13 @@ For .Fn rcmd_af , .Dv PF_UNSPEC is also allowed. +.Sh ENVIRONMENT +.Bl -tag -width RSH +.It Ev RSH +When using the +.Fn rcmd +function, this variable is used as the program to run instead of +.Xr rsh 1 . .Sh DIAGNOSTICS The .Fn rcmd @@ -279,19 +282,25 @@ is overloaded to mean ``All network ports in use.'' .%A M. Thomas .%A E. Nordmark .%T "Advanced Socket API for IPv6" -.%O draft-ietf-ipngwg-rfc2292bis-01.txt +.%O RFC 3542 .Re .Sh HISTORY Most of these functions appeared in .Bx 4.2 . +The .Fn rresvport_af +function appeared in RFC 2292, and was implemented by the WIDE project for the Hydrangea IPv6 protocol stack kit. +The .Fn rcmd_af +function appeared in draft-ietf-ipngwg-rfc2292bis-01.txt, and was implemented in the WIDE/KAME IPv6 protocol stack kit. +The .Fn iruserok_sa +function appeared in discussion on the IETF ipngwg mailing list, and was implemented in .Fx 4.0 . diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index 1fb9400159..96a2dc32ad 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -26,10 +26,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/net/rcmd.c,v 1.23.2.7 2002/08/26 16:17:49 jdp Exp $ - * $DragonFly: src/lib/libc/net/rcmd.c,v 1.7 2005/11/13 02:04:47 swildner Exp $ - * * @(#)rcmd.c 8.3 (Berkeley) 3/26/94 + * $FreeBSD: src/lib/libc/net/rcmd.c,v 1.42 2007/01/09 00:28:02 imp Exp $ + * $DragonFly: src/lib/libc/net/rcmd.c,v 1.7 2005/11/13 02:04:47 swildner Exp $ */ #include "namespace.h" @@ -50,30 +49,23 @@ #include #include #include -#ifdef YP #include +#ifdef YP #include #include #endif #include #include "un-namespace.h" -/* wrapper for KAME-special getnameinfo() */ -#ifndef NI_WITHSCOPEID -#define NI_WITHSCOPEID 0 -#endif - -extern int innetgr ( const char *, const char *, const char *, const char * ); +extern int innetgr(const char *, const char *, const char *, const char *); #define max(a, b) ((a > b) ? a : b) -int __ivaliduser (FILE *, u_int32_t, const char *, const char *); -int __ivaliduser_af (FILE *,const void *, const char *, const char *, - int, int); -int __ivaliduser_sa (FILE *, const struct sockaddr *, socklen_t, - const char *,const char *); -static int __icheckhost (const struct sockaddr *, socklen_t, - const char *); +int __ivaliduser(FILE *, u_int32_t, const char *, const char *); +int __ivaliduser_af(FILE *,const void *, const char *, const char *, int, int); +int __ivaliduser_sa(FILE *, const struct sockaddr *, socklen_t, const char *, + const char *); +static int __icheckhost(const struct sockaddr *, socklen_t, const char *); char paddr[NI_MAXHOST]; @@ -135,8 +127,8 @@ rcmd_af(char **ahost, int rport, const char *locuser, const char *remuser, return (-1); } - if (res->ai_canonname - && strlen(res->ai_canonname) + 1 < sizeof(canonnamebuf)) { + if (res->ai_canonname && + strlen(res->ai_canonname) + 1 < sizeof(canonnamebuf)) { strncpy(canonnamebuf, res->ai_canonname, sizeof(canonnamebuf)); *ahost = canonnamebuf; } @@ -186,10 +178,8 @@ rcmd_af(char **ahost, int rport, const char *locuser, const char *remuser, if (nres > 1) { int oerrno = errno; - getnameinfo(ai->ai_addr, ai->ai_addrlen, - paddr, sizeof(paddr), - NULL, 0, - NI_NUMERICHOST|NI_WITHSCOPEID); + getnameinfo(ai->ai_addr, ai->ai_addrlen, paddr, + sizeof(paddr), NULL, 0, NI_NUMERICHOST); fprintf(stderr, "connect to address %s: ", paddr); errno = oerrno; perror(0); @@ -206,10 +196,8 @@ rcmd_af(char **ahost, int rport, const char *locuser, const char *remuser, refused = 0; } if (nres > 1) { - getnameinfo(ai->ai_addr, ai->ai_addrlen, - paddr, sizeof(paddr), - NULL, 0, - NI_NUMERICHOST|NI_WITHSCOPEID); + getnameinfo(ai->ai_addr, ai->ai_addrlen, paddr, + sizeof(paddr), NULL, 0, NI_NUMERICHOST); fprintf(stderr, "Trying %s...\n", paddr); } } @@ -218,9 +206,8 @@ rcmd_af(char **ahost, int rport, const char *locuser, const char *remuser, _write(s, "", 1); lport = 0; } else { - char num[8]; int s2 = rresvport_af(&lport, ai->ai_family), s3; - int len = ai->ai_addrlen; + socklen_t len = ai->ai_addrlen; int nfds; if (s2 < 0) @@ -569,9 +556,6 @@ __ivaliduser_af(FILE *hostf, const void *raddr, const char *luser, return __ivaliduser_sa(hostf, sa, sa->sa_len, luser, ruser); } -/* - * Returns 0 if ok, -1 if not ok. - */ int __ivaliduser_sa(FILE *hostf, const struct sockaddr *raddr, socklen_t salen, const char *luser, const char *ruser) @@ -691,9 +675,6 @@ __ivaliduser_sa(FILE *hostf, const struct sockaddr *raddr, socklen_t salen, /* * Returns "true" if match, 0 if no match. - * - * NI_WITHSCOPEID is useful for comparing sin6_scope_id portion - * if af == AF_INET6. */ static int __icheckhost(const struct sockaddr *raddr, socklen_t salen, const char *lhost) @@ -719,7 +700,7 @@ __icheckhost(const struct sockaddr *raddr, socklen_t salen, const char *lhost) h1[0] = '\0'; if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0, - NI_NUMERICHOST | NI_WITHSCOPEID) != 0) + NI_NUMERICHOST) != 0) return (0); /* Resolve laddr into sockaddr */ @@ -734,7 +715,7 @@ __icheckhost(const struct sockaddr *raddr, socklen_t salen, const char *lhost) for (r = res; r ; r = r->ai_next) { h2[0] = '\0'; if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2), - NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) != 0) + NULL, 0, NI_NUMERICHOST) != 0) continue; if (strcmp(h1, h2) == 0) { freeaddrinfo(res); diff --git a/lib/libc/net/rcmdsh.3 b/lib/libc/net/rcmdsh.3 index a99534a05c..83aef77b0c 100644 --- a/lib/libc/net/rcmdsh.3 +++ b/lib/libc/net/rcmdsh.3 @@ -11,10 +11,6 @@ .\" 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. @@ -31,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libc/net/rcmdsh.3,v 1.2.2.2 2002/06/06 10:53:29 sheldonh Exp $ +.\" $FreeBSD: src/lib/libc/net/rcmdsh.3,v 1.7 2007/01/09 00:28:02 imp Exp $ .\" $DragonFly: src/lib/libc/net/rcmdsh.3,v 1.4 2007/08/18 20:48:47 swildner Exp $ .\" .Dd September 1, 1996 @@ -82,8 +78,9 @@ residing at the well-known Internet port .Dq Li shell/tcp (or whatever port is used by .Fa rshprog ) . -The parameter +The .Fa inport +argument is ignored; it is only included to provide an interface similar to .Xr rcmd 3 . .Pp @@ -93,7 +90,10 @@ a socket in the domain of type .Dv SOCK_STREAM is returned to the caller, and given to the remote -command as stdin, stdout, and stderr. +command as +.Dv stdin , stdout , +and +.Dv stderr . .Sh RETURN VALUES The .Fn rcmdsh diff --git a/lib/libc/net/rcmdsh.c b/lib/libc/net/rcmdsh.c index 5ca5351773..31cd5ee371 100644 --- a/lib/libc/net/rcmdsh.c +++ b/lib/libc/net/rcmdsh.c @@ -27,7 +27,7 @@ * 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. * - * $FreeBSD: src/lib/libc/net/rcmdsh.c,v 1.3.2.2 2002/04/22 17:38:53 ume Exp $ + * $FreeBSD: src/lib/libc/net/rcmdsh.c,v 1.5 2003/02/27 13:40:00 nectar Exp $ * $DragonFly: src/lib/libc/net/rcmdsh.c,v 1.4 2005/11/13 02:04:47 swildner Exp $ */ @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -85,7 +86,7 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, hints.ai_flags = AI_CANONNAME; hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - snprintf(num, sizeof(num), "%d", ntohs(rport)); + snprintf(num, sizeof(num), "%u", (unsigned int)ntohs(rport)); error = getaddrinfo(*ahost, num, &hints, &res); if (error) { fprintf(stderr, "rcmdsh: getaddrinfo: %s\n", diff --git a/lib/libc/net/recv.c b/lib/libc/net/recv.c index 0cc09c6768..f33a03a4f2 100644 --- a/lib/libc/net/recv.c +++ b/lib/libc/net/recv.c @@ -26,10 +26,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/net/recv.c,v 1.1.1.1.14.1 2001/03/05 10:47:11 obrien Exp $ - * $DragonFly: src/lib/libc/net/recv.c,v 1.5 2005/11/13 02:04:47 swildner Exp $ - * * @(#)recv.c 8.2 (Berkeley) 2/21/94 + * $FreeBSD: src/lib/libc/net/recv.c,v 1.4 2007/01/09 00:28:02 imp Exp $ + * $DragonFly: src/lib/libc/net/recv.c,v 1.5 2005/11/13 02:04:47 swildner Exp $ */ #include "namespace.h" diff --git a/lib/libc/net/resolver.3 b/lib/libc/net/resolver.3 index 6c6ef53bfd..001dca2df2 100644 --- a/lib/libc/net/resolver.3 +++ b/lib/libc/net/resolver.3 @@ -9,10 +9,6 @@ .\" 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. @@ -30,10 +26,10 @@ .\" SUCH DAMAGE. .\" .\" @(#)resolver.3 8.1 (Berkeley) 6/4/93 -.\" $FreeBSD: src/lib/libc/net/resolver.3,v 1.11.2.7 2001/12/14 18:33:55 ru Exp $ +.\" $FreeBSD: src/lib/libc/net/resolver.3,v 1.33 2007/01/09 00:28:02 imp Exp $ .\" $DragonFly: src/lib/libc/net/resolver.3,v 1.4 2007/11/23 23:16:36 swildner Exp $ .\" -.Dd June 4, 1993 +.Dd November 4, 2006 .Dt RESOLVER 3 .Os .Sh NAME @@ -43,7 +39,12 @@ .Nm res_send , .Nm res_init , .Nm dn_comp , -.Nm dn_expand +.Nm dn_expand , +.Nm dn_skipname , +.Nm ns_get16 , +.Nm ns_get32 , +.Nm ns_put16 , +.Nm ns_put32 .Nd resolver routines .Sh LIBRARY .Lb libc @@ -88,7 +89,8 @@ .Fa "int anslen" .Fc .Ft int -.Fn res_init +.Fn res_init void +.Ft int .Fo dn_comp .Fa "const char *exp_dn" .Fa "u_char *comp_dn" @@ -104,17 +106,27 @@ .Fa "char *exp_dn" .Fa "int length" .Fc +.Ft int +.Fn dn_skipname "const u_char *comp_dn" "const u_char *eom" +.Ft u_int +.Fn ns_get16 "const u_char *src" +.Ft u_long +.Fn ns_get32 "const u_char *src" +.Ft void +.Fn ns_put16 "u_int src" "u_char *dst" +.Ft void +.Fn ns_put32 "u_long src" "u_char *dst" .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 . +.Va _res . Most of the values have reasonable defaults and can be ignored. Options stored in -.Em _res.options +.Va _res.options are defined in .In resolv.h and are as follows. @@ -151,7 +163,7 @@ 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 +Unused currently (ignore truncation errors, i.e., do not retry with .Tn TCP ) . .It Dv RES_RECURSE Set the recursion-desired bit in queries. @@ -176,7 +188,8 @@ 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. +environment variable. +Network daemons should set this option. .It Dv RES_USE_INET6 Enables support for IPv6-only applications. This causes IPv4 addresses to be returned as an IPv4 mapped address. @@ -212,18 +225,20 @@ it can be overridden by the environment variable 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 +on a per-process basis. +This is similar to the +.Ic 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 +.Va _res structure or are inherited from the configuration file's -.Em options -command. The syntax of the +.Ic options +command. +The syntax of the .Dq Ev RES_OPTIONS environment variable is explained in .Xr resolver 5 . @@ -277,7 +292,9 @@ but can be any of the query types defined in .In arpa/nameser.h . The domain name for the query is given by .Fa dname . -.Fa Newrr +The +.Fa newrr_in +argument is currently unused but is intended for making update messages. .Pp The @@ -320,7 +337,7 @@ is to update the list of pointers for labels inserted into the message as the name is compressed. If -.Em dnptr +.Fa dnptr is .Dv NULL , names are not compressed. @@ -344,6 +361,66 @@ The uncompressed name is placed in the buffer indicated by which is of size .Fa length . The size of compressed name is returned or \-1 if there was an error. +.Pp +The +.Fn dn_skipname +function skips over a compressed domain name, which starts at a location +pointed to by +.Fa comp_dn . +The compressed name is contained in a query or reply message; +.Fa eom +is a pointer to the end of the message. +The size of compressed name is returned or \-1 if there was +an error. +.Pp +The +.Fn ns_get16 +function gets a 16-bit quantity from a buffer pointed to by +.Fa src . +.Pp +The +.Fn ns_get32 +function gets a 32-bit quantity from a buffer pointed to by +.Fa src . +.Pp +The +.Fn ns_put16 +function puts a 16-bit quantity +.Fa src +to a buffer pointed to by +.Fa dst . +.Pp +The +.Fn ns_put32 +function puts a 32-bit quantity +.Fa src +to a buffer pointed to by +.Fa dst . +.Sh IMPLEMENTATION NOTES +This implementation of the resolver is thread-safe, but it will not +function properly if the programmer attempts to declare his or her own +.Va _res +structure in an attempt to replace the per-thread version referred to +by that macro. +.Sh RETURN VALUES +The +.Fn res_init +function will return 0 on success, or \-1 in a threaded program if +per-thread storage could not be allocated. +.Pp +The +.Fn res_mkquery , +.Fn res_search , +and +.Fn res_query +functions return the size of the response on success, or \-1 if an +error occurs. +The integer +.Vt h_errno +may be checked to determine the reason for error. +See +.Xr gethostbyname 3 +for more information. .Sh FILES .Bl -tag -width /etc/resolv.conf .It Pa /etc/resolv.conf diff --git a/lib/libc/net/send.c b/lib/libc/net/send.c index 6081009869..c8e067cda8 100644 --- a/lib/libc/net/send.c +++ b/lib/libc/net/send.c @@ -26,10 +26,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/net/send.c,v 1.1.1.1.14.1 2001/03/05 10:47:11 obrien Exp $ - * $DragonFly: src/lib/libc/net/send.c,v 1.5 2005/11/13 02:04:47 swildner Exp $ - * * @(#)send.c 8.2 (Berkeley) 2/21/94 + * $FreeBSD: src/lib/libc/net/send.c,v 1.4 2007/01/09 00:28:02 imp Exp $ + * $DragonFly: src/lib/libc/net/send.c,v 1.5 2005/11/13 02:04:47 swildner Exp $ */ #include "namespace.h" diff --git a/lib/libc/net/sockatmark.3 b/lib/libc/net/sockatmark.3 new file mode 100644 index 0000000000..7740b9e90d --- /dev/null +++ b/lib/libc/net/sockatmark.3 @@ -0,0 +1,124 @@ +.\" Copyright (c) 2002 William C. Fenner. 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 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. +.\" +.\" $FreeBSD: src/lib/libc/net/sockatmark.3,v 1.4 2002/12/19 09:40:22 ru Exp $ +.\" +.Dd October 13, 2002 +.Dt SOCKATMARK 3 +.Os +.Sh NAME +.Nm sockatmark +.Nd determine whether the read pointer is at the OOB mark +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/socket.h +.Ft int +.Fn sockatmark "int s" +.Sh DESCRIPTION +To find out if the read pointer is currently pointing at +the mark in the data stream, the +.Fn sockatmark +function is provided. +If +.Fn sockatmark +returns 1, the next read will return data +after the mark. +Otherwise (assuming out of band data has arrived), +the next read will provide data sent by the client prior +to transmission of the out of band signal. +The routine used +in the remote login process to flush output on receipt of an +interrupt or quit signal is shown below. +It reads the normal data up to the mark (to discard it), +then reads the out-of-band byte. +.Bd -literal -offset indent +#include +\&... +void +oob(void) +{ + int out = FWRITE, mark; + char waste[BUFSIZ]; + + /* flush local terminal output */ + ioctl(1, TIOCFLUSH, (char *)&out); + for (;;) { + if ((mark = sockatmark(rem)) < 0) { + perror("sockatmark"); + break; + } + if (mark) + break; + read(rem, waste, sizeof (waste)); + } + if (recv(rem, &mark, 1, MSG_OOB) < 0) { + perror("recv"); + ... + } + ... +} +.Ed +.Sh RETURN VALUES +Upon successful completion, the +.Fn sockatmark +function returns the value 1 if the read pointer is pointing at +the OOB mark, 0 if it is not. +Otherwise the value \-1 is returned +and the global variable +.Va errno +is set to +indicate the error. +.Sh ERRORS +The +.Fn sockatmark +call fails if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa s +argument +is not a valid descriptor. +.It Bq Er ENOTTY +The +.Fa s +argument +is a descriptor for a file, not a socket. +.El +.Sh SEE ALSO +.Xr recv 2 , +.Xr send 2 +.Sh HISTORY +The +.Fn sockatmark +function was introduced by +.St -p1003.1-2001 , +to standardize the historical +.Dv SIOCATMARK +.Xr ioctl 2 . +The +.Er ENOTTY +error instead of the usual +.Er ENOTSOCK +is to match the historical behavior of +.Dv SIOCATMARK . diff --git a/lib/libc/i386/net/htons.S b/lib/libc/net/sockatmark.c similarity index 55% rename from lib/libc/i386/net/htons.S rename to lib/libc/net/sockatmark.c index a0ac5079a4..17c15b7ccd 100644 --- a/lib/libc/i386/net/htons.S +++ b/lib/libc/net/sockatmark.c @@ -1,9 +1,5 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. +/* + * Copyright (c) 2002 William C. Fenner. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -13,15 +9,8 @@ * 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 + * 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 @@ -33,15 +22,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/i386/net/htons.S,v 1.5 1999/08/27 23:59:25 peter Exp $ - * $DragonFly: src/lib/libc/i386/net/htons.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ + * $FreeBSD: src/lib/libc/net/sockatmark.c,v 1.1 2002/12/13 22:22:55 fenner Exp $ */ -/* netorder = htons(hostorder) */ +#include -#include "DEFS.h" +int sockatmark(int s) +{ + int atmark; -ENTRY(htons) - movzwl 4(%esp),%eax - xchgb %al,%ah - ret + if (ioctl(s, SIOCATMARK, &atmark) == -1) + return -1; + return atmark; +} diff --git a/lib/libc/net/vars.c b/lib/libc/net/vars.c index 6cd4007d12..009fd0f4ee 100644 --- a/lib/libc/net/vars.c +++ b/lib/libc/net/vars.c @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/net/vars.c,v 1.1.2.1 2002/04/28 05:40:24 suz Exp $ + * $FreeBSD: src/lib/libc/net/vars.c,v 1.3 2002/04/19 04:46:20 suz Exp $ * $DragonFly: src/lib/libc/net/vars.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ */ diff --git a/sbin/route/Makefile b/sbin/route/Makefile index 1ab7c637f8..b176cca4b7 100644 --- a/sbin/route/Makefile +++ b/sbin/route/Makefile @@ -5,7 +5,7 @@ PROG= route MAN= route.8 SRCS= route.c show.c keywords.h keywords.c -CFLAGS+=-I. -DNS +CFLAGS+=-I. CFLAGS+=-DINET6 CLEANFILES+=keywords.h keywords.c _keywords.tmp WARNS?= 3 diff --git a/sbin/route/show.c b/sbin/route/show.c index 0bc600848c..96dd9a49c8 100644 --- a/sbin/route/show.c +++ b/sbin/route/show.c @@ -366,9 +366,11 @@ p_sockaddr(struct sockaddr *sa, int flags, int width) } #endif /* INET6 */ +#ifdef NS case AF_NS: cp = ns_print((struct sockaddr_ns *)sa); break; +#endif default: { diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 0dc7d10b03..a154bafbdc 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -26,6 +26,7 @@ MAN= accept_filter.9 \ bus_set_resource.9 \ BUS_SETUP_INTR.9 \ bus_space.9 \ + byteorder.9 \ callout.9 \ cd.9 \ contigmalloc.9 \ @@ -292,6 +293,33 @@ MLINKS+=bus_space.9 bus_space_barrier.9 \ bus_space.9 bus_space_write_stream_1.9 \ bus_space.9 bus_space_write_stream_2.9 \ bus_space.9 bus_space_write_stream_4.9 +MLINKS+=byteorder.9 be16dec.9 \ + byteorder.9 be16enc.9 \ + byteorder.9 be16toh.9 \ + byteorder.9 be32dec.9 \ + byteorder.9 be32enc.9 \ + byteorder.9 be32toh.9 \ + byteorder.9 be64dec.9 \ + byteorder.9 be64enc.9 \ + byteorder.9 be64toh.9 \ + byteorder.9 bswap16.9 \ + byteorder.9 bswap32.9 \ + byteorder.9 bswap64.9 \ + byteorder.9 htobe16.9 \ + byteorder.9 htobe32.9 \ + byteorder.9 htobe64.9 \ + byteorder.9 htole16.9 \ + byteorder.9 htole32.9 \ + byteorder.9 htole64.9 \ + byteorder.9 le16dec.9 \ + byteorder.9 le16enc.9 \ + byteorder.9 le16toh.9 \ + byteorder.9 le32dec.9 \ + byteorder.9 le32enc.9 \ + byteorder.9 le32toh.9 \ + byteorder.9 le64dec.9 \ + byteorder.9 le64enc.9 \ + byteorder.9 le64toh.9 MLINKS+=callout.9 callout_active.9 \ callout.9 callout_deactivate.9 \ callout.9 callout_init.9 \ diff --git a/share/man/man9/byteorder.9 b/share/man/man9/byteorder.9 new file mode 100644 index 0000000000..3ba6943e45 --- /dev/null +++ b/share/man/man9/byteorder.9 @@ -0,0 +1,169 @@ +.\" Copyright (c) 2002 Mike Barcroft +.\" 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. +.\" +.\" $FreeBSD: src/share/man/man9/byteorder.9,v 1.6 2003/05/21 17:32:55 ru Exp $ +.\" +.Dd April 29, 2002 +.Dt BYTEORDER 9 +.Os +.Sh NAME +.Nm bswap16 , bswap32 , bswap64 , +.Nm be16toh , be32toh , be64toh , htobe16 , htobe32 , htobe64 , +.Nm htole16 , htole32 , htole64 , le16toh , le32toh , le64toh , +.Nm be16enc , be16dec , be32enc , be32dec , be64enc , be64dec , +.Nm le16enc , le16dec , le32enc , le32dec , le64enc , le64dec +.Nd byte order operations +.Sh SYNOPSIS +.In sys/endian.h +.Ft uint16_t +.Fn bswap16 "uint16_t int16" +.Ft uint32_t +.Fn bswap32 "uint32_t int32" +.Ft uint64_t +.Fn bswap64 "uint64_t int64" +.Ft uint16_t +.Fn be16toh "uint16_t big16" +.Ft uint32_t +.Fn be32toh "uint32_t big32" +.Ft uint64_t +.Fn be64toh "uint64_t big64" +.Ft uint16_t +.Fn htobe16 "uint16_t host16" +.Ft uint32_t +.Fn htobe32 "uint32_t host32" +.Ft uint64_t +.Fn htobe64 "uint64_t host64" +.Ft uint16_t +.Fn htole16 "uint16_t host16" +.Ft uint32_t +.Fn htole32 "uint32_t host32" +.Ft uint64_t +.Fn htole64 "uint64_t host64" +.Ft uint16_t +.Fn le16toh "uint16_t little16" +.Ft uint32_t +.Fn le32toh "uint32_t little32" +.Ft uint64_t +.Fn le64toh "uint64_t little64" +.Ft uint16_t +.Fn be16dec "const void *" +.Ft uint32_t +.Fn be32dec "const void *" +.Ft uint64_t +.Fn be64dec "const void *" +.Ft uint16_t +.Fn le16dec "const void *" +.Ft uint32_t +.Fn le32dec "const void *" +.Ft uint64_t +.Fn le64dec "const void *" +.Ft void +.Fn be16enc "void *" uint16_t +.Ft void +.Fn be32enc "void *" uint32_t +.Ft void +.Fn be64enc "void *" uint64_t +.Ft void +.Fn le16enc "void *" uint16_t +.Ft void +.Fn le32enc "void *" uint32_t +.Ft void +.Fn le64enc "void *" uint64_t +.Sh DESCRIPTION +The +.Fn bswap16 , +.Fn bswap32 , +and +.Fn bswap64 +functions return a byte order swapped integer. +On big endian systems, the number is converted to little endian byte order. +On little endian systems, the number is converted to big endian byte order. +.Pp +The +.Fn be16toh , +.Fn be32toh , +and +.Fn be64toh +functions return a big endian byte ordered integer +converted to the system's native byte order. +The return value will be the same as the argument on big endian systems. +.Pp +The +.Fn le16toh , +.Fn le32toh , +and +.Fn le64toh +functions return a little endian byte ordered integer +converted to the system's native byte order. +The return value will be the same as the argument on little endian systems. +.Pp +The +.Fn htobe16 , +.Fn htobe32 , +and +.Fn htobe64 +functions return a integer in the system's native +byte order converted to big endian byte order. +The return value will be the same as the argument on big endian systems. +.Pp +The +.Fn htole16 , +.Fn htole32 , +and +.Fn htole64 +functions return a integer in the system's native +byte order converted to little endian byte order. +The return value will be the same as the argument on little endian systems. +.Pp +The +.Fn be16enc , +.Fn be16dec , +.Fn be32enc , +.Fn be32dec , +.Fn be64enc , +.Fn be64dec , +.Fn le16enc , +.Fn le16dec , +.Fn le32enc , +.Fn le32dec , +.Fn le64enc , +and +.Fn le64dec +functions encode and decode integers to/from byte strings on any alignment +in big/little endian format. +.Sh SEE ALSO +.Xr byteorder 3 +.Sh HISTORY +The +.Fn hto* +and +.Fn toh* +functions first appeared in +.Fx 5.0 , +and were originally developed by the +.Nx +project. +.Pp +The encode/decode functions first appeared in +.Fx 5.1 . diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h index 643c8cfb09..13b55f04bd 100644 --- a/sys/net/ethernet.h +++ b/sys/net/ethernet.h @@ -407,9 +407,11 @@ void altq_etherclassify(struct ifaltq *, struct mbuf *, struct altq_pktattr *); */ __BEGIN_DECLS struct ether_addr *ether_aton (const char *); +struct ether_addr *ether_aton_r(const char *, struct ether_addr *); int ether_hostton (const char *, struct ether_addr *); int ether_line (const char *, struct ether_addr *, char *); char *ether_ntoa (const struct ether_addr *); +char *ether_ntoa_r(const struct ether_addr *, char *); int ether_ntohost (char *, const struct ether_addr *); __END_DECLS diff --git a/sys/net/if.c b/sys/net/if.c index 09f752d34f..b591c7627a 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1211,6 +1211,10 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct ucred *cred) return (ENXIO); switch (cmd) { + case SIOCGIFINDEX: + ifr->ifr_index = ifp->if_index; + break; + case SIOCGIFFLAGS: ifr->ifr_flags = ifp->if_flags; ifr->ifr_flagshigh = ifp->if_flags >> 16; diff --git a/sys/net/if.h b/sys/net/if.h index bad78f7ebd..efecc6a059 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -235,6 +235,7 @@ struct ifreq { struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; short ifru_flags[2]; + short ifru_index; int ifru_metric; int ifru_mtu; int ifru_phys; @@ -255,6 +256,7 @@ struct ifreq { #define ifr_data ifr_ifru.ifru_data /* for use by interface */ #define ifr_reqcap ifr_ifru.ifru_cap[0] /* requested capabilities */ #define ifr_curcap ifr_ifru.ifru_cap[1] /* current capabilities */ +#define ifr_index ifr_ifru.ifru_index /* interface index */ #define ifr_pollcpu ifr_ifru.ifru_pollcpu /* polling(4) cpu */ }; diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h index 5ef5a50253..8649f5c325 100644 --- a/sys/sys/sockio.h +++ b/sys/sys/sockio.h @@ -80,6 +80,7 @@ #define SIOCDLIFADDR _IOW('i', 29, struct if_laddrreq) /* delete IF addr */ #define SIOCSIFCAP _IOW('i', 30, struct ifreq) /* set IF features */ #define SIOCGIFCAP _IOWR('i', 31, struct ifreq) /* get IF features */ +#define SIOCGIFINDEX _IOWR('i', 32, struct ifreq) /* get IF index */ #define SIOCSIFNAME _IOW('i', 40, struct ifreq) /* set IF name */ #define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ -- 2.41.0