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, ðernetif_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:
sis my socket descriptor,levelis set toSOL_SOCKET,optnameis set toSO_BINDTODEVICE,optvalis a pointer toifreqstructure,optlenis size of theifreqstructure (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):
So what am I doing wrong that I get the ENDOV error?
