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. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93 33.\" 34.Dd June 4, 1993 35.Dt GETNETENT 3 36.Os BSD 4.2 37.Sh NAME 38.Nm getnetent , 39.Nm getnetbyaddr , 40.Nm getnetbyname , 41.Nm setnetent , 42.Nm endnetent 43.Nd get network entry 44.Sh SYNOPSIS 45.Fd #include <netdb.h> 46.Ft struct netent * 47.Fn getnetent void 48.Ft struct netent * 49.Fn getnetbyname "const char *name" 50.Ft struct netent * 51.Fn getnetbyaddr "unsigned long 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 63each return a pointer to an object with the 64following structure 65containing the broken-out 66fields of a line in the network data base, 67.Pa /etc/networks . 68.Bd -literal -offset indent 69struct netent { 70 char *n_name; /* official name of net */ 71 char **n_aliases; /* alias list */ 72 int n_addrtype; /* net number type */ 73 unsigned long n_net; /* net number */ 74}; 75.Ed 76.Pp 77The members of this structure are: 78.Bl -tag -width n_addrtype 79.It Fa n_name 80The official name of the network. 81.It Fa n_aliases 82A zero terminated list of alternate names for the network. 83.It Fa n_addrtype 84The type of the network number returned; currently only AF_INET. 85.It Fa n_net 86The network number. Network numbers are returned in machine byte 87order. 88.El 89.Pp 90The 91.Fn getnetent 92function 93reads the next line of the file, opening the file if necessary. 94.Pp 95The 96.Fn setnetent 97function 98opens and rewinds the file. If the 99.Fa stayopen 100flag is non-zero, 101the net data base will not be closed after each call to 102.Fn getnetbyname 103or 104.Fn getnetbyaddr . 105.Pp 106The 107.Fn endnetent 108function 109closes the file. 110.Pp 111The 112.Fn getnetbyname 113function 114and 115.Fn getnetbyaddr 116sequentially search from the beginning 117of the file until a matching 118net name or 119net address and type is found, 120or until 121.Dv EOF 122is encountered. The 123.Fa type 124must be 125.Dv AF_INET . 126Network numbers are supplied in host order. 127.Sh FILES 128.Bl -tag -width /etc/networks -compact 129.It Pa /etc/networks 130.El 131.Sh DIAGNOSTICS 132Null pointer 133(0) returned on 134.Dv EOF 135or error. 136.Sh SEE ALSO 137.Xr networks 5 138.Pp 139.%T RFC 1101 140.Sh HISTORY 141The 142.Fn getnetent , 143.Fn getnetbyaddr , 144.Fn getnetbyname , 145.Fn setnetent , 146and 147.Fn endnetent 148functions appeared in 149.Bx 4.2 . 150.Sh BUGS 151The data space used by 152these functions is static; if future use requires the data, it should be 153copied before any subsequent calls to these functions overwrite it. 154Only Internet network 155numbers are currently understood. 156Expecting network numbers to fit 157in no more than 32 bits is probably 158naive. 159