Managing HP Serviceguard for Linux, Eighth Edition, March 2008

Designing Highly Available Cluster Applications
Designing Applications to Run on Multiple Systems
Appendix B 349
With UDP datagram sockets, however, there is a problem. The client may
connect to multiple servers utilizing the relocatable IP address and sort
out the replies based on the source IP address in the server’s response
message. However, the source IP address given in this response will be
the stationary IP address rather than the relocatable application IP
address. Therefore, when creating a UDP socket for listening, the
application must always call bind(2) with the appropriate relocatable
application IP address rather than INADDR_ANY.
Call bind() before connect()
When an application initiates its own connection, it should first call
bind(2), specifying the application IP address before calling
connect(2). Otherwise the connect request will be sent using the
stationary IP address of the system's outbound LAN interface rather
than the desired relocatable application IP address. The client will
receive this IP address from the accept(2) call, possibly confusing the
client software and preventing it from working correctly.