xref: /freebsd/lib/libc/rpc/bindresvport.3 (revision f11a166425a05ab79fb04d9dc914273be07ef440)
199064799SGarrett Wollman.\" @(#)bindresvport.3n	2.2 88/08/02 4.0 RPCSRC; from 1.7 88/03/14 SMI
27f3dea24SPeter Wemm.\" $FreeBSD$
3fbc400a6SNik Clayton.\"
4f11a1664SBruce Evans.Dd January 27, 2000
5639460dcSMike Pritchard.Dt BINDRESVPORT 3
6639460dcSMike Pritchard.Os
7639460dcSMike Pritchard.Sh NAME
8469bed11SYoshinobu Inoue.Nm bindresvport ,
9f11a1664SBruce Evans.Nm bindresvport_sa
10639460dcSMike Pritchard.Ndbind a socket to a privileged IP port
11639460dcSMike Pritchard.Sh SYNOPSIS
12f11a1664SBruce Evans.Fd #include <rpc/rpc.h>
13639460dcSMike Pritchard.Ft int
14469bed11SYoshinobu Inoue.Fn bindresvport "int sd" "struct sockaddr_in *sin"
15469bed11SYoshinobu Inoue.Ft int
16469bed11SYoshinobu Inoue.Fn bindresvport_sa "int sd" "struct sockaddr *sa"
17639460dcSMike Pritchard.Sh DESCRIPTION
18f11a1664SBruce Evans.Fn bindresvport
19469bed11SYoshinobu Inoueand
20f11a1664SBruce Evans.Fn bindresvport_sa
21469bed11SYoshinobu Inoueare used to bind a socket descriptor to a privileged
22dd50fc21SPeter Wemm.Tn IP
2399064799SGarrett Wollmanport, that is, a
2499064799SGarrett Wollmanport number in the range 0-1023.
25639460dcSMike Pritchard.Pp
2699064799SGarrett WollmanOnly root can bind to a privileged port; this call will fail for any
2799064799SGarrett Wollmanother users.
28dd50fc21SPeter Wemm.Pp
29469bed11SYoshinobu InoueWhen
30469bed11SYoshinobu Inoue.Va sin
31469bed11SYoshinobu Inoueis not null,
32469bed11SYoshinobu Inoue.Va sin->sin_family
33469bed11SYoshinobu Inouemust be initialized to the address family of the socket, passed by
34469bed11SYoshinobu Inoue.Va sd .
35dd50fc21SPeter WemmIf the value of sin->sin_port is non-zero
36dd50fc21SPeter Wemm.Fn bindresvport
37dd50fc21SPeter Wemmwill attempt to use that specific port.  If it fails, it chooses another
38dd50fc21SPeter Wemmprivileged port automatically.
39469bed11SYoshinobu Inoue.Pp
40469bed11SYoshinobu InoueIt is legal to pass null pointer to
41469bed11SYoshinobu Inoue.Va sin .
42469bed11SYoshinobu InoueIn this case, the caller cannot get the port number
43469bed11SYoshinobu Inoue.Fn bindresvport
44469bed11SYoshinobu Inouehas picked.
45469bed11SYoshinobu Inoue.Pp
46469bed11SYoshinobu InoueFunction prototype of
47469bed11SYoshinobu Inoue.Fn bindresvport
48469bed11SYoshinobu Inoueis biased to
49469bed11SYoshinobu Inoue.Dv AF_INET
50469bed11SYoshinobu Inouesocket.
51469bed11SYoshinobu Inoue.Fn bindresvport_sa
52469bed11SYoshinobu Inoueacts exactly the same, with more neutral function prototype.
53469bed11SYoshinobu InoueNote that both functions behave exactly the same, and
54469bed11SYoshinobu Inoueboth support
55469bed11SYoshinobu Inoue.Dv AF_INET6
56469bed11SYoshinobu Inouesockets as well as
57469bed11SYoshinobu Inoue.Dv AF_INET
58469bed11SYoshinobu Inouesockets.
59469bed11SYoshinobu Inoue.Sh RETURN VALUES
60469bed11SYoshinobu Inoue.Fn bindresvport
61f11a1664SBruce Evansand
62f11a1664SBruce Evans.Fn bindresvport_sa
63f11a1664SBruce Evansreturn 0 if they are successful, otherwise \-1 is returned and
64469bed11SYoshinobu Inoue.Va errno
65469bed11SYoshinobu Inoueset to reflect the cause of the error.
66469bed11SYoshinobu Inoue.Sh ERRORS
67469bed11SYoshinobu InoueThe
68469bed11SYoshinobu Inoue.Fn bindresvport
69f11a1664SBruce Evansand
70f11a1664SBruce Evans.Fn bindresvport_sa
71f11a1664SBruce Evansfunctions fail if:
72469bed11SYoshinobu Inoue.Bl -tag -width Er
73469bed11SYoshinobu Inoue.It Bq Er EBADF
74469bed11SYoshinobu Inoue.Fa sd
75469bed11SYoshinobu Inoueis not a valid descriptor.
76469bed11SYoshinobu Inoue.It Bq Er ENOTSOCK
77469bed11SYoshinobu Inoue.Fa sd
78469bed11SYoshinobu Inoueis not a socket.
79469bed11SYoshinobu Inoue.It Bq Er EADDRNOTAVAIL
80469bed11SYoshinobu InoueThe specified address is not available from the local machine.
81469bed11SYoshinobu Inoue.It Bq Er EADDRINUSE
82469bed11SYoshinobu InoueThe specified address is already in use.
83469bed11SYoshinobu Inoue.It Bq Er EINVAL
84469bed11SYoshinobu InoueThe socket is already bound to an address,
85469bed11SYoshinobu Inoueor the socket family and the family of specified address mismatch.
86469bed11SYoshinobu Inoue.It Bq Er EACCES
87469bed11SYoshinobu InoueThe requested address is protected, and the current user
88469bed11SYoshinobu Inouehas inadequate permission to access it.
89469bed11SYoshinobu Inoue.It Bq Er EFAULT
90469bed11SYoshinobu InoueThe
91469bed11SYoshinobu Inoue.Fa name
92469bed11SYoshinobu Inoueparameter is not in a valid part of the user
93469bed11SYoshinobu Inoueaddress space.
94469bed11SYoshinobu Inoue.It Bq Er ENOBUFS
95469bed11SYoshinobu InoueInsufficient resources were available in the system
96469bed11SYoshinobu Inoueto perform the operation.
97469bed11SYoshinobu Inoue.It Bq Er EPFNOSUPPORT
98469bed11SYoshinobu InoueThe protocol family has not been configured into the
99469bed11SYoshinobu Inouesystem, no implementation for it exists,
100469bed11SYoshinobu Inoueor address family did not match between arguments.
101469bed11SYoshinobu Inoue.El
10242b4f28eSYoshinobu Inoue.Sh "SEE ALSO"
103469bed11SYoshinobu Inoue.Xr bind 2 ,
104469bed11SYoshinobu Inoue.Xr socket 2 ,
105469bed11SYoshinobu Inoue.Xr rresvport 3 ,
106469bed11SYoshinobu Inoue.Xr rresvport_af 3
107