71GA
71GA

Reputation: 1391

LWIP -- using option `SO_BINDTODEVICE` with `lwip_setsockopt()` returns error `ENODEV`

With LWIP, I usually set up my ethernet interface on my embedded device like this (not all argument definitions are specified here):

struct netif gnetif;

// Set up the ethernet interface on embedded device.
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);

// Registers the default network interface.
netif_set_default(&gnetif);

// Make ethernet interface work.
if(netif_is_link_up(&gnetif)){
    netif_set_up(&gnetif);
}
else{
    netif_set_down(&gnetif);
}

When the interface is set up, I want to bind it to the device using this call to setsockopt():

lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)

where:

  1. s is my socket descriptor,
  2. level is set to SOL_SOCKET,
  3. optname is set to SO_BINDTODEVICE,
  4. optval is a pointer to ifreq structure,
  5. optlen is size of the ifreq structure (previous bullet).

This call successfully enters this switch statement and successfully interprets the SOL_SOCKET level and SO_BINDTODEVICE option to end up here.

But for some reason this call to netif_find() sets n to 0 and then I get an error ENODEV which means that there is no device. This is weird, because gnetif.name returns st and also optval which is ifreq structure has only one member ifr_name which looks like this in the debugger (just before the call):

enter image description here

So what am I doing wrong that I get the ENDOV error?

Upvotes: 1

Views: 333

Answers (0)

Related Questions