xref: /freebsd/lib/libc/rpc/bindresvport.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
18360efbdSAlfred Perlstein.\" $NetBSD: bindresvport.3,v 1.8 2000/07/05 15:45:33 msaitoh Exp $
2fbc400a6SNik Clayton.\"
38360efbdSAlfred Perlstein.Dd November 22, 1987
4639460dcSMike Pritchard.Dt BINDRESVPORT 3
5639460dcSMike Pritchard.Os
6639460dcSMike Pritchard.Sh NAME
7469bed11SYoshinobu Inoue.Nm bindresvport ,
8f11a1664SBruce Evans.Nm bindresvport_sa
9639460dcSMike Pritchard.Nd bind a socket to a privileged IP port
108360efbdSAlfred Perlstein.Sh LIBRARY
118360efbdSAlfred Perlstein.Lb libc
12639460dcSMike Pritchard.Sh SYNOPSIS
1332eef9aeSRuslan Ermilov.In sys/types.h
1432eef9aeSRuslan Ermilov.In rpc/rpc.h
15639460dcSMike Pritchard.Ft int
16469bed11SYoshinobu Inoue.Fn bindresvport "int sd" "struct sockaddr_in *sin"
17469bed11SYoshinobu Inoue.Ft int
18469bed11SYoshinobu Inoue.Fn bindresvport_sa "int sd" "struct sockaddr *sa"
19639460dcSMike Pritchard.Sh DESCRIPTION
201fae73b1SRuslan ErmilovThe
21f11a1664SBruce Evans.Fn bindresvport
22469bed11SYoshinobu Inoueand
23f11a1664SBruce Evans.Fn bindresvport_sa
241fae73b1SRuslan Ermilovfunctions
25469bed11SYoshinobu Inoueare used to bind a socket descriptor to a privileged
26dd50fc21SPeter Wemm.Tn IP
2799064799SGarrett Wollmanport, that is, a
2899064799SGarrett Wollmanport number in the range 0-1023.
29639460dcSMike Pritchard.Pp
308360efbdSAlfred PerlsteinIf
318360efbdSAlfred Perlstein.Fa sin
328360efbdSAlfred Perlsteinis a pointer to a
338360efbdSAlfred Perlstein.Ft "struct sockaddr_in"
348360efbdSAlfred Perlsteinthen the appropriate fields in the structure should be defined.
358360efbdSAlfred PerlsteinNote that
368360efbdSAlfred Perlstein.Fa sin->sin_family
378360efbdSAlfred Perlsteinmust be initialized to the address family of the socket, passed by
388360efbdSAlfred Perlstein.Fa sd .
398360efbdSAlfred PerlsteinIf
408360efbdSAlfred Perlstein.Fa sin->sin_port
418360efbdSAlfred Perlsteinis
428360efbdSAlfred Perlstein.Sq 0
438360efbdSAlfred Perlsteinthen an anonymous port (in the range 600-1023) will be
448360efbdSAlfred Perlsteinchosen, and if
458360efbdSAlfred Perlstein.Xr bind 2
468360efbdSAlfred Perlsteinis successful, the
478360efbdSAlfred Perlstein.Fa sin->sin_port
488360efbdSAlfred Perlsteinwill be updated to contain the allocated port.
498360efbdSAlfred Perlstein.Pp
508360efbdSAlfred PerlsteinIf
518360efbdSAlfred Perlstein.Fa sin
528360efbdSAlfred Perlsteinis the
538360efbdSAlfred Perlstein.Dv NULL
548360efbdSAlfred Perlsteinpointer,
558360efbdSAlfred Perlsteinan anonymous port will be allocated (as above).
568360efbdSAlfred PerlsteinHowever, there is no way for
578360efbdSAlfred Perlstein.Fn bindresvport
588360efbdSAlfred Perlsteinto return the allocated port in this case.
598360efbdSAlfred Perlstein.Pp
6099064799SGarrett WollmanOnly root can bind to a privileged port; this call will fail for any
6199064799SGarrett Wollmanother users.
62dd50fc21SPeter Wemm.Pp
63469bed11SYoshinobu InoueFunction prototype of
64469bed11SYoshinobu Inoue.Fn bindresvport
65469bed11SYoshinobu Inoueis biased to
66469bed11SYoshinobu Inoue.Dv AF_INET
67469bed11SYoshinobu Inouesocket.
681fae73b1SRuslan ErmilovThe
69469bed11SYoshinobu Inoue.Fn bindresvport_sa
701fae73b1SRuslan Ermilovfunction
71469bed11SYoshinobu Inoueacts exactly the same, with more neutral function prototype.
72469bed11SYoshinobu InoueNote that both functions behave exactly the same, and
73469bed11SYoshinobu Inoueboth support
74469bed11SYoshinobu Inoue.Dv AF_INET6
75469bed11SYoshinobu Inouesockets as well as
76469bed11SYoshinobu Inoue.Dv AF_INET
77469bed11SYoshinobu Inouesockets.
78469bed11SYoshinobu Inoue.Sh RETURN VALUES
798360efbdSAlfred Perlstein.Rv -std bindresvport
80469bed11SYoshinobu Inoue.Sh ERRORS
81469bed11SYoshinobu Inoue.Bl -tag -width Er
82469bed11SYoshinobu Inoue.It Bq Er EPFNOSUPPORT
838360efbdSAlfred PerlsteinIf second argument was supplied,
848360efbdSAlfred Perlsteinand address family did not match between arguments.
85469bed11SYoshinobu Inoue.El
868360efbdSAlfred Perlstein.Pp
871fae73b1SRuslan ErmilovThe
888360efbdSAlfred Perlstein.Fn bindresvport
891fae73b1SRuslan Ermilovfunction
908360efbdSAlfred Perlsteinmay also fail and set
918360efbdSAlfred Perlstein.Va errno
928360efbdSAlfred Perlsteinfor any of the errors specified for the calls
93469bed11SYoshinobu Inoue.Xr bind 2 ,
948360efbdSAlfred Perlstein.Xr getsockopt 2 ,
958360efbdSAlfred Perlsteinor
968360efbdSAlfred Perlstein.Xr setsockopt 2 .
978360efbdSAlfred Perlstein.Sh SEE ALSO
988360efbdSAlfred Perlstein.Xr bind 2 ,
998360efbdSAlfred Perlstein.Xr getsockopt 2 ,
1008360efbdSAlfred Perlstein.Xr setsockopt 2 ,
1018360efbdSAlfred Perlstein.Xr ip 4
102