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