1.\" Copyright (c) 1983, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)getnetent.3 6.6 (Berkeley) 04/19/91 7.\" 8.Dd 9.Dt GETNETENT 3 10.Os BSD 4.2 11.Sh NAME 12.Nm getnetent , 13.Nm getnetbyaddr , 14.Nm getnetbyname , 15.Nm setnetent , 16.Nm endnetent 17.Nd get network entry 18.Sh SYNOPSIS 19.Fd #include <netdb.h> 20.Ft struct netent * 21.Fn getnetent 22.Ft struct netent * 23.Fn getnetbyname "char *name" 24.Ft struct netent * 25.Fn getnetbyaddr "long net" "int type" 26.Fn setnetent "int stayopen" 27.Fn endnetent 28.Sh DESCRIPTION 29The 30.Fn getnetent , 31.Fn getnetbyname , 32and 33.Fn getnetbyaddr 34functions 35each return a pointer to an object with the 36following structure 37containing the broken-out 38fields of a line in the network data base, 39.Pa /etc/networks . 40.Bd -literal -offset indent 41struct netent { 42 char *n_name; /* official name of net */ 43 char **n_aliases; /* alias list */ 44 int n_addrtype; /* net number type */ 45 unsigned long n_net; /* net number */ 46}; 47.Ed 48.Pp 49The members of this structure are: 50.Bl -tag -width n_addrtype 51.It Fa n_name 52The official name of the network. 53.It Fa n_aliases 54A zero terminated list of alternate names for the network. 55.It Fa n_addrtype 56The type of the network number returned; currently only AF_INET. 57.It Fa n_net 58The network number. Network numbers are returned in machine byte 59order. 60.El 61.Pp 62The 63.Fn getnetent 64function 65reads the next line of the file, opening the file if necessary. 66.Pp 67The 68.Fn setnetent 69function 70opens and rewinds the file. If the 71.Fa stayopen 72flag is non-zero, 73the net data base will not be closed after each call to 74.Fn getnetbyname 75or 76.Fn getnetbyaddr . 77.Pp 78The 79.Fn endnetent 80function 81closes the file. 82.Pp 83The 84.Fn getnetbyname 85function 86and 87.Fn getnetbyaddr 88sequentially search from the beginning 89of the file until a matching 90net name or 91net address and type is found, 92or until 93.Dv EOF 94is encountered. 95Network numbers are supplied in host order. 96.Sh FILES 97.Bl -tag -width /etc/networks -compact 98.It Pa /etc/networks 99.El 100.Sh DIAGNOSTICS 101Null pointer 102(0) returned on 103.Dv EOF 104or error. 105.Sh SEE ALSO 106.Xr networks 5 107.Sh HISTORY 108The 109.Fn getnetent , 110.Fn getnetbyaddr , 111.Fn getnetbyname , 112.Fn setnetent , 113and 114.Fn endnetent 115functions appeared in 116.Bx 4.2 . 117.Sh BUGS 118The data space used by 119these functions is static; if future use requires the data, it should be 120copied before any subsequent calls to these functions overwrite it. 121Only Internet network 122numbers are currently understood. 123Expecting network numbers to fit 124in no more than 32 bits is probably 125naive. 126