mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 12:28:21 +01:00
Add support for the IPV6_V6ONLY socket option defaulting to on.
This commit is contained in:
parent
4df1618aab
commit
f871a29f27
@ -154,6 +154,11 @@ int opt_set_ip_drop_membersip(lua_State *L, p_socket ps)
|
||||
return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP);
|
||||
}
|
||||
|
||||
int opt_set_ip6_v6only(lua_State *L, p_socket ps)
|
||||
{
|
||||
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
|
||||
}
|
||||
|
||||
/*=========================================================================*\
|
||||
* Auxiliar functions
|
||||
\*=========================================================================*/
|
||||
|
@ -32,6 +32,7 @@ int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_add_membership(lua_State *L, p_socket ps);
|
||||
int opt_set_ip_drop_membersip(lua_State *L, p_socket ps);
|
||||
int opt_set_ip6_v6only(lua_State *L, p_socket ps);
|
||||
/* invokes the appropriate option handler */
|
||||
int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps);
|
||||
|
||||
|
@ -70,6 +70,7 @@ static t_opt optset[] = {
|
||||
{"keepalive", opt_set_keepalive},
|
||||
{"reuseaddr", opt_set_reuseaddr},
|
||||
{"tcp-nodelay", opt_set_tcp_nodelay},
|
||||
{"ipv6-v6only", opt_set_ip6_v6only},
|
||||
{"linger", opt_set_linger},
|
||||
{NULL, NULL}
|
||||
};
|
||||
@ -334,6 +335,11 @@ static int tcp_create(lua_State *L, int domain) {
|
||||
auxiliar_setclass(L, "tcp{master}", -1);
|
||||
/* initialize remaining structure fields */
|
||||
socket_setnonblocking(&sock);
|
||||
if (domain == PF_INET6) {
|
||||
int yes = 1;
|
||||
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(void *)&yes, sizeof(yes));
|
||||
}
|
||||
tcp->sock = sock;
|
||||
io_init(&tcp->io, (p_send) socket_send, (p_recv) socket_recv,
|
||||
(p_error) socket_ioerror, &tcp->sock);
|
||||
|
@ -77,6 +77,7 @@ static t_opt optset[] = {
|
||||
{"ip-multicast-loop", opt_set_ip_multicast_loop},
|
||||
{"ip-add-membership", opt_set_ip_add_membership},
|
||||
{"ip-drop-membership", opt_set_ip_drop_membersip},
|
||||
{"ipv6-v6only", opt_set_ip6_v6only},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -352,6 +353,11 @@ static int udp_create(lua_State *L, int domain) {
|
||||
auxiliar_setclass(L, "udp{unconnected}", -1);
|
||||
/* initialize remaining structure fields */
|
||||
socket_setnonblocking(&sock);
|
||||
if (domain == PF_INET6) {
|
||||
int yes = 1;
|
||||
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(void *)&yes, sizeof(yes));
|
||||
}
|
||||
udp->sock = sock;
|
||||
timeout_init(&udp->tm, -1, -1);
|
||||
udp->domain = domain;
|
||||
|
Loading…
Reference in New Issue
Block a user