1*b5677b36Schristos.\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 2*b5677b36Schristos.\" Copyright (c) 1995,1996,1999 by Internet Software Consortium 3*b5677b36Schristos.\" 4*b5677b36Schristos.\" Permission to use, copy, modify, and distribute this software for any 5*b5677b36Schristos.\" purpose with or without fee is hereby granted, provided that the above 6*b5677b36Schristos.\" copyright notice and this permission notice appear in all copies. 7*b5677b36Schristos.\" 8*b5677b36Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 9*b5677b36Schristos.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10*b5677b36Schristos.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 11*b5677b36Schristos.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12*b5677b36Schristos.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13*b5677b36Schristos.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 14*b5677b36Schristos.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15*b5677b36Schristos.\" 16*b5677b36Schristos.\" Id: getnetent.man3,v 1.2 2009/01/21 00:12:34 each Exp 17*b5677b36Schristos.\" 18*b5677b36Schristos.Dd May 20, 1996 19*b5677b36Schristos.Dt GETNETENT 3 20*b5677b36Schristos.Os BSD 4 21*b5677b36Schristos.Sh NAME 22*b5677b36Schristos.Nm getnetent , 23*b5677b36Schristos.Nm getnetbyaddr , 24*b5677b36Schristos.Nm getnetbyname , 25*b5677b36Schristos.Nm setnetent , 26*b5677b36Schristos.Nm endnetent 27*b5677b36Schristos.Nd get networks entry 28*b5677b36Schristos.Sh SYNOPSIS 29*b5677b36Schristos.Fd #include <netdb.h> 30*b5677b36Schristos.Ft struct netent * 31*b5677b36Schristos.Fn getnetent 32*b5677b36Schristos.Ft struct netent * 33*b5677b36Schristos.Fn getnetbyname "char name" 34*b5677b36Schristos.Ft struct netent * 35*b5677b36Schristos.Fn getnetbyaddr "unsigned long net" "int type" 36*b5677b36Schristos.Ft void 37*b5677b36Schristos.Fn setnetent "int stayopen" 38*b5677b36Schristos.Ft void 39*b5677b36Schristos.Fn endnetent 40*b5677b36Schristos.Sh DESCRIPTION 41*b5677b36SchristosThe 42*b5677b36Schristos.Fn getnetent , 43*b5677b36Schristos.Fn getnetbyname , 44*b5677b36Schristosand 45*b5677b36Schristos.Fn getnetbyaddr 46*b5677b36Schristossubroutines 47*b5677b36Schristoseach return a pointer to an object with the following structure 48*b5677b36Schristoscontaining the broken-out fields of a line in the 49*b5677b36Schristos.Pa networks 50*b5677b36Schristosdatabase. 51*b5677b36Schristos.Bd -literal -offset indent 52*b5677b36Schristosstruct netent { 53*b5677b36Schristos char *n_name; /* official name of net */ 54*b5677b36Schristos char **n_aliases; /* alias list */ 55*b5677b36Schristos int n_addrtype; /* net number type */ 56*b5677b36Schristos long n_net; /* net number */ 57*b5677b36Schristos}; 58*b5677b36Schristos.Ed 59*b5677b36Schristos.Pp 60*b5677b36SchristosThe members of this structure are: 61*b5677b36Schristos.Bl -tag -width "n_addrtype" 62*b5677b36Schristos.It n_name 63*b5677b36SchristosThe official name of the network. 64*b5677b36Schristos.It n_aliases 65*b5677b36SchristosA zero-terminated list of alternate names for the network. 66*b5677b36Schristos.It n_addrtype 67*b5677b36SchristosThe type of the network number returned: 68*b5677b36Schristos.Dv AF_INET . 69*b5677b36Schristos.It n_net 70*b5677b36SchristosThe network number. Network numbers are returned in machine byte 71*b5677b36Schristosorder. 72*b5677b36Schristos.El 73*b5677b36Schristos.Pp 74*b5677b36SchristosIf the 75*b5677b36Schristos.Fa stayopen 76*b5677b36Schristosflag on a 77*b5677b36Schristos.Fn setnetent 78*b5677b36Schristossubroutine is NULL, the 79*b5677b36Schristos.Pa networks 80*b5677b36Schristosdatabase is opened. Otherwise, the 81*b5677b36Schristos.Fn setnetent 82*b5677b36Schristoshas the effect of rewinding the 83*b5677b36Schristos.Pa networks 84*b5677b36Schristosdatabase. 85*b5677b36SchristosThe 86*b5677b36Schristos.Fn endnetent 87*b5677b36Schristossubroutine may be called to 88*b5677b36Schristosclose the 89*b5677b36Schristos.Pa networks 90*b5677b36Schristosdatabase when processing is complete. 91*b5677b36Schristos.Pp 92*b5677b36SchristosThe 93*b5677b36Schristos.Fn getnetent 94*b5677b36Schristossubroutine simply reads the next 95*b5677b36Schristosline while 96*b5677b36Schristos.Fn getnetbyname 97*b5677b36Schristosand 98*b5677b36Schristos.Fn getnetbyaddr 99*b5677b36Schristossearch until a matching 100*b5677b36Schristos.Fa name 101*b5677b36Schristosor 102*b5677b36Schristos.Fa net 103*b5677b36Schristosnumber is found 104*b5677b36Schristos(or until 105*b5677b36Schristos.Dv EOF 106*b5677b36Schristosis encountered). The 107*b5677b36Schristos.Fa type must be 108*b5677b36Schristos.Dv AF_INET . 109*b5677b36SchristosThe 110*b5677b36Schristos.Fn getnetent 111*b5677b36Schristossubroutine keeps a pointer in the database, allowing 112*b5677b36Schristossuccessive calls to be used to search the entire file. 113*b5677b36Schristos.Pp 114*b5677b36SchristosBefore a 115*b5677b36Schristos.Ic while 116*b5677b36Schristosloop using 117*b5677b36Schristos.Fn getnetent , 118*b5677b36Schristosa call to 119*b5677b36Schristos.Fn setnetent 120*b5677b36Schristosmust be made 121*b5677b36Schristosin order to perform initialization; a call to 122*b5677b36Schristos.Fn endnetent 123*b5677b36Schristosmust be used after the loop. Both 124*b5677b36Schristos.Fn getnetbyname 125*b5677b36Schristosand 126*b5677b36Schristos.Fn getnetbyaddr 127*b5677b36Schristosmake calls to 128*b5677b36Schristos.Fn setnetent 129*b5677b36Schristosand 130*b5677b36Schristos.Fn endnetent . 131*b5677b36Schristos.Sh FILES 132*b5677b36Schristos.Pa /etc/networks 133*b5677b36Schristos.Sh DIAGNOSTICS 134*b5677b36SchristosNull pointer (0) returned on 135*b5677b36Schristos.Dv EOF 136*b5677b36Schristosor error. 137*b5677b36Schristos.Sh SEE ALSO 138*b5677b36Schristos.Xr networks 5 , 139*b5677b36SchristosRFC 1101. 140*b5677b36Schristos.Sh HISTORY 141*b5677b36SchristosThe 142*b5677b36Schristos.Fn "getnetent" , 143*b5677b36Schristos.Fn "getnetbyaddr" , 144*b5677b36Schristos.Fn "getnetbyname" , 145*b5677b36Schristos.Fn "setnetent" , 146*b5677b36Schristosand 147*b5677b36Schristos.Fn "endnetent" 148*b5677b36Schristosfunctions appeared in 149*b5677b36Schristos.Bx 4.2 . 150*b5677b36Schristos.Sh BUGS 151*b5677b36SchristosThe data space used by these functions is static; if future use requires the 152*b5677b36Schristosdata, it should be copied before any subsequent calls to these functions 153*b5677b36Schristosoverwrite it. Only Internet network numbers are currently understood. 154*b5677b36SchristosExpecting network numbers to fit in no more than 32 bits is probably naive. 155