diff --git a/src/options.c b/src/options.c index 8ac2a14..2f68fd9 100644 --- a/src/options.c +++ b/src/options.c @@ -187,6 +187,29 @@ int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL); } +int opt_get_ip_multicast_ttl(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL); +} + +int opt_set_bindtodevice(lua_State *L, p_socket ps) +{ + size_t len; + const char *device = luaL_checklstring(L, 3, &len); /* obj, name, device */ + return opt_set(L, ps, SOL_SOCKET, SO_BINDTODEVICE, (char *) device, len); +} + +int opt_get_bindtodevice(lua_State *L, p_socket ps) +{ + int len; + char device[IFNAMSIZ]; + int err = opt_get(L, ps, SOL_SOCKET, SO_BINDTODEVICE, (char *) device, &len); + if (err) + return err; + lua_pushlstring(L, device, len); + return 1; +} + int opt_set_ip_multicast_if(lua_State *L, p_socket ps) { const char *address = luaL_checkstring(L, 3); /* obj, name, ip */ diff --git a/src/options.h b/src/options.h index 5657a06..8bd6746 100644 --- a/src/options.h +++ b/src/options.h @@ -38,6 +38,7 @@ int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps); int opt_set_ip6_add_membership(lua_State *L, p_socket ps); int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps); int opt_set_ip6_v6only(lua_State *L, p_socket ps); +int opt_set_bindtodevice(lua_State *L, p_socket ps); /* supported options for getoption */ int opt_get_reuseaddr(lua_State *L, p_socket ps); @@ -47,11 +48,13 @@ int opt_get_linger(lua_State *L, p_socket ps); int opt_get_reuseaddr(lua_State *L, p_socket ps); int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); int opt_get_ip_multicast_if(lua_State *L, p_socket ps); +int opt_get_ip_multicast_ttl(lua_State *L, p_socket ps); int opt_get_error(lua_State *L, p_socket ps); int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); int opt_get_ip6_v6only(lua_State *L, p_socket ps); +int opt_get_bindtodevice(lua_State *L, p_socket ps); /* invokes the appropriate option handler */ int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); diff --git a/src/udp.c b/src/udp.c index a9f2393..1bb2856 100644 --- a/src/udp.c +++ b/src/udp.c @@ -84,18 +84,21 @@ static t_opt optset[] = { {"ipv6-add-membership", opt_set_ip6_add_membership}, {"ipv6-drop-membership", opt_set_ip6_drop_membersip}, {"ipv6-v6only", opt_set_ip6_v6only}, + {"bindtodevice", opt_set_bindtodevice}, {NULL, NULL} }; /* socket options for getoption */ static t_opt optget[] = { {"ip-multicast-if", opt_get_ip_multicast_if}, + {"ip-multicast-ttl", opt_get_ip_multicast_ttl}, {"ip-multicast-loop", opt_get_ip_multicast_loop}, {"error", opt_get_error}, {"ipv6-unicast-hops", opt_get_ip6_unicast_hops}, {"ipv6-multicast-hops", opt_get_ip6_unicast_hops}, {"ipv6-multicast-loop", opt_get_ip6_multicast_loop}, {"ipv6-v6only", opt_get_ip6_v6only}, + {"bindtodevice", opt_get_bindtodevice}, {NULL, NULL} };