lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] 2 Devices


From: Fabian Cenedese
Subject: Re: [lwip-users] 2 Devices
Date: Fri, 10 Nov 2017 10:51:55 +0100

At 21:09 07.11.2017, address@hidden wrote:
>Dirk Ziegelmeier wrote:
>>Try SO_BINDTODEVICE socket option
>
>A better description for this short answer is: having 2 netifs on the same 
>subnet was not supported until we implemented SO_BINDTODEVICE. It might now 
>work, but there might be pitfalls we haven't thought of/haven't tested yet.
>
>Having those 2 netifs on different subnets (like a router) should have worked 
>always. Basically, as Fabian got it, finding the netif to send responses is 
>the tricky part, which fails without BINDTODEVICE when 2 netifs are on the 
>same subnet.

I'm still trying to find my way around it (after updating lwip). On the Internet
are several but contradicting examples.

Here's what I have so far (not much error checking):

struct sockaddr_in addr;
s=socket(AF_INET, SOCK_DGRAM, 0);
if (s >= 0) {
        // set up port from any address to bind to
        memset(&addr, 0, sizeof(addr));
        addr.sin_len=sizeof(addr);
        addr.sin_family=AF_INET;
        addr.sin_port=PP_HTONS(port);
        addr.sin_addr.s_addr=PP_HTONL(INADDR_ANY);
        // connect
        int ret = bind(s, (struct sockaddr*)&addr, sizeof(addr));
        // should succeed
        if (ret < 0) {
                // error
        }
        else {
                // limit to one interface
                struct ifreq ifr;
                memset(&ifr, 0, sizeof(struct ifreq));
                ifr.ifr_name[0] = 'e';// IFNAME0;
                ifr.ifr_name[1] = '0';// IFNAME1

                int rc = setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE,
                                (void*)&ifr, sizeof(struct ifreq));
        }
}

Do I need both setsockopt() and bind()? Is the order
correct/important? If I don't need bind(), how can
I limit the socket to listen to only one port?

Is this a usable way to have two sockets on the same
port, one for netif e0 and one for netif e1?

Thanks

bye  Fabi




reply via email to

[Prev in Thread] Current Thread [Next in Thread]