.\" Copyright (c) 1983, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)getpeername.2 6.5 (Berkeley) 3/10/91 .\" .\" Modified Sat Jul 24 16:37:50 1993 by Rik Faith .\" Modified Thu Jul 30 14:37:50 1993 by Martin Schulze .\" Modified Sun Mar 28 21:26:46 1999 by Andries Brouwer .\" Modified 17 Jul 2002, Michael Kerrisk .\" Added 'socket' to NAME, so that "man -k socket" will show this page. .\" .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya .\" all rights reserved. .\" Translated Sat Apr 3 14:53:19 JST 1999 .\" by HANATAKA Shinya .\" Updated Tue Nov 26 JST 2002 by Kentaro Shirakata .\" .\"WORD: connect 接続 .\"WORD: peer 相手 .\"WORD: socket ソケット .\"WORD: buffer バッファ .\"WORD: descriptor ディスクリプタ .\"WORD: argument 引き数 .\" .TH GETPEERNAME 2 2008-12-03 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O getpeername \- get name of connected peer socket getpeername \- 接続している相手ソケットの名前を取得する .\"O .SH SYNOPSIS .SH 書式 .B #include .sp .BI "int getpeername(int " sockfd ", struct sockaddr *" addr \ ", socklen_t *" addrlen ); .\"O .SH DESCRIPTION .SH 説明 .\"O .BR getpeername () .\"O returns the address of the peer connected to the socket .\"O .IR sockfd , .\"O in the buffer pointed to by .\"O .IR addr . .BR getpeername () は、ソケット(socket) .I sockfd に接続している相手のアドレスを、 .I addr が指すバッファに格納して返す。 .\"O The .\"O .I addrlen .\"O argument should be initialized to indicate the amount of space pointed to .\"O by .\"O .IR addr . .I addrlen 引き数は、 .I addr が指している領域のサイズに初期化しておかなければならない。 .\"O On return it contains the actual size of the name returned (in bytes). .\"O The name is truncated if the buffer provided is too small. 関数が返る時には、 .I addrlen には実際に返された名前のサイズが (バイト単位で) 格納される。 提供されたバッファが小さすぎた場合には、名前は切り詰められる。 .\"O The returned address is truncated if the buffer provided is too small; .\"O in this case, .\"O .I addrlen .\"O will return a value greater than was supplied to the call. 渡されたバッファが小さ過ぎた場合は、返されるアドレスの末尾が切り詰められる。 この場合には、 .I addrlen には、呼び出し時に指定された値よりも大きな値が格納される。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success, zero is returned. .\"O On error, \-1 is returned, and .\"O .I errno .\"O is set appropriately. 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 .I errno を適切に設定する。 .\"O .SH ERRORS .SH エラー .TP .B EBADF .\"O The argument .\"O .I sockfd .\"O is not a valid descriptor. 引き数 .I sockfd が有効なディスクリプタでない。 .TP .B EFAULT .\"O The .\"O .I addr .\"O argument points to memory not in a valid part of the .\"O process address space. .I addr 引き数の指しているメモリが有効なプロセスのアドレス空間の 一部でない。 .TP .B EINVAL .\"O .I addrlen .\"O is invalid (e.g., is negative). .I addrlen が不正である (例えば、負で場合など)。 .TP .B ENOBUFS .\"O Insufficient resources were available in the system .\"O to perform the operation. この操作を行なうのに十分な資源がシステムに存在しない。 .TP .B ENOTCONN .\"O The socket is not connected. ソケットが接続していない。 .TP .B ENOTSOCK .\"O The argument .\"O .I sockfd .\"O is a file, not a socket. 引き数 .I sockfd がソケットでなくてファイルである。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O SVr4, 4.4BSD (the .\"O .BR getpeername () .\"O function call first appeared in 4.2BSD), POSIX.1-2001. SVr4, 4.4BSD .RB ( getpeername () 関数は 4.2BSD で登場した), POSIX.1-2001. .\"O .SH NOTES .SH 注意 .\"O The third argument of .\"O .BR getpeername () .\"O is in reality an .\"O .I int * .\"O (and this is what 4.x BSD and libc4 and libc5 have). .\"O Some POSIX confusion resulted in the present .\"O .IR socklen_t , .\"O also used by glibc. .\"O See also .\"O .BR accept (2). .BR getpeername () の三番目の引き数は実際には .I `int *' である (4.x BSD, libc4, libc5 では このようになっている)。 POSIX では紆余曲折を経て現在の .I socklen_t になっており、 glibc でも .I socklen_t を使っている。 .BR accept (2) も参照のこと。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR accept (2), .BR bind (2), .BR getsockname (2), .BR ip (7), .BR socket (7), .BR unix (7)