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: src/lib/libc/net/getnetent.3,v 1.23 2007/01/09 00:28:02 imp Exp $ 30.\" 31.Dd May 6, 2019 32.Dt GETNETENT 3 33.Os 34.Sh NAME 35.Nm getnetent , 36.Nm getnetent_r , 37.Nm getnetbyaddr , 38.Nm getnetbyaddr_r , 39.Nm getnetbyname , 40.Nm getnetbyname_r , 41.Nm setnetent , 42.Nm endnetent 43.Nd get network entry 44.Sh LIBRARY 45.Lb libc 46.Sh SYNOPSIS 47.In netdb.h 48.Ft struct netent * 49.Fn getnetent void 50.Ft int 51.Fn getnetent_r "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errnop" 52.Ft struct netent * 53.Fn getnetbyname "const char *name" 54.Ft int 55.Fn getnetbyname_r "const char *name" "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errnop" 56.Ft struct netent * 57.Fn getnetbyaddr "uint32_t net" "int type" 58.Ft int 59.Fn getnetbyaddr_r "uint32_t addr" "int af" "struct netent *ne" "char *buffer" "size_t buflen" "struct netent **result" "int *h_errnop" 60.Ft void 61.Fn setnetent "int stayopen" 62.Ft void 63.Fn endnetent void 64.Sh DESCRIPTION 65The 66.Fn getnetent , 67.Fn getnetbyname , 68and 69.Fn getnetbyaddr 70functions 71each return a pointer to an object with the 72following structure describing an internet network. 73This structure contains either the information obtained 74from the nameserver, 75.Xr named 8 , 76broken-out fields of a line in the network data base 77.Pa /etc/networks , 78or entries supplied by the 79.Xr yp 8 80system. 81The order of the lookups is controlled by the 82`networks' entry in 83.Xr nsswitch.conf 5 . 84.Bd -literal -offset indent 85struct netent { 86 char *n_name; /* official name of net */ 87 char **n_aliases; /* alias list */ 88 int n_addrtype; /* net number type */ 89 uint32_t n_net; /* net number */ 90}; 91.Ed 92.Pp 93The members of this structure are: 94.Bl -tag -width n_addrtype 95.It Fa n_name 96The official name of the network. 97.It Fa n_aliases 98A zero terminated list of alternate names for the network. 99.It Fa n_addrtype 100The type of the network number returned; currently only AF_INET. 101.It Fa n_net 102The network number. 103Network numbers are returned in machine byte 104order. 105.El 106.Pp 107The 108.Fn getnetent 109function 110reads the next line of the file, opening the file if necessary. 111.Pp 112The 113.Fn setnetent 114function 115opens and rewinds the file. 116If the 117.Fa stayopen 118flag is non-zero, 119the net data base will not be closed after each call to 120.Fn getnetbyname 121or 122.Fn getnetbyaddr . 123.Pp 124The 125.Fn endnetent 126function 127closes the file. 128.Pp 129The 130.Fn getnetbyname 131function 132and 133.Fn getnetbyaddr 134sequentially search from the beginning 135of the file until a matching 136net name or 137net address and type is found, 138or until 139.Dv EOF 140is encountered. 141The 142.Fa type 143argument 144must be 145.Dv AF_INET . 146Network numbers are supplied in host order. 147.Pp 148The 149.Fn getnetent_r , 150.Fn getnetbyaddr_r , 151and 152.Fn getnetbyname_r 153functions are reentrant versions of the above functions that take a 154pointer to a 155.Vt netent 156structure which is used to store state information. 157The structure must be zero-filled before it is used 158and should be considered opaque for the sake of portability. 159These functions also take a pointer to another 160.Vt netent 161structure which is used to store the results of the database lookup. 162.Sh RETURN VALUES 163The 164.Fn getnetent , 165.Fn getnetbyaddr , 166and 167.Fn getnetbyname 168functions return a pointer to a 169.Vt netent 170structure on success or a null pointer if end-of-file 171is reached or an error occurs. 172.Pp 173The 174.Fn getnetent_r , 175.Fn getnetbyaddr_r , 176and 177.Fn getnetbyname_r 178functions return 0 on success or \-1 if end-of-file 179is reached or an error occurs. 180.Sh FILES 181.Bl -tag -width ".Pa /etc/nsswitch.conf" -compact 182.It Pa /etc/networks 183.It Pa /etc/nsswitch.conf 184.It Pa /etc/resolv.conf 185.El 186.Sh SEE ALSO 187.Xr networks 5 188.Pp 189.%T RFC 1101 190.Sh STANDARDS 191The 192.Fn getnetent , 193.Fn getnetbyaddr , 194.Fn getnetbyname , 195.Fn setnetent , 196and 197.Fn endnetent 198functions conform to 199.St -p1003.1-2004 . 200.Pp 201The 202.Fn getnetent_r , 203.Fn getnetbyaddr_r , 204and 205.Fn getnetbyname_r 206functions are not currently standardized. 207.Sh HISTORY 208The 209.Fn getnetent , 210.Fn getnetbyaddr , 211.Fn getnetbyname , 212.Fn setnetent , 213and 214.Fn endnetent 215functions appeared in 216.Bx 4.2 . 217.Pp 218The 219.Fn getnetent_r , 220.Fn getnetbyaddr_r , 221and 222.Fn getnetbyname_r 223functions appeared in 224.Dx 2.1 . 225.Sh BUGS 226The data space used by 227these functions is thread-specific; if future use requires the data, it should be 228copied before any subsequent calls to these functions overwrite it. 229Only Internet network 230numbers are currently understood. 231Expecting network numbers to fit 232in no more than 32 bits is probably 233naive. 234