Problem
In our system, working with RTEMS 4.9.2, we are faced with a very complex socket problem. We install the socket and use the following command to bind:
// Bind the socket to set the local port sockaddr_in localSocketAddress = {0}; localSocketAddress.sin_family = AF_INET; localSocketAddress.sin_port = (u_short)localPort; localSocketAddress.sin_addr.s_addr = localAddress; if (bind( mSocket, (sockaddr *)&localSocketAddress, sizeof(sockaddr_in)) == SOCKET_ERROR) { int errorOut = errno; ...
And this works for UDP communications, with the exception of a strange specific scenario, which is explained below. The problem we are facing is that this bind call fails, even if the setting is correct. We get error 125 , which for RTEMS EADDRNOTAVAIL :
The requested non-existent interface or the requested address was not local.
Obvious reason
When loading the device, we can configure our network in one of 2 ways:
Network IP and SUBNET are automatically configured based on what is in the default bootloader (UBOOT), and configured through the RTEMS OS.
The RTEMS rtems_bsdnet_ifconfig function is called to change the IP address of a single Ethernet interface after boot.
For clarification, option 2 is called:
rtems_bsdnet_ifconfig(eth_interface, SIOCSIFADDR, &ipaddr);
If the network is configured as specified in option 1, everything works as expected, but if option 2 is used (even if the setting matches the network options defined by option 1), the socket binding failed.
Is there a known cause or error for RTEMS that indicates that this binding will fail if you reconfigure your IP address?
Additional Information
We configure a new IP address (option 2) using a method that essentially uses ioctl("eht1", SIOCSIFADDR, ...) .
If we bind our socket without specifying a local ADDRESS (i.e. use INADDR_ANY ), then it works anyway.
rtems_bsdnet_ifconfig is a simple interface for the ioctl function. This is from rtems_glue.c and has a function signiture int rtems_bsdnet_ifconfig(const char *ifname, uint32_t cmd, void *param)
All the usual network functions seem to work, except for this binding.
After watching this, I thought that I needed to do more to reset my IP address. But this does not work, using the first answer or even doing something with SIOCSIFFLAGS , leads to the termination of all network functions.
source share