xref: /freebsd/lib/libc/rpc/bindresvport.3 (revision 17d6c636720d00f77e5d098daf4c278f89d84f7b)
1.\" @(#)bindresvport.3n	2.2 88/08/02 4.0 RPCSRC; from 1.7 88/03/14 SMI
2.\" $NetBSD: bindresvport.3,v 1.8 2000/07/05 15:45:33 msaitoh Exp $
3.\" $FreeBSD$
4.\"
5.Dd November 22, 1987
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 sys/types.h
16.In rpc/rpc.h
17.Ft int
18.Fn bindresvport "int sd" "struct sockaddr_in *sin"
19.Ft int
20.Fn bindresvport_sa "int sd" "struct sockaddr *sa"
21.Sh DESCRIPTION
22.Fn bindresvport
23and
24.Fn bindresvport_sa
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.
68.Fn bindresvport_sa
69acts exactly the same, with more neutral function prototype.
70Note that both functions behave exactly the same, and
71both support
72.Dv AF_INET6
73sockets as well as
74.Dv AF_INET
75sockets.
76.Sh RETURN VALUES
77.Rv -std bindresvport
78.Sh ERRORS
79.Bl -tag -width Er
80.It Bq Er EPFNOSUPPORT
81If second argument was supplied,
82and address family did not match between arguments.
83.El
84.Pp
85.Fn bindresvport
86may also fail and set
87.Va errno
88for any of the errors specified for the calls
89.Xr bind 2 ,
90.Xr getsockopt 2 ,
91or
92.Xr setsockopt 2 .
93.Sh SEE ALSO
94.Xr bind 2 ,
95.Xr getsockopt 2 ,
96.Xr setsockopt 2 ,
97.Xr ip 4
98