From 495634795203bf4b1b4c7b6ffbc09c071cfbd7a2 Mon Sep 17 00:00:00 2001 From: Wires77 Date: Thu, 27 Feb 2025 15:40:35 -0600 Subject: [PATCH] Add option for SO_EXCLUSIVEADDRUSE --- src/options.c | 20 ++++++++++++++++++++ src/options.h | 5 +++++ src/tcp.c | 6 ++++++ src/udp.c | 6 ++++++ 4 files changed, 37 insertions(+) diff --git a/src/options.c b/src/options.c index 9dea6bd..1c3eb1c 100644 --- a/src/options.c +++ b/src/options.c @@ -93,6 +93,26 @@ int opt_get_reuseaddr(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); } +/*------------------------------------------------------*/ +/* enables reuse of local address */ +int opt_set_exclusiveaddruse(lua_State* L, p_socket ps) +{ +#ifndef SO_EXCLUSIVEADDRUSE + return luaL_error(L, "SO_EXCLUSIVEADDRUSE is not supported on this operating system"); +#else + return opt_setboolean(L, ps, SOL_SOCKET, SO_EXCLUSIVEADDRUSE); +#endif +} + +int opt_get_exclusiveaddruse(lua_State* L, p_socket ps) +{ +#ifndef SO_EXCLUSIVEADDRUSE + return luaL_error(L, "SO_EXCLUSIVEADDRUSE is not supported on this operating system"); +#else + return opt_getboolean(L, ps, SOL_SOCKET, SO_EXCLUSIVEADDRUSE); +#endif +} + /*------------------------------------------------------*/ /* enables reuse of local port */ int opt_set_reuseport(lua_State *L, p_socket ps) diff --git a/src/options.h b/src/options.h index 26d6f02..6d6d7e0 100644 --- a/src/options.h +++ b/src/options.h @@ -28,6 +28,11 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps); int opt_set_reuseaddr(lua_State *L, p_socket ps); int opt_get_reuseaddr(lua_State *L, p_socket ps); +#ifdef SO_EXCLUSIVEADDRUSE +int opt_set_exclusiveaddruse(lua_State* L, p_socket ps); +int opt_get_exclusiveaddruse(lua_State* L, p_socket ps); +#endif + int opt_set_reuseport(lua_State *L, p_socket ps); int opt_get_reuseport(lua_State *L, p_socket ps); diff --git a/src/tcp.c b/src/tcp.c index f001206..0a36cde 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -74,6 +74,9 @@ static t_opt optget[] = { {"bindtodevice", opt_get_bindtodevice}, {"keepalive", opt_get_keepalive}, {"reuseaddr", opt_get_reuseaddr}, +#ifdef SO_EXCLUSIVEADDRUSE + {"exclusiveaddruse", opt_get_exclusiveaddruse}, +#endif {"reuseport", opt_get_reuseport}, {"tcp-nodelay", opt_get_tcp_nodelay}, #ifdef TCP_KEEPIDLE @@ -96,6 +99,9 @@ static t_opt optset[] = { {"bindtodevice", opt_set_bindtodevice}, {"keepalive", opt_set_keepalive}, {"reuseaddr", opt_set_reuseaddr}, +#ifdef SO_EXCLUSIVEADDRUSE + {"exclusiveaddruse", opt_set_exclusiveaddruse}, +#endif {"reuseport", opt_set_reuseport}, {"tcp-nodelay", opt_set_tcp_nodelay}, #ifdef TCP_KEEPIDLE diff --git a/src/udp.c b/src/udp.c index 712ad50..6c0d39e 100644 --- a/src/udp.c +++ b/src/udp.c @@ -74,6 +74,9 @@ static t_opt optset[] = { {"dontroute", opt_set_dontroute}, {"broadcast", opt_set_broadcast}, {"reuseaddr", opt_set_reuseaddr}, +#ifdef SO_EXCLUSIVEADDRUSE + {"exclusiveaddruse", opt_set_exclusiveaddruse}, +#endif {"reuseport", opt_set_reuseport}, {"ip-multicast-if", opt_set_ip_multicast_if}, {"ip-multicast-ttl", opt_set_ip_multicast_ttl}, @@ -96,6 +99,9 @@ static t_opt optget[] = { {"dontroute", opt_get_dontroute}, {"broadcast", opt_get_broadcast}, {"reuseaddr", opt_get_reuseaddr}, +#ifdef SO_EXCLUSIVEADDRUSE + {"exclusiveaddruse", opt_get_exclusiveaddruse}, +#endif {"reuseport", opt_get_reuseport}, {"ip-multicast-if", opt_get_ip_multicast_if}, {"ip-multicast-loop", opt_get_ip_multicast_loop},