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