Syntax
int vm_soc_setsockopt(
    int sock, 
    unsigned int option, 
    void* val, 
    unsigned int val_size
);
ContentsIndex
PreviousUpNext
vm_soc_setsockopt
Example | See Also
Syntax
int vm_soc_setsockopt(
    int sock, 
    unsigned int option, 
    void* val, 
    unsigned int val_size
);
Description

This function sets the socket options.

Parameters
Parameters 
Description 
int sock 
[IN] Socket descriptor. 
unsigned int option 
[IN] Specifies the option type, as defined in VM_SOC_OPTION
void* val 
[IN] The option value. 
unsigned int val_size 
[IN] The size of the option value. 
Return Values
Return Values 
Description 
VM_SOC_SUCCESS 
Success.
 
VM_SOC_INVALID_SOCKET 
Invalid socket descriptor.
 
VM_SOC_INVAL 
Invalid value, specified in how.
 
VM_SOC_ERROR 
Unspecified error. 
See Also
Example

VM_SOC_NBIO: 

This option must to be set if you want to use the non-blocking mode or 

non-blocking plus async mode. 

val contains KAL_TRUE indicates non-blocking shall be adopted, 

KAL_FALSE indicates blocking mode shall be adopted. 

For example, set a socket to non-blocking mode: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, SOC_NBIO, &val, sizeof(kal_bool)); 

 

VM_SOC_SILENT_LISTEN: 

val contains KAL_TRUE indicates the silent listen shall be adopted, 

KAL_FALSE indicates non-silent listen shall be adopted. 

This is SOC_SOCK_SMS property. For example, if you want to let the socket be 

the passive to activate the bear, you can set a socket to silent listen mode: 

For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_SILENT_LISTEN, &val, sizeof(kal_bool)) 

 

VM_SOC_UDP_NEED_ICMP: 

This option is used to deliver NOTIFY(close) for ICMP error. 

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. 

For example, if you want to let set a socket to UDP NEED ICMP mode: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_UDP_NEED_ICMP, &val, sizeof(kal_bool)) 

 

VM_SOC_ASYNC: 

this option needs to be set if you want to use the non-blocking plus asyn mode. 

val contains the events application wants to receive. 

For example, if application wants to receive 

READ/WRITE/CLOSE/CONNECT events, 

it shall call soc_setsockopt like the following: 

kal_uint8 val = 0; 

val = SOC_READ | SOC_WRITE | SOC_CLOSE | SOC_CONNECT; 

vm_soc_setsockopt(sock, VM_SOC_ASYNC, &val, sizeof(kal_uint8)); 

P.S. if you are using the server socket, please remember to set the SOC_ACCPET event. 

 

VM_SOC_TCP_MAXSEG: 

A process can only decrease the MSS. When a TCP socket is created, 

the default MSS is set to 512. The MSS is updated according to the value announced 

from peer TCP after the socket completes TCP three-way handshake. 

Therefore, after a socket is created but before connected, a process can only decrease 

the MSS from its default of 512. After a connection is established, 

the process can decrease the MSS from the new updated value. 

 

The value of TCP MSS is reduced to fit the interface MTU if the application set an 

unacceptable large value. 

For example: 

kal_uint8 val = 512; 

vm_soc_setsockopt(sock, VM_SOC_TCP_MAXSEG, &val, sizeof(kal_uint8)); 

 

VM_SOC_LISTEN_BEARER: 

val contains bear type indicates which kind of bear we want to receive packets from. 

For example, set a socket to receive the WiFi bear: 

kal_uint8 val = SOC_BEARER_WIFI; 

vm_soc_setsockopt(sock, VM_SOC_LISTEN_BEARER, &val, sizeof(kal_uint8)); 

 

VM_SOC_WIFI_NOWAKEUP: 

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. 

This option is to make WNDRV sends outgoing packet to in power saving mode. 

For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_WIFI_NOWAKEUP, &val, sizeof(kal_bool)) 

 

VM_SOC_IP_HDRINCL: 

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. If this option is set for a raw IP socket

we must build our own IP header for all the datagrams that we send on the raw socket

We can only set this socket option if the socket type in soc_create is 

SOC_SOCK_RAW(raw socket) and protocol in soc_create is not SOC_IPPROTO_ICMP. 

For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_IP_HDRINCL, &val, sizeof(kal_bool)) 

 

VM_SOC_UDP_ANY_FPORT: 

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. For a connected UDP socket

this option makes socket deliver incoming packet from the same remote 

address but different remote port. 

For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_UDP_ANY_FPORT, &val, sizeof(kal_bool)) 

 

VM_SOC_IP_TTL: 

val contains the TTL values . If you want to change the default TTL (64), 

you can set this option. For example: 

kal_uint8 val = 128; 

vm_soc_setsockopt(sock, VM_SOC_IP_TTL, &val, sizeof(kal_uint8)) 

 

VM_SOC_QOS: 

val contains the TOS values . If you want to set the TOS values, you can set this option. 

For example: 

kal_uint8 val = 0x80; 

vm_soc_setsockopt(sock, VM_SOC_QOS, &val, sizeof(kal_uint8)) 

 

VM_SOC_KEEPALIVE: 

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. 

You can use this option to enable or disable the keep-alive timer in TCP. 

For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_KEEPALIVE, &val, sizeof(kal_bool)) 

 

VM_SOC_NODELAY: 

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. 

If you want to send the packet directly without waiting a packet size larger than MSS, 

you can set this option. For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_NODELAY, &val, sizeof(kal_bool)) 

 

VM_SOC_SENDBUF: 

val contains the value of send buffer's high water mark. 

If you want to set the high water mark, you can set this option. 

If the value you set is smaller than the MSS, the mss would be adjusted to this value. 

The value must be greater than 0 and smaller than the SSPDU + SSPDU_GROW. 

For example: 

kal_uint32 val = 1024; 

vm_soc_setsockopt(sock, VM_SOC_SENDBUF, &val, sizeof(kal_uint32)) 

 

VM_SOC_RECVBUF: 

val contains the value of receive buffer's high water mark. 

If you want to set the high water mark, you can set this option. 

This value must be greater than 0 and smaller than the SRPDU size. 

For example: 

kal_uint32 val = 4096; 

vm_soc_setsockopt(sock, VM_SOC_RECVBUF, &val, sizeof(kal_uint32)) 

 

VM_SOC_LINGER: 

val contains the value of enable/diable LINGER option and the value of LINGER time. 

This option is used in linger on close. 

For example: 

soc_linger_t val; 

val.onoff = KAL_TRUE; val. 

linger_time = 3; (sec) 

vm_soc_setsockopt(sock, VM_SOC_LINGER, &val, sizeof(soc_linger_t_val)); 

 

VM_SOC_IPSEC_POLICY: 

val contains sadb_x_policy structure content. 

You can set this option to set the IPSEC policy. 

If you want to get the IPSEC policy, 

you can set this option. For example: 

struct sadb_x_policy policy; 

policy.sadb_x_policy_len = PFKEY_UNIT64(sizeof(policy)); 

policy.sadb_x_policy_exttype = SADB_X_EXT_POLICY; 

policy.sadb_x_policy_type = 4; // IPSEC_POLICY_BYPASS; 

policy.sadb_x_policy_dir = 1; // IPSEC_DIR_INBOUND; 

vm_soc_setsockopt(sock, VM_SOC_IPSEC_POLICY, &policy, sizeof(sadb_x_policy)) 

 

VM_SOC_TCP_DELAYED_ACK: 

The VM_SOC_TCP_DELAYED_ACK function is enable by default. That is to say, 

if you don't set this option. The default VM_SOC_TCP_DELAYED_ACK value is TRUE

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. 

If you want to enable the "TCP no delay" function, 

you can set this option. For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_TCP_DELAYED_ACK, &val, sizeof(kal_bool)) 

 

VM_SOC_TCP_SACK: 

The VM_SOC_TCP_SACK function is enable by default. That is to say, 

if you don't set this option. The default VM_SOC_TCP_SACK value is TRUE

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. 

If you want to enable the "TCP SACK" function, 

you can set this option. For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_TCP_SACK, &val, sizeof(kal_bool)) 

 

VM_SOC_TCP_TIME_STAMP: 

The VM_SOC_TCP_TIME_STAMP function is enable by default. That is to say, 

if you don't set this option. The default VM_SOC_TCP_TIME_STAMP value is TRUE

val contains KAL_TRUE indicates this option shall be enabled, 

KAL_FALSE indicates this option shall be disabled. 

If you want to enable the "TCP TIME STAMP" function, 

you can set this option. For example: 

kal_bool val = KAL_TRUE; 

vm_soc_setsockopt(sock, VM_SOC_TCP_TIME_STAMP, &val, sizeof(kal_bool))

File

vmsock.h

Group
Created with a commercial version of Doc-O-Matic. In order to make this message disappear you need to register this software. If you have problems registering this software please contact us at support@toolsfactory.com.