1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" 2007-07-05 mtk: Added details on underlying system call interfaces
27 .TH UNAME 2 2008-12-03 "Linux" "Linux Programmer's Manual"
29 uname \- get name and information about current kernel
31 .B #include <sys/utsname.h>
33 .BI "int uname(struct utsname *" buf );
36 returns system information in the structure pointed to by
46 char sysname[]; /* Operating system name (e.g., "Linux") */
47 char nodename[]; /* Name within "some implementation-defined
49 char release[]; /* Operating system release (e.g., "2.6.28") */
50 char version[]; /* Operating system version */
51 char machine[]; /* Hardware identifier */
53 char domainname[]; /* NIS or YP domain name */
59 The length of the arrays in a
61 is unspecified (see NOTES);
62 the fields are terminated by a null byte (\(aq\\0\(aq).
64 On success, zero is returned.
65 On error, \-1 is returned, and
81 member (the NIS or YP domain name) is a GNU extension.
83 This is a system call, and the operating system presumably knows
84 its name, release and version.
85 It also knows what hardware it runs on.
86 So, four of the fields of the struct are meaningful.
87 On the other hand, the field \fInodename\fP is meaningless:
88 it gives the name of the present machine in some undefined
89 network, but typically machines are in more than one network
90 and have several names.
91 Moreover, the kernel has no way of knowing
92 about such things, so it has to be told what to answer here.
93 The same holds for the additional \fIdomainname\fP field.
95 To this end Linux uses the system calls
98 .BR setdomainname (2).
99 Note that there is no standard that says that the hostname set by
101 is the same string as the \fInodename\fP field of the struct returned by
103 (indeed, some systems allow a 256-byte hostname and an 8-byte nodename),
104 but this is true on Linux.
106 .BR setdomainname (2)
107 and the \fIdomainname\fP field.
109 The length of the fields in the struct varies.
110 Some operating systems
111 or libraries use a hardcoded 9 or 33 or 65 or 257.
119 .BR _UTSNAME_LENGTH .
121 idea to use any of these constants; just use sizeof(...).
122 Often 257 is chosen in order to have room for an internet hostname.
124 Part of the utsname information is also accessible via
125 .IR /proc/sys/kernel/ { ostype ,
130 .SS Underlying kernel interface
132 Over time, increases in the size of the
134 structure have led to three successive versions of
138 .IR __NR_oldolduname ),
147 .\" That was back before Linux 1.0
148 used length 9 for all fields;
150 .\" That was also back before Linux 1.0
152 the third also uses 65 but adds the \fIdomainname\fP field.
155 wrapper function hides these details from applications,
156 invoking the most recent version of the system call provided by the kernel.
159 .BR getdomainname (2),