Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is parameter level in getsockopt?

I got the following link: SOL_SOCKET in getsockopt()

But it is really confusing for me. One replied that the SOL_SOCKET means the socket layer. What is the socket layer? Are there any other options available for that parameter?

What happens if we pass the SOL_SOCKET parameter and what does the SOL stand for?

I am using UNIX.

like image 610
VINOTH ENERGETIC Avatar asked Oct 31 '22 16:10

VINOTH ENERGETIC


1 Answers

"socket layers" refers to the socket abstraction of the operative system. Those options can be set independently of the type of socket you are handling. In practice, you may be only interested in TCP/IP sockets, but there are also UDP/IP sockets, Unix domain sockets, and others. The options related to SOL_SOCKET can be applied to any of them. The list provided in the answer of the other question has some of them; in the manual page of sockets there are even more, under the "Socket options" section.

SOL_SOCKET is a constant for the "protocol number" associated with that level. For other protocols or levels, you can use getprotoent to obtain the protocol number from its name, or check the manual of the protocol - for example, in the manual page of IP are described the constants for the protocol numbers of IP (IPPROTO_IP), TCP (IPPROTO_TCP) and UDP (IPPROTO_UDP), while the manual page of Unix sockets says that, for historial reasons, its protocol options must be set using SOL_SOCKET too. Moreover, you can find the list of supported protocols for your system in /etc/protocols. And, of course, the options supported by each of the protocols is in their manuals: IP, TCP, UDP, Unix sockets...

like image 124
jdehesa Avatar answered Nov 09 '22 07:11

jdehesa