BINDRESVPORT(3) | Linux Programmer's Manual | BINDRESVPORT(3) |
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) と同じ原因で失敗する可能性がある。 さらに、以下のエラーが発生することがある:
この節で使用されている用語の説明については、 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/ に書かれている。
2017-09-15 |