setsockopt TCP UDP

Set a specific option on a specific TCP socket. See function NetSock_OptSet for more information.

Files

net_bsd.h/net_bsd.c

Prototype

int  setsockopt (int          sock_id,
                 int          level,
                 int          opt_name,
                 void        *p_opt_val,
                 sock_len_t   opt_len);


Arguments

sock_id

This is the socket ID returned by NetSock_Open()/socket() when the socket was created or by NetSock_Accept()/accept() when a connection was accepted.

level

Protocol level from which to retrieve the socket option.

opt_name

Socket option to set the value.

popt_val

Pointer to the socket option value to set.

opt_len

Option length.

Returned Value

0, if successful;

-1, otherwise.

Required Configuration

None.

Notes / Warnings

The supported options are:

  • Protocol levelSOL_SOCKET:
    • SO_KEEPALIVE
    • SO_SNDBUF / SO_RCVBUF
    • SO_SNDTIMEO / SO_RCVTIMEO
  • Protocol levelIPPROTO_IP:
    • IP_TOS
    • IP_TTL
  • Protocol levelIPPROTO_TCP:
    • TCP_NODELAY
    • TCP_KEEPCNT
    • TCP_KEEPIDLE
    • TCP_INTVL



This function must be called after either listen() (in the server case) or connect() (in the client case) have been called.