|
From: | Joel Cunningham |
Subject: | Re: [lwip-users] 2 Devices |
Date: | Mon, 13 Nov 2017 15:40:01 -0600 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 |
On 11/10/2017 03:51 AM, Fabian Cenedese wrote:
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
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.
int rc = setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, (void*)&ifr, sizeof(struct ifreq)); } }
Joel
[Prev in Thread] | Current Thread | [Next in Thread] |