Obtains the option associated with the socket, either at the socket level or at the protocol level.
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. |
The kern_sogetopt kernel service obtains the option associated with the socket, either at the socket level, or at the protocol level.
The kern_sogetopt kernel service can be called from the process environment.
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 */
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.