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: Tue, 14 Nov 2017 08:18:42 +0100

>>        // 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
>
>Unless you've made modifications to LwIP's interface naming/numbering, the 
>name is at least least 3 characters: two chars and a number (which is also the 
>index).  See netif_find(), which is invoked from SO_BINDTODEVICE.

Yes, I already saw the number and already fixed it.

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

I also had to put the setsockopt before the bind as two binds on the same
port are only allowed if both have the BINDTODEVICE flag set. So this needs
to be set before the bind call. Apart from that it doesn't look bad but I'm
still testing.

Thanks

bye  Fabi




reply via email to

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