|HP-UX Reference > U
uname(2)HP-UX 11i Version 3: February 2007
uname(), setuname() — get information about computer system; set node name (system name)
int uname(struct utsname *name);
int setuname(const char *name, size_t namelen);
The uname() system call places information identifying the computer system in the utsname structure pointed to by name.
The utsname structure, defined in <sys/utsname.h>, is set up as follows:
char sysname; char nodename; char release; char version; char machine; char idnumber;
Each field is a null-terminated string.
The sysname field contains the name of the operating system, HP-UX on standard HP-UX systems.
The nodename field contains the name by which the computer system is known in a communications network.
The release field contains the release identifier of the operating system, such as B.11.23.
The version field contains additional information about the operating system. This value can change in future releases. The first character of the version field identifies the license level:
The machine field contains the hardware and model identifiers of the computer system. On Itanium®-based systems, this field always returns ia64.
The idnumber field contains a unique identification number within that class of hardware, possibly a hardware or software serial number. This field contains a null string if there is no identification number. On Itanium®-based systems this number may not be unique. To get a unique id, use the _CS_MACHINE_IDENT option of confstr.
The setuname() system call sets the node name (system name), as returned in the nodename field of the utsname structure, to name, which has a length of namelen characters. This is usually executed by /sbin/init.d/hostname at system boot time. Names are limited to UTSLEN - 1 characters; UTSLEN is defined in <sys/utsname.h>.
The actions associated with this system call require the PRIV_SYSATTR privilege (SYSATTR). Processes owned by the superuser have this privilege. Processes owned by other users may have this privilege, depending on system configuration.
See privileges(5) for more information about privileged access on systems that support fine-grained privileges.
uname() and setuname() return the following values:
The uname() function may return truncated results when the non-expanded version of the utsname structure is used. See WARNINGS.
If uname() or setuname() fails, errno is set to one of the following values.
uname() returns one of two versions of the utsname structure:
The compatible structure is used by default. To use the expanded structure, see nodehostnamesize(5).
If the administrator has configured a node name with a length larger than 8 bytes, the compatible version of the utsname structure, as returned by uname(), contains just the first 8 bytes (plus null) in the utsname.nodename field. In a future release the field will not contain any data bytes if the entire node name cannot fit.
Setting a node name of more than 8 bytes with setuname() is only possible with the appropriate configuration options enabled. It is strongly recommended that all related documentation be completely understood before setting a larger node name. A node name larger than 8 bytes can cause anomalous behavior or failure in applications which use the uname command or the uname() system function to access the name.
It is recommended that, whenever possible, programs use the host name as returned by the gethostname() function rather than the utsname.nodename field. It can be given a sufficiently large buffer to avoid truncation issues. See gethostname(2) for more information.
hostname(1), uname(1), setuname(1M), gethostname(2), sethostname(2), nodehostnamesize(5), privileges(5).