1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

netdev: BIND_TO_DEVICE

This commit is contained in:
Andy Green 2024-09-25 10:43:28 +01:00
parent 79ae57a2f9
commit 082443ff25
3 changed files with 13 additions and 0 deletions

View file

@ -337,8 +337,10 @@ endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
option(LWS_WITH_NETLINK "Monitor Netlink for Routing Table changes" ON)
option(LWS_WITH_BINDTODEVICE "Use bind to interface socket option" ON)
else()
set(LWS_WITH_NETLINK 0)
set(LWS_WITH_BINDTODEVICE 0)
endif()
option(LWS_WITH_MCUFONT_ENCODER "Build the ttf to mcufont encoder" OFF)

View file

@ -201,6 +201,7 @@
#cmakedefine LWS_WITH_MBEDTLS
#cmakedefine LWS_WITH_MINIZ
#cmakedefine LWS_WITH_NETLINK
#cmakedefine LWS_WITH_BINDTODEVICE
#cmakedefine LWS_WITH_NETWORK
#cmakedefine LWS_WITH_NO_LOGS
#cmakedefine LWS_WITH_OTA

View file

@ -381,6 +381,16 @@ lws_socket_bind(struct lws_vhost *vhost, struct lws *wsi,
/* just checking for the interface extant */
if (sockfd == LWS_SOCK_INVALID)
return LWS_ITOSA_USABLE;
#if defined(LWS_WITH_BINDTODEVICE)
if (af != AF_UNIX && iface) {
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, iface, (socklen_t)strlen(iface)) < 0) {
int _lws_errno = LWS_ERRNO;
lwsl_wsi_warn(wsi, "setsockopt bind to device %s error fd %d (%d)",
iface, sockfd, _lws_errno);
/* Root only, non-fatal, continue here. */
}
}
#endif
n = bind(sockfd, v, (socklen_t)n);
#ifdef LWS_WITH_UNIX_SOCK