Single Socket for IPv4 and IPv6

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Single Socket for IPv4 and IPv6

Singaravelu Balasubramani

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


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Single Socket for IPv4 and IPv6

goldsimon@gmx.de
Am 18.06.2019 um 06:10 schrieb Singaravelu Balasubramani:

> 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?

We aim to be standard here. Regarding sockets, your question seems
wrong. Instead, try to implement what you want with Linux or *BSD and if
it then doesn't work with lwIP, come back here and ask why ;-)

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users