Node and Host Name Sizes on HP-UX: Using the Expanded Capabilities of HP-UX

12
All programmers are advised to read Appendix C, “Source Code Issues with Expanded Node and
Host Names,” and inspect their programs for actual usage of the names, to ensure the program
operates correctly when recompiled.
Building for Execution on Multiple Releases
This section describes how to build a program to handle expanded node or host names to be
executed on systems regardless of release or update level.
Building for Any HP-UX 11i v2 or Higher System
If a program is compiled with -D_HPUX_API_LEVEL=20040821 and the node-name related
interfaces are used, the resulting binary might not be portable to HP-UX 11i v2 systems that do not
have the 11i v2 September 2004 Update or later installed. However, programmers can take
additional measures to ensure the binary program runs on the original, nonupdated, 11i v2 system:
Do not use the compiler option -D_HPUX_API_LEVEL=20040821.
Use gethostname(2) in place of utsname.nodename (you might need to scan up to the
first dot (“.”) if a fully qualified domain name is not desired).
If the uname() function is used for data other than the node name, the program should be
prepared to deal gracefully with the EOVERFLOW error status which indicates that the whole
node name did not fit into the utsname.nodename field and has been truncated.
Do not use the MAXHOSTNAMELEN symbolic constant. Instead, define a private symbolic
constant to set the size of buffers and the size parameter passed to gethostname(). The
value must be at least 256.
Build on any HP-UX 11i v2 system, regardless of update level.
The resulting application binary should run correctly on any HP-UX 11i v2 system and all subsequent
versions. It is also expanded node and host name clean, which means it accommodates any current
and future version of HP-UX that supports expanded node and host names and for which the system
administrator has set long names.
Do not use this approach for programs that re-export, via an API, the utsname structure, or any of
the symbolic constants: MAXHOSTNAMELEN, UTSLEN, SYS_NMLN, SNLEN (or equivalents).
Caution: For programs that use utsname structure fields other than nodename, do not ignore the
EOVERFLOW error. A future HP-UX update or release might expand the possible values of other
fields. The program should determine whether or not the values obtained are complete. Furthermore,
in a future version of HP-UX, generation of the EOVERFLOW error might also inhibit the return of any
data, whether or not it is truncated. For additional information about this check the release notes that
accompany updates and releases.
Building for Any HP-UX Version
Many programmers prefer to create a single application binary to be deployed on any HP-UX OS
release. For instance, a PA-RISC binary can be built on HP-UX 11.00, and be deployed on that
release and on HP-UX 11i v1, v2, and future versions. An Intel® Itanium®-based binary can be built
on HP-UX 11i v1.6, and be deployed on that version, HP-UX 11i v2, and on future versions.