Solving missing implementation for limited broadcast in uIP

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
BEBDigitalAudio
Experienced Member
Posts: 82
Joined: Thu Nov 11, 2010 7:45 pm

Solving missing implementation for limited broadcast in uIP

Post by BEBDigitalAudio »

Hello all,
as I was working on ArtNet implementation for the XS1, I discovered that uIP is missing an important function : limited IP broadcast
The current uIP implementation (as distributed by Adam and XMOS) supports only unicast and global broadcast (e.g : if your device's address is 192.168.0.4, it recognizes this address and also 255.255.255.255)
But the uIP rejects packets coming to 192.168.0.255 (the limited broadcast address)

To solve this, you have :
- declare a uip_ipaddr_t variable named uip_limbcastaddr in uip.c

Then add this function in uip.c

Code: Select all

void uip_setlimitedbroadcast (void)
{
	uip_ipaddr_t newmask;

	// Step 1 : mask the node address in IP with the mask (gives the higher order bytes)
	uip_limbcastaddr[0]=uip_hostaddr[0]&uip_netmask[0];
	uip_limbcastaddr[1]=uip_hostaddr[1]&uip_netmask[1];

	// Step 2 : invert the netmask
	newmask[0]=~uip_netmask[0];
	newmask[1]=~uip_netmask[1];

	// Step 3 : OR the high order bytes with inverted mask to get lower order bytes (must be 0xFF)
	uip_limbcastaddr[0]|=newmask[0];
	uip_limbcastaddr[1]|=newmask[1];
}  // uip_setlimitedbrodcast
// -------------------------------------------------------------
You have to call this function in uip_server.c (if you use XSOCKETS or XTCP) where the static IP address is computed, but also after the DHCP lease is obtained.

It's not possible to give here all the modified code. If you are interested by this addition, contact me, I will send you the complete source code.

Note that this change is included in the next XSOCKETS library release (V0.7)