[#Sock-GetSockOpt]
= xref:Sock.adoc[Sock]::GetSockOpt
:relfileprefix: ../
:mrdocs:

getsockopt(2) wrapper&period; Equivalent to `getsockopt(m&lowbar;socket, level, opt&lowbar;name, opt&lowbar;val, opt&lowbar;len)`&period; Code that uses this wrapper can be unit tested if this method is overridden by a mock Sock implementation&period;

== Synopsis

Declared in `&lt;util&sol;sock&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
virtual
int
GetSockOpt(
    int level,
    int opt&lowbar;name,
    void* opt&lowbar;val,
    socklen&lowbar;t* opt&lowbar;len) const;
----

== Return Value

0 on success, or &hyphen;1 on error (with errno set)&period;

[NOTE]
====
The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^].
====
== Parameters

[cols="1,4"]
|===
| Name| Description
| *level*
| Protocol level at which the option resides&period;
| *opt&lowbar;name*
| Name of the option to query&period;
| *opt&lowbar;val*
| Buffer that receives the option value&period;
| *opt&lowbar;len*
| On input the size of `opt&lowbar;val`, on output the actual option size&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
