kern_sogetopt Kernel Service

Purpose

Obtains the option associated with the socket, either at the socket level or at the protocol level.

Syntax

#include <sys/kern_socket.h>
int  kern_sogetopt( ksocket_t  so, int level, int optname, struct mbuf **mp )

Parameters

Item Description
so The socket that will be used to retrieve the option.
level The socket level (e.g. SOL_SOCKET) or protocol level (IPPROTO_TCP)
optname The option name to retrieve. Socket options can be found in <sys/socket.h> and TCP options can be found in <netinet/tcp.h> mp
mp The mbuf that will be returned with the option value. The mp->m_len will be the size of the value. The caller must pass the address of the struct mbuf *. The caller must set the mbuf free after the function returns successfully.

Description

The kern_sogetopt kernel service obtains the option associated with the socket, either at the socket level, or at the protocol level.

Execution Environment

The kern_sogetopt kernel service can be called from the process environment.

Examples

ksocket_t   so;
int		     rc;		 
struct mbuf *sopt = NULL;
int  tcp_nodelay = -1;
rc = kern_socreate(AF_INET, &so, SOCK_STREAM, IPPROTO_TCP);
if (rc != 0 )  		 
{ 		 		 
			return(-1); 		 
}		   		 
rc = sogetopt(so, IPPROTO_TCP, TCP_NODELAY, &sopt); 		 
if (rc != 0 )  		 
{ 		 		 
			return(-1); 		 
}		   		 
tcp_nodelay = *mtod(sopt, int *) ? 1 : 0; 		 
m_free(sopt); /* Caller needs to free the mbuf after kern_sogetopt */ 

Return Values

Item Description
0 Upon Success
>0 Error

The nonzero return value is the error number that is defined in the /usr/include/sys/errno.h file.