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

21
Arrays Dimensioned by UTSLEN, SYS_NMLN, SNLEN, or MAXHOSTNAMELEN
A program might use one of the symbolic constant interfaces (UTSLEN, SYS_NMLN, SNLEN, or
MAXHOSTNAMELEN) to declare the size of array buffers to hold the node or host name. If not rebuilt
with the compiler option D_HPUX_API_LEVEL=20040821, the program’s buffer is not large
enough to hold the entire node or host name.
In most cases, when recompiling to use the expanded version, these symbol references adapt cleanly
to the expanded values. However, developers need to validate this for their code.
Because UTSLEN, SYS_NMLN, and SNLEN are used in conjunction with uname(2), and because
the program must be rebuilt to use the expanded uname(2) function version, the recompile is usually
the best approach. However, with MAXHOSTNAMELEN, it is possible to simply not use it, and have the
program simply define its own buffer sizes to pass along to gethostname(2). See “Building for
Execution on Multiple Releases. Rebuilding the program is still required, but there is more flexibility
in compilation environment and in deployment.
Arrays Dimensioned by Constant 8, 9, 15, or 64
Some programs do not use the symbolic constants but instead use hard-coded integer constants to
declare arrays that ultimately hold values returned by uname(2) or gethostname(2). Strictly
speaking, this is a violation of the specification.
These programs must be modified to use the symbolic constants before recompiling to use the
expanded interface version. (Better yet, use sysconf(_SC_HOST_NAME_MAX) to obtain the
maximum size, and dynamically allocate buffers to hold the host name. For a sample code fragment
see Dynamic Buffer Sizing.)
Embedded utsname Structure or Node/Host Name Constants
Some programs use the utsname structure or one of the node name or host name constants
(SYS_NMLN, SNLEN, UTSLEN, or MAXHOSTNAMELEN) in the definition of their own data
structures. That is, the utsname structure might be a substructure of a program data structure.
Alternatively, one of the listed constants (or their literal equivalents) might be used to declare an array
within a data structure. For the purpose of this discussion, we say one interface is “embedded
within another.
The concern about node and host name interfaces embedded within a program data structure
depends on the program’s use of that data structure.
Embedded in Internal-Only Data Structures
The node/host name structure/constant interfaces may be embedded inside program private
structures. Generally, such programs can be updated for expanded names simply by recompiling with
the option D_HPUX_API_LEVEL=20040821. The alternative approach for MAXHOSTNAMELEN
described in Building for Execution on Multiple Releasesis also acceptable.
Embedded in Storage Formats
Sometimes the node/host name structure/constant interfaces are embedded in storage formats (such
as files, tapes, and so on). Recompiling the program to use the expanded version has two problems.
First, the program can no longer read files created with the prior version of the program. To remedy