|
From: | Singaravelu Balasubramani |
Subject: | [lwip-users] Single Socket for IPv4 and IPv6 |
Date: | Tue, 18 Jun 2019 04:10:48 +0000 |
Hi, I need to know is there any way, we can create a single socket to accept connection from both IPv4 and IPv6 with the constrain of binding to specific interface. I know that IPV6_V6ONLY socket option with value as 0 can listen to both IPv4 and IPv6 and SO_BINDTODEVICE socket option bind to specific interface instead of specific IP address. Can we use this two socket option to achieve the single
socket to accept both IPv4 and IPv6 connection specific to interface? or is there any other way to achieve this? If not, why cannot we do this? Example code: int s = lwip_socket(AF_INET6, SOCK_STREAM, 0); //Binding to specific interface int ret = lwip_setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, "e01", 4); int on = 0; // Allowing IPv4 and IPv6 connection to be connected ret = lwip_setsockopt(s, IPPROTO_TCP, IPV6_V6ONLY, (char*)&on, sizeof(on)); struct sockaddr_in6 chargen_saddr; memset(&chargen_saddr, 0, sizeof(chargen_saddr)); chargen_saddr.sin6_family = AF_INET6; chargen_saddr.sin6_port = lwip_htons(19); /* Chargen server port */ if(lwip_bind(s, (struct sockaddr*) &chargen_saddr, sizeof(chargen_saddr)) == -1) { LWIP_ASSERT("chargen_thread(): Socket bind failed.", 0); } /* Put socket into listening mode */ lwip_listen(s, 5); Thanks, Singaravelu B |
[Prev in Thread] | Current Thread | [Next in Thread] |