1gethostname(3C)          Standard C Library Functions          gethostname(3C)
2
3
4

NAME

6       gethostname, sethostname - get or set name of current host
7

SYNOPSIS

9       #include <unistd.h>
10
11       int gethostname(char *name, int namelen);
12
13
14       int sethostname(char *name, int namelen);
15
16

DESCRIPTION

18       The  gethostname() function returns the standard host name for the cur‐
19       rent processor, as previously set by sethostname(). The  namelen  argu‐
20       ment  specifies  the size of the array pointed to by name. The returned
21       name is null-terminated unless insufficient space is provided.
22
23
24       The sethostname() function sets the name of  the  host  machine  to  be
25       name,  which  has  length namelen. This call is restricted to the supe‐
26       ruser and is normally used only when the system is bootstrapped.
27
28
29       Host names are limited to  MAXHOSTNAMELEN  characters,  currently  256,
30       defined in the <netdb.h> header.
31

RETURN VALUES

33       Upon  successful  completion, gethostname() and sethostname() return 0.
34       Otherwise, they return −1 and set errno to indicate the error.
35

ERRORS

37       The gethostname() and sethostname() functions will fail if:
38
39       EFAULT    The name or namelen argument gave an invalid address.
40
41
42
43       The sethostname() function will fail if:
44
45       EPERM    The {PRIV_SYS_ADMIN} privilege was not asserted in the  effec‐
46                tive set of the calling process.
47
48

ATTRIBUTES

50       See attributes(5) for descriptions of the following attributes:
51
52
53
54
55       ┌─────────────────────────────┬─────────────────────────────┐
56       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
57       ├─────────────────────────────┼─────────────────────────────┤
58       │Interface Stability          │Standard                     │
59       ├─────────────────────────────┼─────────────────────────────┤
60       │MT-Level                     │MT-Safe                      │
61       └─────────────────────────────┴─────────────────────────────┘
62

SEE ALSO

64       sysinfo(2), uname(2), gethostid(3C), attributes(5), standards(5)
65
66
67
68SunOS 5.11                        22 Mar 2004                  gethostname(3C)
Impressum