perl-5.38.0
getsockopt SOCKET,LEVEL,OPTNAME

Queries the option named OPTNAME associated with SOCKET at a given LEVEL. Options may exist at multiple protocol levels depending on the socket type, but at least the uppermost socket level SOL_SOCKET (defined in the Socket module) will exist. To query options at another level the protocol number of the appropriate protocol controlling the option should be supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, LEVEL should be set to the protocol number of TCP, which you can get using getprotobyname.

与えられた LEVEL で SOCKET に関連付けられた OPTNAME と言う名前のオプションを 問い合わせます。 オプションはソケットの種類に依存しした複数のプロトコルレベルに存在することも ありますが、少なくとも最上位ソケットレベル SOL_SOCKET (Socket モジュールで定義されています)は存在します。 その他のレベルのオプションを問い合わせるには、そのオプションを制御する 適切なプロトコルのプロトコル番号を指定します。 例えば、オプションが TCP プロトコルで解釈されるべきであることを示すためには、 LEVEL は getprotobyname で得られる TCP の プロトコル番号を設定します。

The function returns a packed string representing the requested socket option, or undef on error, with the reason for the error placed in $!. Just what is in the packed string depends on LEVEL and OPTNAME; consult getsockopt(2) for details. A common case is that the option is an integer, in which case the result is a packed integer, which you can decode using unpack with the i (or I) format.

この関数は、要求されたソケットオプションの pack された文字列表現か、 あるいはエラーの場合は undef を返し、エラーの理由は $! にあります。 pack された文字列の中身は LEVEL と OPTNAME に依存します; 詳細については getsockopt(2) を確認してください。 一般的な場合はオプションが整数の場合で、この場合結果は unpacki (あるいは I)フォーマットでデコードできる pack された整数です。

Here's an example to test whether Nagle's algorithm is enabled on a socket:

あるソケットで Nagle のアルゴリズム有効かどうかを調べる例です:

    use Socket qw(:all);

    defined(my $tcp = getprotobyname("tcp"))
        or die "Could not determine the protocol number for tcp";
    # my $tcp = IPPROTO_TCP; # Alternative
    my $packed = getsockopt($socket, $tcp, TCP_NODELAY)
        or die "getsockopt TCP_NODELAY: $!";
    my $nodelay = unpack("I", $packed);
    print "Nagle's algorithm is turned ",
           $nodelay ? "off\n" : "on\n";

Portability issues: "getsockopt" in perlport.

移植性の問題: "getsockopt" in perlport