getsockopt

getsockoptSOCKET,LEVEL,OPTNAME
This function queries the option named
OPTNAME associated with
SOCKET at a given
LEVEL. Options may exist at multiple protocol
levels depending on 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 for TCP, which you can get using getprotobyname.
The function returns a packed string representing the requested
socket option, or undef if there is
an error with the reason for that error in $!. Just what is in the packed string depends
on the LEVEL and
OPTNAME; see
getsockopt(2) for details. But often the option is
an integer, in which case the result is a packed integer, which you can
unpack with the “i” (or I)
format.
For example, to test whether Nagle’s algorithm is enabled on a socket:
use Socket qw(:all); # assume that $socket hold the handle of a connected socket $tcp = IPPROTO_TCP; $packed = getsockopt($socket, $tcp, TCP_NODELAY) || die ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access