void
sockopt_init(struct sockopt *sopt, int level, int name, size_t size)
void
sockopt_destroy(struct sockopt *sopt)
int
sockopt_get(struct sockopt *sopt, void *value, size_t size)
int
sockopt_getint(struct sockopt *sopt, int *value)
int
sockopt_set(struct sockopt *sopt, const void *value, size_t size)
int
sockopt_setint(struct sockopt *sopt, int 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.
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.
DIAGNOSTIC
option will perform basic sanity checks on socket options operations.
sopt, level, name, size))
will arrange for sopt_data to point to a buffer of
size
bytes for the sockopt value.
Where memory needs to be allocated to satisfy this,
sockopt_init()
may sleep.
sopt)sopt, value, size)EINVAL
if an incorrect data size is given.
sopt, value)EINVAL
if sockopt does not contain an integer sized value.
sopt, value, size)KM_NOSLEEP
flag which may cause
sockopt_set()
to return
ENOMEM.
Note: If you need to use
sockopt_set()
in a context where memory allocation may be required and you do not wish to
contemplate failure, the sockopt structure can be initialised in a more suitable
context using
sockopt_init()
which will not fail.
sopt, value)/usr/src.
The function prototypes and sockopt structure are defined in the
sys/sys/socketvar.h
header file, and the socket options implementation is in
sys/kern/uipc_socket.c.