The
sockopt structure is used to pass a socket option and associated value:
struct sockopt {
int sopt_level; /* option level */
int sopt_name; /* option name */
size_t sopt_size; /* data length */
void * sopt_data; /* data pointer */
uint8_t sopt_buf[sizeof(int)]; /* internal storage */
};
The internal storage is used for the common case of values up to integer size so that memory allocation is not required and sopt_data will point to this in that case.
Rather than provide accessor functions, the
sockopt structure is public and the contents are expected to be internally consistent, but the normal practice would be to use the appropriate methods for storage and retrieval of values where a known datatype is expected, as the size will be verified.
Note: a sockopt structure may only be used for a single level/name/size combination. If the structure is to be re-used, it must be destroyed and re-initialized with the new values.