OSDN Git Service

dfd53239309b7a1ba6bd94da613eca6e50c7bbd7
[linuxjm/LDP_man-pages.git] / 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 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" 2007-05-31, mtk: Rewrite and substantial additional text.
28 .\" 2008-12-03, mtk: Rewrote some pieces and fixed some errors
29 .\"
30 .TH BINDRESVPORT 3  2013-06-21 "" "Linux Programmer's Manual"
31 .SH NAME
32 bindresvport \- bind a socket to a privileged IP port
33 .SH SYNOPSIS
34 .nf
35 .B #include <sys/types.h>
36 .B #include <netinet/in.h>
37 .LP
38 .BI "int bindresvport(int " sockfd ", struct sockaddr_in *" sin );
39 .fi
40 .SH DESCRIPTION
41 .LP
42 .BR bindresvport ()
43 is used to bind a socket descriptor to a privileged anonymous IP port,
44 that is, a port number arbitrarily selected from the range 512 to 1023.
45 .\" Glibc actually starts searching with a port # in the range 600 to 1023
46
47 If the
48 .BR bind (2)
49 performed by
50 .BR bindresvport ()
51 is successful, and
52 .I sin
53 is not NULL, then
54 .I sin\->sin_port
55 returns the port number actually allocated.
56
57 .I sin
58 can be NULL, in which case
59 .I sin\->sin_family
60 is implicitly taken to be
61 .BR AF_INET .
62 However, in this case,
63 .BR bindresvport ()
64 has no way to return the port number actually allocated.
65 (This information can later be obtained using
66 .BR getsockname (2).)
67 .SH RETURN VALUE
68 .BR bindresvport ()
69 returns 0 on success; otherwise \-1 is returned and
70 .I errno
71 set to indicate the cause of the error.
72 .SH ERRORS
73 .BR bindresvport ()
74 can fail for any of the same reasons as
75 .BR bind (2).
76 In addition, the following errors may occur:
77 .TP
78 .BR EACCES
79 The caller did not have superuser privilege (to be precise: the
80 .B CAP_NET_BIND_SERVICE
81 capability is required).
82 .TP
83 .B EADDRINUSE
84 All privileged ports are in use.
85 .TP
86 .BR EAFNOSUPPORT " (" EPFNOSUPPORT " in glibc 2.7 and earlier)"
87 .I sin
88 is not NULL and
89 .I sin->sin_family
90 is not
91 .BR AF_INET .
92 .SH ATTRIBUTES
93 .SS Multithreading (see pthreads(7))
94 Before glibc 2.17, the
95 .BR bindresvport ()
96 function uses a static variable that is not protected,
97 so it is not thread-safe.
98
99 Since glibc 2.17,
100 .\" commit f6da27e53695ad1cc0e2a9490358decbbfdff5e5
101 the
102 .BR bindresvport ()
103 function uses a lock to protect static variable, so it is thread-safe.
104 .SH CONFORMING TO
105 Not in POSIX.1-2001.
106 Present on the BSDs, Solaris, and many other systems.
107 .SH NOTES
108 Unlike some
109 .BR bindresvport ()
110 implementations,
111 the glibc implementation ignores any value that the caller supplies in
112 .IR sin\->sin_port .
113 .SH SEE ALSO
114 .BR bind (2),
115 .BR getsockname (2)
116 .SH COLOPHON
117 This page is part of release 3.67 of the Linux
118 .I man-pages
119 project.
120 A description of the project,
121 information about reporting bugs,
122 and the latest version of this page,
123 can be found at
124 \%http://www.kernel.org/doc/man\-pages/.