diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 683e2826c401..755d44e6c5dd 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -1,133 +1,135 @@ # from @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 # $FreeBSD$ # machine-independent net sources .PATH: ${LIBC_SRCTOP}/net CONFS+= net/hosts net/hosts.equiv net/networks net/nsswitch.conf net/protocols SRCS+= base64.c ether_addr.c eui64.c \ gai_strerror.c getaddrinfo.c \ gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \ getifaddrs.c getifmaddrs.c getnameinfo.c \ getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.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 ntoh.c \ nsdispatch.c nslexer.l nsparser.y nss_compat.c \ rcmd.c rcmdsh.c recv.c rthdr.c sctp_sys_calls.c send.c \ sockatmark.c sourcefilter.c vars.c .if ${MK_NS_CACHING} != "no" SRCS+= nscache.c nscachedcli.c .endif SYM_MAPS+=${LIBC_SRCTOP}/net/Symbol.map .if ${MK_INET6_SUPPORT} != "no" CFLAGS+=-DINET6 .endif CFLAGS+=-I${.OBJDIR} # name6.c refers res_private.h CFLAGS+=-I${LIBC_SRCTOP}/resolv YFLAGS+=-p_nsyy LFLAGS+=-P_nsyy CFLAGS.nslexer.c= -DYY_BUF_SIZE=1024 MAN+= byteorder.3 ethers.3 eui64.3 \ getaddrinfo.3 gai_strerror.3 gethostbyname.3 \ getifaddrs.3 getifmaddrs.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 sockatmark.3 \ sourcefilter.3 \ sctp_bindx.3 sctp_connectx.3 sctp_freepaddrs.3 \ sctp_getaddrlen.3 sctp_getassocid.3 sctp_getpaddrs.3 \ sctp_opt_info.3 sctp_recvmsg.3 sctp_send.3 sctp_sendmsg.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+=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 MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ gethostbyname.3 gethostbyaddr_r.3 gethostbyname.3 gethostbyname2.3 \ gethostbyname.3 gethostbyname2_r.3 gethostbyname.3 gethostbyname_r.3 \ gethostbyname.3 gethostent.3 gethostbyname.3 herror.3 \ gethostbyname.3 hstrerror.3 gethostbyname.3 sethostent.3 MLINKS+=getifaddrs.3 freeifaddrs.3 MLINKS+=getifmaddrs.3 freeifmaddrs.3 MLINKS+=getipnodebyname.3 getipnodebyaddr.3 getipnodebyname.3 freehostent.3 MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \ - getnetent.3 getnetbyname.3 getnetent.3 setnetent.3 + getnetent.3 getnetbyaddr_r.3 getnetent.3 getnetbyname.3 \ + getnetent.3 getnetbyname_r.3 getnetent.3 setnetent.3 \ + getnetent.3 getnetent_r.3 MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \ getprotoent.3 getprotobynumber.3 getprotoent.3 setprotoent.3 MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \ getservent.3 getservbyport.3 getservent.3 setservent.3 MLINKS+=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_ntoa_r.3\ inet.3 inet_ntop.3 inet.3 inet_pton.3 \ inet.3 network.3 inet.3 ntoa.3 MLINKS+= sctp_send.3 sctp_sendx.3 MLINKS+= sctp_sendmsg.3 sctp_sendmsgx.3 MLINKS+= sctp_freepaddrs.3 sctp_freeladdrs.3 MLINKS+= sctp_getpaddrs.3 sctp_getladdrs.3 MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 MLINKS+=inet6_opt_init.3 inet6_opt_append.3 \ inet6_opt_init.3 inet6_opt_find.3 \ inet6_opt_init.3 inet6_opt_finish.3 \ inet6_opt_init.3 inet6_opt_get_val.3 \ inet6_opt_init.3 inet6_opt_next.3 \ inet6_opt_init.3 inet6_opt_set_val.3 \ inet6_option_space.3 inet6_option_alloc.3 \ inet6_option_space.3 inet6_option_append.3 \ inet6_option_space.3 inet6_option_find.3 \ inet6_option_space.3 inet6_option_init.3 \ inet6_option_space.3 inet6_option_next.3 \ inet6_rth_space.3 inet6_rth_add.3 \ inet6_rth_space.3 inet6_rth_getaddr.3 \ inet6_rth_space.3 inet6_rth_init.3 \ inet6_rth_space.3 inet6_rth_reverse.3 \ inet6_rth_space.3 inet6_rth_segments.3 \ inet6_rthdr_space.3 inet6_rthdr_add.3 \ inet6_rthdr_space.3 inet6_rthdr_getaddr.3 \ inet6_rthdr_space.3 inet6_rthdr_getflags.3 \ inet6_rthdr_space.3 inet6_rthdr_init.3 \ inet6_rthdr_space.3 inet6_rthdr_lasthop.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+=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 \ resolver.3 res_mkquery.3 resolver.3 res_query.3 \ resolver.3 res_search.3 resolver.3 res_send.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 MLINKS+=sourcefilter.3 setipv4sourcefilter.3 sourcefilter.3 getipv4sourcefilter.3 \ sourcefilter.3 setsourcefilter.3 sourcefilter.3 getsourcefilter.3 .if ${MK_HESIOD} != "no" SRCS+= hesiod.c MAN+= hesiod.3 .endif afterinstallconfig: modify-nsswitch-conf modify-nsswitch-conf: .PHONY .if ${MK_NIS} == "no" sed -i "" -e 's/.*_compat:/# &/' -e 's/compat$$/files/' \ ${DESTDIR}/etc/nsswitch.conf .endif diff --git a/lib/libc/net/getnetent.3 b/lib/libc/net/getnetent.3 index adf2760d132f..29eabdacd6bf 100644 --- a/lib/libc/net/getnetent.3 +++ b/lib/libc/net/getnetent.3 @@ -1,170 +1,196 @@ .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd June 20, 2022 .Dt GETNETENT 3 .Os .Sh NAME .Nm getnetent , .Nm getnetbyaddr , .Nm getnetbyname , .Nm setnetent , .Nm endnetent .Nd get network entry .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In netdb.h .Ft struct netent * .Fn getnetent void .Ft struct netent * .Fn getnetbyname "const char *name" .Ft struct netent * .Fn getnetbyaddr "uint32_t net" "int type" .Ft void .Fn setnetent "int stayopen" .Ft void .Fn endnetent void +.Ft int +.Fn getnetent_r "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errnop" +.Ft int +.Fn getnetbyaddr_r "uint32_t net" "int type" "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" int *h_errorp" +.Ft int +.Fn getnetbyname_r "const char *name" "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errorp" .Sh DESCRIPTION The .Fn getnetent , .Fn getnetbyname , and .Fn getnetbyaddr functions each return a pointer to an object with the following structure describing an internet network. This structure contains either the information obtained from the nameserver, .Xr named 8 , 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 `networks' entry in .Xr nsswitch.conf 5 . .Bd -literal -offset indent struct netent { char *n_name; /* official name of net */ char **n_aliases; /* alias list */ int n_addrtype; /* net number type */ uint32_t n_net; /* net number */ }; .Ed .Pp The members of this structure are: .Bl -tag -width n_addrtype .It Fa n_name The official name of the network. .It Fa n_aliases A zero terminated list of alternate names for the network. .It Fa n_addrtype The type of the network number returned; currently only AF_INET. .It Fa n_net The network number. Network numbers are returned in machine byte order. .El .Pp The .Fn getnetent function reads the next line of the file, opening the file if necessary. .Pp The .Fn setnetent function opens and rewinds the file. If the .Fa stayopen flag is non-zero, the net data base will not be closed after each call to .Fn getnetbyname or .Fn getnetbyaddr . .Pp The .Fn endnetent function closes the file. .Pp The .Fn getnetbyname function and .Fn getnetbyaddr sequentially search from the beginning of the file until a matching net name or net address and type is found, or until .Dv EOF is encountered. The .Fa type argument must be .Dv AF_INET . Network numbers are supplied in host order. +.Pp +Functions with the +.Em _r +suffix provide reentrant versions of their respective counterparts. +The caller must supply five additional parameters: a +.Vt struct netent +variable to be filled on success, a +.Va buffer +of +.Va buflen +bytes in size, a +.Vt struct netent +.Va result +variable that will point to the result on success or be set to +.Dv NULL +on failure or if the name is not found. +The +.Va h_errnop +variable will be filled with the error code if any. +All these functions return 0 on success. .Sh FILES .Bl -tag -width /etc/nsswitch.conf -compact .It Pa /etc/networks .It Pa /etc/nsswitch.conf .It Pa /etc/resolv.conf .El .Sh DIAGNOSTICS Null pointer returned on .Dv EOF or error. .Sh SEE ALSO .Xr networks 5 .Pp .%T RFC 1101 .Sh HISTORY The .Fn getnetent , .Fn getnetbyaddr , .Fn getnetbyname , .Fn setnetent , and .Fn endnetent functions appeared in .Bx 4.2 . .Sh BUGS The data space used by these functions is 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. Expecting network numbers to fit in no more than 32 bits is probably naive.