The problem
On our system running RTEMS 4.9.2 we are experiencing a very odd issue with socket communications. We are setting up a socket and using 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 except in a strange specific scenario which is explained below. The problem that we experience is a failure of this bind
call even though the setup is correct. We get the error 125
which for RTEMS is EADDRNOTAVAIL
:
A nonexistent interface was requested or the requested address was not local.
The Apparent Cause
At boot of the device we can set up our network in 1 of 2 ways:
The Network IP and SUBNET is autoconfigured based on what is in the default bootloader (UBOOT), and is set up through the RTEMS OS.
The RTEMS function
rtems_bsdnet_ifconfig
is called to change the ip address of the sole ethernet interface after boot time.
For clarification, option 2 is called like this:
rtems_bsdnet_ifconfig(eth_interface, SIOCSIFADDR, &ipaddr);
If the network is set up as indicated by option 1, everything works as expected, but if option 2 is used (even in the case where the setup matches the network options defined by option 1) then the socket bind fails.
Is there a known reason or bug for RTEMS that indicates that this bind would fail if you reconfigure your IP?
Additional Information
We are setting up 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 (ie use
INADDR_ANY
) then it works in any case.The
rtems_bsdnet_ifconfig
is a simple interface for theioctl
function. It is fromrtems_glue.c
and has the function signitureint rtems_bsdnet_ifconfig(const char *ifname, uint32_t cmd, void *param)
All normal network functions seem to work except for this bind.
After looking at this i thought maybe I needed to do more in resetting my IP address. But this doesn't work , using the first answer or even doing anything with
SIOCSIFFLAGS
causes all network functionality to cease.