1.\" $OpenBSD: getprotoent.3,v 1.18 2013/06/05 03:39:23 tedu 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.Dd $Mdocdate: June 5 2013 $ 31.Dt GETPROTOENT 3 32.Os 33.Sh NAME 34.Nm getprotoent , 35.Nm getprotoent_r , 36.Nm getprotobynumber , 37.Nm getprotobynumber_r , 38.Nm getprotobyname , 39.Nm getprotobyname_r , 40.Nm setprotoent , 41.Nm setprotoent_r , 42.Nm endprotoent , 43.Nm endprotoent_r 44.Nd get protocol entry 45.Sh SYNOPSIS 46.In netdb.h 47.Ft struct protoent * 48.Fn getprotoent "void" 49.Ft int 50.Fn getprotoent_r "struct protoent *protoent" "struct protoent_data *protoent_data" 51.Ft struct protoent * 52.Fn getprotobyname "const char *name" 53.Ft int 54.Fn getprotobyname_r "const char *name" "struct protoent *protoent" "struct protoent_data *protoent_data" 55.Ft struct protoent * 56.Fn getprotobynumber "int proto" 57.Ft int 58.Fn getprotobynumber_r "int proto" "struct protoent *protoent" "struct protoent_data *protoent_data" 59.Ft void 60.Fn setprotoent "int stayopen" 61.Ft void 62.Fn setprotoent_r "int stayopen" "struct protoent_data *protoent_data" 63.Ft void 64.Fn endprotoent "void" 65.Ft void 66.Fn endprotoent_r "struct protoent_data *protoent_data" 67.Sh DESCRIPTION 68The 69.Fn getprotoent , 70.Fn getprotobyname , 71and 72.Fn getprotobynumber 73functions each return a pointer to an object with the following structure 74containing the broken-out fields of a line in the network protocol database, 75.Pa /etc/protocols . 76.Bd -literal -offset indent 77.Pp 78struct protoent { 79 char *p_name; /* official name of protocol */ 80 char **p_aliases; /* alias list */ 81 int p_proto; /* protocol number */ 82}; 83.Ed 84.Pp 85The members of this structure are: 86.Bl -tag -width p_aliases 87.It Fa p_name 88The official name of the protocol. 89.It Fa p_aliases 90A null-terminated list of alternate names for the protocol. 91.It Fa p_proto 92The protocol number. 93.El 94.Pp 95The 96.Fn getprotoent 97function reads the next line of the file, opening the file if necessary. 98.Pp 99The 100.Fn setprotoent 101function opens and rewinds the file. 102If the 103.Fa stayopen 104flag is non-zero, 105the protocol database will not be closed after each call to 106.Fn getprotobyname 107or 108.Fn getprotobynumber . 109.Pp 110The 111.Fn endprotoent 112function closes the file. 113.Pp 114The 115.Fn getprotobyname 116and 117.Fn getprotobynumber 118functions sequentially search from the beginning of the file until a 119matching protocol name or protocol number is found, or until 120.Dv EOF 121is encountered. 122.Pp 123The 124.Fn getprotoent_r , 125.Fn getprotobyport_r , 126.Fn getprotobyname_r , 127.Fn setprotoent_r , 128and 129.Fn endprotoent_r 130functions are reentrant versions of the above functions that take a 131pointer to a 132.Vt protoent_data 133structure which is used to store state information. 134The structure must be zero-filled before it is used 135and should be considered opaque for the sake of portability. 136.Pp 137The 138.Fn getprotoent_r , 139.Fn getprotobyport_r , 140and 141.Fn getprotobyname_r 142functions 143also take a pointer to a 144.Vt protoent 145structure which is used to store the results of the database lookup. 146.Sh RETURN VALUES 147The 148.Fn getprotoent , 149.Fn getprotobyport , 150and 151.Fn getprotobyname 152functions return a pointer to a 153.Vt protoent 154structure on success or a null pointer if end-of-file 155is reached or an error occurs. 156.Pp 157The 158.Fn getprotoent_r , 159.Fn getprotobyport_r , 160and 161.Fn getprotobyname_r 162functions return 0 on success or \-1 if end-of-file 163is reached or an error occurs. 164.Sh FILES 165.Bl -tag -width /etc/protocols -compact 166.It Pa /etc/protocols 167.El 168.Sh SEE ALSO 169.Xr protocols 5 170.Sh STANDARDS 171The 172.Fn getprotoent , 173.Fn getprotobynumber , 174.Fn getprotobyname , 175.Fn setprotoent , 176and 177.Fn endprotoent 178functions conform to 179.St -p1003.1-2004 . 180.Pp 181The 182.Fn getprotoent_r , 183.Fn getprotobyport_r , 184.Fn getprotobyname_r , 185.Fn setprotoent_r , 186and 187.Fn endprotoent_r 188functions are not currently standardized. 189This implementation follows the API used by HP, IBM, and Digital. 190.Sh HISTORY 191The 192.Fn getprotoent , 193.Fn getprotobynumber , 194.Fn getprotobyname , 195.Fn setprotoent , 196and 197.Fn endprotoent 198functions appeared in 199.Bx 4.2 . 200.Pp 201The 202.Fn getprotoent_r , 203.Fn getprotobyport_r , 204.Fn getprotobyname_r , 205.Fn setprotoent_r , 206and 207.Fn endprotoent_r 208functions appeared in 209.Ox 3.7 . 210.Sh BUGS 211The non-reentrant functions use a static data space; if the data is needed 212for future use, it should be copied before any subsequent calls overwrite it. 213Only the Internet protocols are currently understood. 214