QNX RTOS v4 Knowledge Base
QNX RTOS v4 Knowledge Base
Title |
UDP Behaviour |
Ref. No. |
QNX.000010461 |
Category(ies) |
Network, Development |
Issue |
We don't quite understand why we get certain types of behaviour using UDP broadcasts, what is going on? |
Solution |
TCPIP 5.0 or earlier unless noted. RTP 6.1.0 or earlier unless noted.
When attempting to broadcast a UDP packet using the limited broadcast address, the following happens:
The TCP/IP stack will attempt to resolve the limited broadcast address to the broadcast address of the primary interface. eg 255.255.255.255 -> 10.255.255.255 if the primary interface is on network 10.0.0.0 netmask 255.0.0.0
The primary interface is the first interface configured. In TCPRT 4.25 and later versions, the primary interface is localhost since it is configured automatically.
The stack will then check to see if the primary interface supports broadcasting (interface flags "ifconfig -a"). If it does not, it will attempt to transmit the broadcast with the original limited broadcast address.
This will result in a "no route to host" error since there is no route to that network unless the default route exists, which would not be the correct ethernet broadcast result.
There are two ways to get around this and specifically determine what interface the packet is transmitted on.
You can reconfigure localhost, which will move localhost to the end of the interface list making the next interface the primary interface (assuming the next interface supports broadcasting). This will result in the packet being transmitted with the destination address of the subnet broadcast address.
or define the route
route add -interface 255.255.255.0 x.x.x.x
where x.x.x.x is the ip address of the interface you wish to transmit out of. (This assumes the primary interface does not support broadcasting). This will result in the packet being transmitted with the limited broadcast address as the destination address.
When RTP 6.1.1 is released, the broadcast behavior may change so that the interface list is searched until the first interface which supports broadcasting is found, and the subnet broadcast address will be used.
When TCPIP 5.0 (QNX4) and RTP 6 with the full BSD stack was introduced, it included support for SO_BINDTODEVICE. Using this socket option combined with bypassing the routing table with either the socket option SO_DONTROUTE, or more preferably using the flags option in send() or sendto() (MSG_DONTROUTE) you can direct the broadcast packets to a specific interface in your program. This will result in the packets being transmitted with the destination ipadress set to the limited broadcast address (255.255.255.255) which the application specified as the destination address.
|
|