I don't use the socket API but as far as I can remember, all you need is one socket listening on IPv6 ANY address. This will accept IPv4 connections as well by default. It can also be disabled.

If there is no predefined sin6 address for ANY, your procedure of setting it to 0 is correct.

Somebody about a year or two ago had made sure this was working. Is it not working for you?

Cheers
Ivan



Date: Wed, 8 Apr 2015 06:15:08 -0700 (MST)
From: Mohsin <[email protected]>
To: [email protected]
Subject: [lwip-users] How to have two different sockets for IPv4 and
        IPv6
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hi,

I am trying to write a web server that listens on both IPv4 and IPv6
addresses. Although, only one implementation at a time works fine. However, the code that I wrote for both simulateniously doesn't work. I mean I'm creating two diff webserver tasks for IPv4 and IPv6. The socket for both
AF_INET6 and AF_INET and binding it with port=80 which is as follows:

//webserver_task_IPv4
iStatus = socket( AF_INET, SOCK_STREAM, 0 );
sin.sin_family = AF_INET;
sin.sin_len = sizeof(sin);
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = HTTP_PORT_NUMBER;               //port = 80
memset(&(sin.sin_zero), '\0', sizeof(sin.sin_zero));

//webserver_task_IPv6
iStatus = socket( AF_INET6, SOCK_STREAM, 0 );
sin.sin6_family = AF_INET6;
sin.sin6_len = sizeof(sin);
memset(&(sin.sin6_addr), 0, sizeof(sin.sin6_addr));
sin.sin6_port = HTTP_PORT_NUMBER;               //port = 80


Actually I'm looking for "in6addr_any" for filling IPv6 ANY Address into
IPv6 socket case but can't find anywhere in the stack and hence used
memset() to set sin6_addr to 0. So is there any replacement variable defined
for it in the stack?

Both above tasks works fine when implemented one at a time.

Can anyone please suggest proper socket binding that can listen for both
IPv4 and IPv6 at the same time.

Any help would be highly appreciated.

Thanks & regards,
Mohsin Kesarani



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

Reply via email to