xref: /netbsd/lib/libc/rpc/bindresvport.3 (revision bf9ec67e)
1.\"	@(#)bindresvport.3n	2.2 88/08/02 4.0 RPCSRC; from 1.7 88/03/14 SMI
2.\"	$NetBSD: bindresvport.3,v 1.10 2002/02/07 07:00:23 ross Exp $
3.\"
4.Dd November 22, 1987
5.Dt BINDRESVPORT 3
6.Os
7.Sh NAME
8.Nm bindresvport ,
9.Nm bindresvport_sa
10.Nd bind a socket to a privileged IP port
11.Sh LIBRARY
12.Lb libc
13.Sh SYNOPSIS
14.Fd #include \*[Lt]sys/types.h\*[Gt]
15.Fd #include \*[Lt]rpc/rpc.h\*[Gt]
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.
28The routine returns 0 if it is successful,
29otherwise -1 is returned and
30.Va errno
31set to reflect the cause of the error.
32.Pp
33If
34.Fa sin
35is a pointer to a
36.Ft "struct sockaddr_in"
37then the appropriate fields in the structure should be defined.
38Note that
39.Fa sin-\*[Gt]sin_family
40must be initialized to the address family of the socket, passed by
41.Fa sd .
42If
43.Fa sin-\*[Gt]sin_port
44is
45.Sq 0
46then an anonymous port (in the range 600-1023) will be
47chosen, and if
48.Xr bind 2
49is successful, the
50.Fa sin-\*[Gt]sin_port
51will be updated to contain the allocated port.
52.Pp
53If
54.Fa sin
55is the
56.Dv NULL
57pointer,
58an anonymous port will be allocated (as above).
59However, there is no way for
60.Fn bindresvport
61to return the allocated port in this case.
62.Pp
63Only root can bind to a privileged port; this call will fail for any
64other users.
65.Pp
66Function prototype of
67.Fn bindresvport
68is biased to
69.Dv AF_INET
70socket.
71.Fn bindresvport_sa
72acts exactly the same, with more neutral function prototype.
73Note that both functions behave exactly the same, and
74both support
75.Dv AF_INET6
76sockets as well as
77.Dv AF_INET
78sockets.
79.Sh RETURN VALUES
80If the bind is successful, a 0 value is returned.
81A return value of -1 indicates an error, which is
82further specified in the global
83.Va errno .
84.Sh ERRORS
85.Bl -tag -width Er
86.It Bq Er EPFNOSUPPORT
87If second argument was supplied,
88and address family did not match between arguments.
89.El
90.Pp
91.Fn bindresvport
92may also fail and set
93.Va errno
94for any of the errors specified for the calls
95.Xr bind 2 ,
96.Xr getsockopt 2 ,
97or
98.Xr setsockopt 2 .
99.Sh SEE ALSO
100.Xr bind 2 ,
101.Xr getsockopt 2 ,
102.Xr setsockopt 2 ,
103.Xr ip 4
104