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.\" 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.In sys/types.h 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 21The 22.Fn bindresvport 23and 24.Fn bindresvport_sa 25functions 26are used to bind a socket descriptor to a privileged 27.Tn IP 28port, that is, a 29port number in the range 0-1023. 30.Pp 31If 32.Fa sin 33is a pointer to a 34.Ft "struct sockaddr_in" 35then the appropriate fields in the structure should be defined. 36Note that 37.Fa sin->sin_family 38must be initialized to the address family of the socket, passed by 39.Fa sd . 40If 41.Fa sin->sin_port 42is 43.Sq 0 44then an anonymous port (in the range 600-1023) will be 45chosen, and if 46.Xr bind 2 47is successful, the 48.Fa sin->sin_port 49will be updated to contain the allocated port. 50.Pp 51If 52.Fa sin 53is the 54.Dv NULL 55pointer, 56an anonymous port will be allocated (as above). 57However, there is no way for 58.Fn bindresvport 59to return the allocated port in this case. 60.Pp 61Only root can bind to a privileged port; this call will fail for any 62other users. 63.Pp 64Function prototype of 65.Fn bindresvport 66is biased to 67.Dv AF_INET 68socket. 69The 70.Fn bindresvport_sa 71function 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 80.Rv -std bindresvport 81.Sh ERRORS 82.Bl -tag -width Er 83.It Bq Er EPFNOSUPPORT 84If second argument was supplied, 85and address family did not match between arguments. 86.El 87.Pp 88The 89.Fn bindresvport 90function 91may also fail and set 92.Va errno 93for any of the errors specified for the calls 94.Xr bind 2 , 95.Xr getsockopt 2 , 96or 97.Xr setsockopt 2 . 98.Sh SEE ALSO 99.Xr bind 2 , 100.Xr getsockopt 2 , 101.Xr setsockopt 2 , 102.Xr ip 4 103