67246631fa29d90615ad28e9e9d354d466af059e
[platform/upstream/libtirpc.git] / man / bindresvport.3t
1 .\" @(#)bindresvport.3n 2.2 88/08/02 4.0 RPCSRC; from 1.7 88/03/14 SMI
2 .\"
3 .Dd November 22, 1987
4 .Dt BINDRESVPORT 3
5 .Os
6 .Sh NAME
7 .Nm bindresvport ,
8 .Nm bindresvport_sa
9 .Nd bind a socket to a privileged IP port
10 .Sh LIBRARY
11 .Lb libc
12 .Sh SYNOPSIS
13 .In sys/types.h
14 .In rpc/rpc.h
15 .Ft int
16 .Fn bindresvport "int sd" "struct sockaddr_in *sin"
17 .Ft int
18 .Fn bindresvport_sa "int sd" "struct sockaddr *sa"
19 .Sh DESCRIPTION
20 The
21 .Fn bindresvport
22 and
23 .Fn bindresvport_sa
24 functions
25 are used to bind a socket descriptor to a privileged
26 .Tn IP
27 port, that is, a
28 port number in the range 0-1023.
29 .Pp
30 If
31 .Fa sin
32 is a pointer to a
33 .Ft "struct sockaddr_in"
34 then the appropriate fields in the structure should be defined.
35 Note that
36 .Fa sin->sin_family
37 must be initialized to the address family of the socket, passed by
38 .Fa sd .
39 If
40 .Fa sin->sin_port
41 is
42 .Sq 0
43 then an anonymous port (in the range 600-1023) will be
44 chosen, and if
45 .Xr bind 2
46 is successful, the
47 .Fa sin->sin_port
48 will be updated to contain the allocated port.
49 .Pp
50 If
51 .Fa sin
52 is the
53 .Dv NULL
54 pointer,
55 an anonymous port will be allocated (as above).
56 However, there is no way for
57 .Fn bindresvport
58 to return the allocated port in this case.
59 .Pp
60 Only root can bind to a privileged port; this call will fail for any
61 other users.
62 .Pp
63 Function prototype of
64 .Fn bindresvport
65 is biased to
66 .Dv AF_INET
67 socket.
68 The
69 .Fn bindresvport_sa
70 function
71 acts exactly the same, with more neutral function prototype.
72 Note that both functions behave exactly the same, and
73 both support
74 .Dv AF_INET6
75 sockets as well as
76 .Dv AF_INET
77 sockets.
78 .Sh RETURN VALUES
79 .Rv -std bindresvport
80 .Sh ERRORS
81 .Bl -tag -width Er
82 .It Bq Er EPFNOSUPPORT
83 If second argument was supplied,
84 and address family did not match between arguments.
85 .El
86 .Pp
87 The
88 .Fn bindresvport
89 function
90 may also fail and set
91 .Va errno
92 for any of the errors specified for the calls
93 .Xr bind 2 ,
94 .Xr getsockopt 2 ,
95 or
96 .Xr setsockopt 2 .
97 .Sh SEE ALSO
98 .Xr bind 2 ,
99 .Xr getsockopt 2 ,
100 .Xr setsockopt 2 ,
101 .Xr ip 4