1.\" $NetBSD: getnetent.3,v 1.17 2022/12/04 01:29:32 uwe Exp $ 2.\" 3.\" Copyright (c) 1983, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 31.\" 32.Dd February 21, 2018 33.Dt GETNETENT 3 34.Os 35.Sh NAME 36.Nm getnetent , 37.Nm getnetbyaddr , 38.Nm getnetbyname , 39.Nm setnetent , 40.Nm endnetent 41.Nd get network entry 42.Sh LIBRARY 43.Lb libc 44.Sh SYNOPSIS 45.In netdb.h 46.Ft struct netent * 47.Fn getnetent 48.Ft struct netent * 49.Fn getnetbyname "const char *name" 50.Ft struct netent * 51.Fn getnetbyaddr "uint32_t net" "int type" 52.Ft void 53.Fn setnetent "int stayopen" 54.Ft void 55.Fn endnetent void 56.Sh DESCRIPTION 57The 58.Fn getnetent , 59.Fn getnetbyname , 60and 61.Fn getnetbyaddr 62functions each return a pointer to an object with the following 63structure containing the broken-out fields of a line in the network 64data base as described in 65.Xr networks 5 . 66.Bd -literal -offset indent 67struct netent { 68 char *n_name; /* official name of net */ 69 char **n_aliases; /* alias list */ 70 int n_addrtype; /* net number type */ 71 uint32_t n_net; /* net number */ 72}; 73.Ed 74.Pp 75The members of this structure are: 76.Bl -tag -width n_addrtype 77.It Fa n_name 78The official name of the network. 79.It Fa n_aliases 80A zero terminated list of alternative names for the network. 81.It Fa n_addrtype 82The type of the network number returned; currently only 83.Dv AF_INET . 84.It Fa n_net 85The network number. 86Network numbers are returned in host byte order. 87.El 88.Pp 89The 90.Fn getnetent 91function reads the next line of the file, opening the file if necessary. 92.Pp 93The 94.Fn setnetent 95function opens and rewinds the file. 96If the 97.Fa stayopen 98flag is non-zero, the net data base will not be closed after each 99call to 100.Fn getnetbyname 101or 102.Fn getnetbyaddr . 103.Pp 104The 105.Fn endnetent 106function closes the file. 107.Pp 108The 109.Fn getnetbyname 110and 111.Fn getnetbyaddr 112functions sequentially search from the beginning of the file until 113a matching net name or net address and type is found, or until 114.Dv EOF 115is encountered. 116Network numbers are supplied in host byte order. 117.Sh FILES 118.Bl -tag -width /etc/networks -compact 119.It Pa /etc/networks 120.El 121.Sh RETURN VALUES 122Null pointer 123.Dv ( NULL ) 124returned on 125.Dv EOF 126or error. 127.Sh SEE ALSO 128.Xr networks 5 , 129.Xr nsswitch.conf 5 130.Sh HISTORY 131The 132.Fn getnetent , 133.Fn getnetbyaddr , 134.Fn getnetbyname , 135.Fn setnetent , 136and 137.Fn endnetent 138functions appeared in 139.Bx 4.2 . 140.Sh BUGS 141The data space used by these functions is static; if future use 142requires the data, it should be copied before any subsequent calls 143to these functions overwrite it. 144Only Internet network numbers are currently understood. 145Expecting network numbers to fit in no more than 32 bits is probably 146naive. 147