mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-07-16 01:37:27 +00:00
sockets: add hooks to implement additional socket options
LWIP_HOOK_SOCKETS_SETSOCKOPT() and LWIP_HOOK_SOCKETS_GETSOCKOPT() are introduced to implement additional socket options. The hooks are always called first and report back if they handled the option or not. Signed-off-by: goldsimon <goldsimon@gmx.de>
This commit is contained in:
parent
61671d6df0
commit
ce79811bce
|
@ -64,6 +64,10 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef LWIP_HOOK_FILENAME
|
||||
#include LWIP_HOOK_FILENAME
|
||||
#endif
|
||||
|
||||
/* If the netconn API is not required publicly, then we include the necessary
|
||||
files here to get the implementation */
|
||||
#if !LWIP_NETCONN
|
||||
|
@ -2835,6 +2839,12 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt
|
|||
return EBADF;
|
||||
}
|
||||
|
||||
#ifdef LWIP_HOOK_SOCKETS_GETSOCKOPT
|
||||
if (LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, &err)) {
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (level) {
|
||||
|
||||
/* Level: SOL_SOCKET */
|
||||
|
@ -3250,6 +3260,12 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
|
|||
return EBADF;
|
||||
}
|
||||
|
||||
#ifdef LWIP_HOOK_SOCKETS_SETSOCKOPT
|
||||
if (LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, &err)) {
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (level) {
|
||||
|
||||
/* Level: SOL_SOCKET */
|
||||
|
|
|
@ -2935,6 +2935,50 @@
|
|||
#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err)
|
||||
* Called from socket API to implement setsockopt() for options not provided by lwIP.
|
||||
* Core lock is held when this hook is called.
|
||||
* Signature:
|
||||
* int my_hook(int s, struct lwip_sock *sock, int level, int optname, const void *optval, socklen_t optlen, int *err)
|
||||
* Arguments:
|
||||
* - s: socket file descriptor
|
||||
* - sock: internal socket descriptor (see lwip/priv/sockets_priv.h)
|
||||
* - level: protocol level at which the option resides
|
||||
* - optname: option to set
|
||||
* - optval: value to set
|
||||
* - optlen: size of optval
|
||||
* - err: output error
|
||||
* Return values:
|
||||
* - 0: Hook has not consumed the option, code continues as normal (to internal options)
|
||||
* - != 0: Hook has consumed the option, 'err' is returned
|
||||
*/
|
||||
#ifdef __DOXYGEN__
|
||||
#define LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err)
|
||||
* Called from socket API to implement getsockopt() for options not provided by lwIP.
|
||||
* Core lock is held when this hook is called.
|
||||
* Signature:
|
||||
* int my_hook(int s, struct lwip_sock *sock, int level, int optname, void *optval, socklen_t *optlen, int *err)
|
||||
* Arguments:
|
||||
* - s: socket file descriptor
|
||||
* - sock: internal socket descriptor (see lwip/priv/sockets_priv.h)
|
||||
* - level: protocol level at which the option resides
|
||||
* - optname: option to get
|
||||
* - optval: value to get
|
||||
* - optlen: size of optval
|
||||
* - err: output error
|
||||
* Return values:
|
||||
* - 0: Hook has not consumed the option, code continues as normal (to internal options)
|
||||
* - != 0: Hook has consumed the option, 'err' is returned
|
||||
*/
|
||||
#ifdef __DOXYGEN__
|
||||
#define LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, err)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE(name, addr, addrtype, err)
|
||||
* Called from netconn APIs (not usable with callback apps) allowing an
|
||||
|
|
Loading…
Reference in New Issue
Block a user