Managing HP Serviceguard for Linux Ninth Edition, April 2009

However, gethostbyname(3) should be used to locate the IP address of an application
only if the application name is configured in DNS. It is probably best to associate a
different application name with each independent HA service. This allows each
application and its IP address to be moved to another node without affecting other
applications. Only the stationary IP addresses should be associated with the hostname
in DNS.
Use uname(2) With Care
Related to the hostname issue discussed in the previous section is the application's use
of uname(2), which returns the official system name. The system name is unique to
a given system whatever the number of LAN cards in the system. By convention, the
uname and hostname are the same, but they do not have to be. Some applications,
after connection to a system, might call uname(2) to validate for security purposes
that they are really on the correct system. This is not appropriate in an HA environment,
since the service is moved from one system to another, and neither the uname nor the
hostname are moved. Applications should develop alternate means of verifying where
they are running. For example, an application might check a list of hostnames that have
been provided in a configuration file.
Bind to a Fixed Port
When binding a socket, a port address can be specified or one can be assigned
dynamically. One issue with binding to random ports is that a different port may be
assigned if the application is later restarted on another cluster node. This may be
confusing to clients accessing the application.
The recommended method is using fixed ports that are the same on all nodes where
the application will run, instead of assigning port numbers dynamically. The application
will then always return the same port number regardless of which node is currently
running the application. Application port assignments should be put in
/etc/services to keep track of them and to help ensure that someone will not choose
the same port number.
Bind to Relocatable IP Addresses
When sockets are bound, an IP address is specified in addition to the port number.
This indicates the IP address to use for communication and is meant to allow
applications to limit which interfaces can communicate with clients. An application
can bind to INADDR_ANY as an indication that messages can arrive on any interface.
Network applications can bind to a stationary IP address, a relocatable IP address, or
INADDR_ANY. If the stationary IP address is specified, then the application may fail
when restarted on another node, because the stationary IP address is not moved to the
new system. If an application binds to the relocatable IP address, then the application
will behave correctly when moved to another system.
Many server-style applications will bind to INADDR_ANY, meaning that they will receive
requests on any interface. This allows clients to send to the stationary or relocatable IP
addresses. However, in this case the networking code cannot determine which source
Designing Applications to Run on Multiple Systems 297