BINDRESVPORT

Section: Linux Programmer's Manual (3)
Updated: 2017-09-15
Index JM Home Page
 

名前

bindresvport - ソケットを特権 IP ポートにバインドする  

書式

#include <sys/types.h>
#include <netinet/in.h>

int bindresvport(int sockfd, struct sockaddr_in *sin);
 

説明

bindresvport() is used to bind the socket referred to by the file descriptor sockfd to a privileged anonymous IP port, that is, a port number arbitrarily selected from the range 512 to 1023.

bindresvport() によって実行された bind(2) が成功し、 sin が NULL 以外の場合、実際に割り当てられたポート番号が sin->sin_port に入れて返される。

sin には NULL を指定することもでき、その場合には sin->sin_family は暗黙のうちに AF_INET とみなされる。 しかし、この場合には、 bindresvport() は実際に割り当てられたポート番号を返す手段を持たない (割り当てられたポート番号は、後で getsockname(2) を使って取得できる)。  

返り値

bindresvport() は成功すると 0 を返す。それ以外の場合、-1 を返し、 errno にエラーの原因を示す値を設定する。  

エラー

bindresvport() は bind(2) と同じ原因で失敗する可能性がある。 さらに、以下のエラーが発生することがある:
EACCES
The calling process was not privileged (on Linux: the calling process did not have the CAP_NET_BIND_SERVICE capability in the user namespace governing its network namespace).
EADDRINUSE
全ての特権ポートが使用中である。
EAFNOSUPPORT (glibc 2.7 以前では EPFNOSUPPORT)
sin が NULL 以外で、かつ sin->sin_family が AF_INET でなかった。
 

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース 属性 値
bindresvport() Thread safety glibc >= 2.17: MT-Safe
glibc < 2.17: MT-Unsafe

The bindresvport() function uses a static variable that was not protected by a lock before glibc 2.17, rendering the function MT-Unsafe.  

準拠

Not in POSIX.1. Present on the BSDs, Solaris, and many other systems.  

注意

bindresvport() のいくつかの実装と異なり、glibc の実装では呼び出し元が sin->sin_port で渡した値はどんな値であっても無視される。  

関連項目

bind(2), getsockname(2)  

この文書について

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

関連キーワード

ポート   port   番号   bindresvport   特権   privileged   成功   実際   family   原因   calling   process   namespace   実装   ソケット   バインド   types   netinet   struct   sockaddr   used   bind   socket   referred   descriptor

Linux マニュアル 一覧

関連するコマンド・関数

iruserok.3   iruserok_af.3   rcmd.3   rcmd_af.3   rresvport.3   rresvport_af.3
 

Index

名前
書式
説明
返り値
エラー
属性
準拠
注意
関連項目
この文書について

This document was created by man2html, using the manual pages.
Time: 04:39:20 GMT, October 11, 2026