1.\" Copyright (c) 1983, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 29.\" $FreeBSD$ 30.\" 31.Dd June 27, 2022 32.Dt GETNETENT 3 33.Os 34.Sh NAME 35.Nm getnetent , 36.Nm getnetbyaddr , 37.Nm getnetbyname , 38.Nm setnetent , 39.Nm endnetent 40.Nd get network entry 41.Sh LIBRARY 42.Lb libc 43.Sh SYNOPSIS 44.In netdb.h 45.Ft struct netent * 46.Fn getnetent void 47.Ft struct netent * 48.Fn getnetbyname "const char *name" 49.Ft struct netent * 50.Fn getnetbyaddr "uint32_t net" "int type" 51.Ft void 52.Fn setnetent "int stayopen" 53.Ft void 54.Fn endnetent void 55.Ft int 56.Fn getnetent_r "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errnop" 57.Ft int 58.Fn getnetbyaddr_r "uint32_t net" "int type" "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" int *h_errorp" 59.Ft int 60.Fn getnetbyname_r "const char *name" "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errorp" 61.Sh DESCRIPTION 62The 63.Fn getnetent , 64.Fn getnetbyname , 65and 66.Fn getnetbyaddr 67functions 68each return a pointer to an object with the 69following structure describing an internet network. 70This structure contains either the information obtained 71from the nameserver, broken-out fields of a line in the network data base 72.Pa /etc/networks , 73or entries supplied by the 74.Xr yp 8 75system. 76The order of the lookups is controlled by the 77`networks' entry in 78.Xr nsswitch.conf 5 . 79.Bd -literal -offset indent 80struct netent { 81 char *n_name; /* official name of net */ 82 char **n_aliases; /* alias list */ 83 int n_addrtype; /* net number type */ 84 uint32_t n_net; /* net number */ 85}; 86.Ed 87.Pp 88The members of this structure are: 89.Bl -tag -width n_addrtype 90.It Fa n_name 91The official name of the network. 92.It Fa n_aliases 93A zero terminated list of alternate names for the network. 94.It Fa n_addrtype 95The type of the network number returned; currently only AF_INET. 96.It Fa n_net 97The network number. 98Network numbers are returned in machine byte 99order. 100.El 101.Pp 102The 103.Fn getnetent 104function 105reads the next line of the file, opening the file if necessary. 106.Pp 107The 108.Fn setnetent 109function 110opens and rewinds the file. 111If the 112.Fa stayopen 113flag is non-zero, 114the net data base will not be closed after each call to 115.Fn getnetbyname 116or 117.Fn getnetbyaddr . 118.Pp 119The 120.Fn endnetent 121function 122closes the file. 123.Pp 124The 125.Fn getnetbyname 126function 127and 128.Fn getnetbyaddr 129sequentially search from the beginning 130of the file until a matching 131net name or 132net address and type is found, 133or until 134.Dv EOF 135is encountered. 136The 137.Fa type 138argument 139must be 140.Dv AF_INET . 141Network numbers are supplied in host order. 142.Pp 143Functions with the 144.Em _r 145suffix provide reentrant versions of their respective counterparts. 146The caller must supply five additional parameters: a 147.Vt struct netent 148variable to be filled on success, a 149.Va buffer 150of 151.Va buflen 152bytes in size, a 153.Vt struct netent 154.Va result 155variable that will point to the result on success or be set to 156.Dv NULL 157on failure or if the name is not found. 158The 159.Va h_errnop 160variable will be filled with the error code if any. 161All these functions return 0 on success. 162.Sh FILES 163.Bl -tag -width /etc/nsswitch.conf -compact 164.It Pa /etc/networks 165.It Pa /etc/nsswitch.conf 166.It Pa /etc/resolv.conf 167.El 168.Sh DIAGNOSTICS 169Null pointer returned on 170.Dv EOF 171or error. 172.Sh SEE ALSO 173.Xr networks 5 174.Pp 175.%T RFC 1101 176.Sh HISTORY 177The 178.Fn getnetent , 179.Fn getnetbyaddr , 180.Fn getnetbyname , 181.Fn setnetent , 182and 183.Fn endnetent 184functions appeared in 185.Bx 4.2 . 186.Sh BUGS 187The data space used by 188these functions is thread-specific; if future use requires the data, it should be 189copied before any subsequent calls to these functions overwrite it. 190Only Internet network 191numbers are currently understood. 192Expecting network numbers to fit 193in no more than 32 bits is probably 194naive. 195