Commit | Line | Data |
---|---|---|
ae59e04c | 1 | .\" Copyright (c) 1983, 1991 The Regents of the University of California. |
56e6bd55 | 2 | .\" All rights reserved. |
ed06f32e | 3 | .\" |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
ed06f32e | 5 | .\" |
ae59e04c | 6 | .\" @(#)getservent.3 6.6 (Berkeley) %G% |
56e6bd55 | 7 | .\" |
ae59e04c CL |
8 | .Dd |
9 | .Dt GETSERVENT 3 | |
10 | .Os BSD 4.2 | |
11 | .Sh NAME | |
12 | .Nm getservent , | |
13 | .Nm getservbyport , | |
14 | .Nm getservbyname , | |
15 | .Nm setservent , | |
16 | .Nm endservent | |
17 | .Nd get service entry | |
18 | .Sh SYNOPSIS | |
19 | .Fd #include <netdb.h> | |
20 | .Ft struct servent * | |
21 | .Fn getservent | |
22 | .Ft struct servent * | |
23 | .Fn getservbyname "char *name" "char *proto" | |
24 | .Ft struct servent * | |
25 | .Fn getservbyport "int port" proto | |
26 | .Ft void | |
27 | .Fn setservent "int stayopen" | |
28 | .Ft void | |
29 | .Fn endservent void | |
30 | .Sh DESCRIPTION | |
31 | The | |
32 | .Fn getservent , | |
33 | .Fn getservbyname , | |
ed06f32e | 34 | and |
ae59e04c CL |
35 | .Fn getservbyport |
36 | functions | |
ed06f32e KM |
37 | each return a pointer to an object with the |
38 | following structure | |
39 | containing the broken-out | |
40 | fields of a line in the network services data base, | |
ae59e04c CL |
41 | .Pa /etc/services . |
42 | .Bd -literal -offset indent | |
ed06f32e KM |
43 | struct servent { |
44 | char *s_name; /* official name of service */ | |
45 | char **s_aliases; /* alias list */ | |
50159ed7 | 46 | int s_port; /* port service resides at */ |
ed06f32e KM |
47 | char *s_proto; /* protocol to use */ |
48 | }; | |
ae59e04c CL |
49 | .Ed |
50 | .Pp | |
ed06f32e | 51 | The members of this structure are: |
ae59e04c CL |
52 | .Bl -tag -width s_aliases |
53 | .It Fa s_name | |
ed06f32e | 54 | The official name of the service. |
ae59e04c | 55 | .It Fa s_aliases |
ed06f32e | 56 | A zero terminated list of alternate names for the service. |
ae59e04c | 57 | .It Fa s_port |
ed06f32e KM |
58 | The port number at which the service resides. |
59 | Port numbers are returned in network byte order. | |
ae59e04c | 60 | .It Fa s_proto |
ed06f32e KM |
61 | The name of the protocol to use when contacting the |
62 | service. | |
ae59e04c CL |
63 | .El |
64 | .Pp | |
65 | The | |
66 | .Fn getservent | |
67 | function | |
ed06f32e | 68 | reads the next line of the file, opening the file if necessary. |
ae59e04c CL |
69 | .Pp |
70 | The | |
71 | .Fn setservent | |
72 | function | |
ed06f32e | 73 | opens and rewinds the file. If the |
ae59e04c | 74 | .Fa stayopen |
ed06f32e KM |
75 | flag is non-zero, |
76 | the net data base will not be closed after each call to | |
ae59e04c CL |
77 | .Fn getservbyname |
78 | or | |
79 | .Fn getservbyport . | |
80 | .Pp | |
81 | The | |
82 | .Fn endservent | |
83 | function | |
ed06f32e | 84 | closes the file. |
ae59e04c CL |
85 | .Pp |
86 | The | |
87 | .Fn getservbyname | |
ed06f32e | 88 | and |
ae59e04c CL |
89 | .Fn getservbyport |
90 | functions | |
ed06f32e KM |
91 | sequentially search from the beginning |
92 | of the file until a matching | |
93 | protocol name or | |
94 | port number is found, | |
ae59e04c CL |
95 | or until |
96 | .Dv EOF | |
97 | is encountered. | |
98 | If a protocol name is also supplied (non- | |
99 | .Dv NULL ) , | |
ed06f32e | 100 | searches must also match the protocol. |
ae59e04c CL |
101 | .Sh FILES |
102 | .Bl -tag -width /etc/services -compact | |
103 | .It Pa /etc/services | |
104 | .El | |
105 | .Sh DIAGNOSTICS | |
ed06f32e | 106 | Null pointer |
ae59e04c CL |
107 | (0) returned on |
108 | .Dv EOF | |
109 | or error. | |
110 | .Sh SEE ALSO | |
111 | .Xr getprotoent 3 , | |
112 | .Xr services 5 | |
113 | .Sh HISTORY | |
114 | The | |
115 | .Fn getservent , | |
116 | .Fn getservbyport , | |
117 | .Fn getservbyname , | |
118 | .Fn setservent , | |
119 | and | |
120 | .Fn endservent | |
121 | functions appeared in | |
122 | .Bx 4.2 . | |
123 | .Sh BUGS | |
124 | These functions use static data storage; | |
125 | if the data is needed for future use, it should be | |
126 | copied before any subsequent calls overwrite it. | |
127 | Expecting port numbers to fit in a 32 bit | |
ed06f32e | 128 | quantity is probably naive. |