How to respond to a multicast udp message sent from a different ip range?
I have a scenario in which I’ve implemented a simple SLP server (http://www.openslp.org/doc/rfc/rfc2608.txt) on a small device and a simple SLP client on a PC.
The device has an ip. Eg. 10.0.0.50
The PC however has several ips. Eg. 10.0.0.70, 192.168.1.70, 172.19.1.70
The PC also have several network adapters, that each have several ips. (Never mind that.)
From the PC I send out an udp message to the slp multicast group:
System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0));
client.Send(m_tx_buffer, encoded, SLPMULTICASTGROUP, SLPPORT);
The .net UdpClient will select a random ip to attach to the udp message.
The device will recieve the udp message and send back a unicast message to the given sender ip. Like so:
int mysock;
struct sockaddr_in myaddr, cliaddr;
char msgbuf[MAXLEN];
socklen_t clilen;
int msglen;
mysock = socket(PF_INET,SOCK_DGRAM,0);
myaddr.sin_family = AF_INET;
myaddr.sin_port = htons( S_PORT );
myaddr.sin_addr = htonl( INADDR_ANY );
bind(mysock, &myaddr, sizeof(myaddr));
while (1) {
len=sizeof(cliaddr);
msglen=recvfrom(mysock,msgbuf,MAXLEN,0,cliaddr,&clilen);
sendto(mysock,msgbuf,msglen,0,cliaddr,clilen);
}
Problem is if the .net chooses eg. ip 192.168.1.70. The device will respond to this. And it doesn’t seem to get through to the PC. (The PC and the device share the 10.0.0.x range.)
Is it supposed to get through? (I’ve verified with Wireshark that the message doesn’t arrive on the PC. And I’ve verified with my jtag that the device sends out a message.)
To solve this I could make the PC enumerate all ips and send out several udp messages. But this has somewhat bad performance and it risks flooding the poor devices. (The device will recieve all the messages and respond accordingly. It’s the PC that doesn’t recieve the responses.)
Is it my device (it’s a small RTOS btw.) that has a flawed transmisson?
Or is there some way to solve this problem, without flooding my small devices?
If you want your device to be able to send to IP addresses that aren’t on the directly attached subnet, you’ll have to give it routes for those IP addresses.
You might be able to simply give it a default route through the PC (ie. a default route with a gateway of
10.0.0.70).