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