xref: /dragonfly/lib/libc/rpc/bindresvport.3 (revision 2cd2d2b5)
1.\" @(#)bindresvport.3n	2.2 88/08/02 4.0 RPCSRC; from 1.7 88/03/14 SMI
2.\" $FreeBSD: src/lib/libc/rpc/bindresvport.3,v 1.10.2.2 2001/12/14 18:33:56 ru Exp $
3.\" $DragonFly: src/lib/libc/rpc/bindresvport.3,v 1.2 2003/06/17 04:26:44 dillon Exp $
4.\"
5.Dd January 27, 2000
6.Dt BINDRESVPORT 3
7.Os
8.Sh NAME
9.Nm bindresvport ,
10.Nm bindresvport_sa
11.Nd bind a socket to a privileged IP port
12.Sh SYNOPSIS
13.In rpc/rpc.h
14.Ft int
15.Fn bindresvport "int sd" "struct sockaddr_in *sin"
16.Ft int
17.Fn bindresvport_sa "int sd" "struct sockaddr *sa"
18.Sh DESCRIPTION
19.Fn bindresvport
20and
21.Fn bindresvport_sa
22are used to bind a socket descriptor to a privileged
23.Tn IP
24port, that is, a
25port number in the range 0-1023.
26.Pp
27Only root can bind to a privileged port; this call will fail for any
28other users.
29.Pp
30When
31.Va sin
32is not null,
33.Va sin->sin_family
34must be initialized to the address family of the socket, passed by
35.Va sd .
36If the value of sin->sin_port is non-zero
37.Fn bindresvport
38will attempt to use that specific port.  If it fails, it chooses another
39privileged port automatically.
40.Pp
41It is legal to pass null pointer to
42.Va sin .
43In this case, the caller cannot get the port number
44.Fn bindresvport
45has picked.
46.Pp
47Function prototype of
48.Fn bindresvport
49is biased to
50.Dv AF_INET
51socket.
52.Fn bindresvport_sa
53acts exactly the same, with more neutral function prototype.
54Note that both functions behave exactly the same, and
55both support
56.Dv AF_INET6
57sockets as well as
58.Dv AF_INET
59sockets.
60.Sh RETURN VALUES
61.Fn bindresvport
62and
63.Fn bindresvport_sa
64return 0 if they are successful, otherwise \-1 is returned and
65.Va errno
66set to reflect the cause of the error.
67.Sh ERRORS
68The
69.Fn bindresvport
70and
71.Fn bindresvport_sa
72functions fail if:
73.Bl -tag -width Er
74.It Bq Er EBADF
75.Fa sd
76is not a valid descriptor.
77.It Bq Er ENOTSOCK
78.Fa sd
79is not a socket.
80.It Bq Er EADDRNOTAVAIL
81The specified address is not available from the local machine.
82.It Bq Er EADDRINUSE
83The specified address is already in use.
84.It Bq Er EINVAL
85The socket is already bound to an address,
86or the socket family and the family of specified address mismatch.
87.It Bq Er EACCES
88The requested address is protected, and the current user
89has inadequate permission to access it.
90.It Bq Er EFAULT
91The
92.Fa name
93parameter is not in a valid part of the user
94address space.
95.It Bq Er ENOBUFS
96Insufficient resources were available in the system
97to perform the operation.
98.It Bq Er EPFNOSUPPORT
99The protocol family has not been configured into the
100system, no implementation for it exists,
101or address family did not match between arguments.
102.El
103.Sh "SEE ALSO"
104.Xr bind 2 ,
105.Xr socket 2 ,
106.Xr rresvport 3 ,
107.Xr rresvport_af 3
108