OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / original / man3 / bindresvport.3
1 .\" Copyright (C) 2007, Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" 2007-05-31, mtk: Rewrite and substantial additional text.
25 .\" 2008-12-03, mtk: Rewrote some pieces and fixed some errors
26 .\"
27 .TH BINDRESVPORT 3  2008-12-03 "" "Linux Programmer's Manual"
28 .SH NAME
29 bindresvport \- bind a socket to a privileged IP port
30 .SH SYNOPSIS
31 .nf
32 .B #include <sys/types.h>
33 .B #include <netinet/in.h>
34 .LP
35 .BI "int bindresvport(int " sockfd ", struct sockaddr_in *" sin );
36 .fi
37 .SH DESCRIPTION
38 .LP
39 .BR bindresvport ()
40 is used to bind a socket descriptor to a privileged anonymous IP port,
41 that is, a port number arbitrarily selected from the range 512 to 1023.
42 .\" Glibc actually starts searching with a port # in the range 600 to 1023
43
44 If the
45 .BR bind (2)
46 performed by
47 .BR bindresvport ()
48 is successful, and
49 .I sin
50 is not NULL, then
51 .I sin\->sin_port
52 returns the port number actually allocated.
53
54 .I sin
55 can be NULL, in which case
56 .I sin\->sin_family
57 is implicitly taken to be
58 .BR AF_INET .
59 However, in this case,
60 .BR bindresvport ()
61 has no way to return the port number actually allocated.
62 (This information can later be obtained using
63 .BR getsockname (2).)
64 .SH RETURN VALUE
65 .BR bindresvport ()
66 returns 0 on success; otherwise \-1 is returned and
67 .I errno
68 set to indicate the cause of the error.
69 .SH ERRORS
70 .BR bindresvport ()
71 can fail for any of the same reasons as
72 .BR bind (2).
73 In addition, the following errors may occur:
74 .TP
75 .BR EACCES
76 The caller did not have superuser privilege (to be precise: the
77 .B CAP_NET_BIND_SERVICE
78 capability is required).
79 .TP
80 .B EADDRINUSE
81 All privileged ports are in use.
82 .TP
83 .BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)"
84 .I sin
85 is not NULL and
86 .I sin->sin_family
87 is not
88 .BR AF_INET .
89 .SH "CONFORMING TO"
90 Not in POSIX.1-2001.
91 Present on the BSDs, Solaris, and many other systems.
92 .SH NOTES
93 Unlike some
94 .BR bindresvport ()
95 implementations,
96 the glibc implementation ignores any value that the caller supplies in
97 .IR sin\->sin_port .
98 .SH SEE ALSO
99 .BR bind (2),
100 .BR getsockname (2)