Commit | Line | Data |
---|---|---|
931b8415 | 1 | .\" Copyright (c) 1983, 1991 The Regents of the University of California. |
88b3ccf2 | 2 | .\" All rights reserved. |
6712d93b | 3 | .\" |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
88b3ccf2 | 5 | .\" |
931b8415 | 6 | .\" @(#)gethostname.3 6.7 (Berkeley) %G% |
6712d93b | 7 | .\" |
931b8415 CL |
8 | .Dd |
9 | .Dt GETHOSTNAME 2 | |
10 | .Os BSD 4.2 | |
11 | .Sh NAME | |
12 | .Nm gethostname , | |
13 | .Nm sethostname | |
14 | .Nd get/set name of current host | |
15 | .Sh SYNOPSIS | |
16 | .Fd #include <unistd.h> | |
17 | .Ft int | |
18 | .Fn gethostname "char *name" "int namelen" | |
19 | .Ft int | |
20 | .Fn sethostname "const char *name" "int namelen" | |
21 | .Sh DESCRIPTION | |
22 | .Fn Gethostname | |
6712d93b KM |
23 | returns the standard host name for the current processor, as |
24 | previously set by | |
931b8415 | 25 | .Fn sethostname . |
6712d93b | 26 | The parameter |
931b8415 | 27 | .Fa namelen |
6712d93b | 28 | specifies the size of the |
931b8415 | 29 | .Fa name |
6712d93b KM |
30 | array. The returned name is null-terminated unless insufficient |
31 | space is provided. | |
931b8415 CL |
32 | .Pp |
33 | .Fn Sethostname | |
6712d93b | 34 | sets the name of the host machine to be |
931b8415 | 35 | .Fa name , |
6712d93b | 36 | which has length |
931b8415 | 37 | .Fa namelen . |
6712d93b KM |
38 | This call is restricted to the super-user and |
39 | is normally used only when the system is bootstrapped. | |
931b8415 | 40 | .Sh RETURN VALUES |
6712d93b | 41 | If the call succeeds a value of 0 is returned. If the call |
931b8415 CL |
42 | fails, a value of -1 is returned and an error code is |
43 | placed in the global location | |
44 | .Va errno . | |
45 | .Sh ERRORS | |
6712d93b | 46 | The following errors may be returned by these calls: |
931b8415 CL |
47 | .Bl -tag -width Er |
48 | .It Bq Er EFAULT | |
49 | The | |
50 | .Fa name | |
51 | or | |
52 | .Fa namelen | |
53 | parameter gave an | |
6712d93b | 54 | invalid address. |
931b8415 | 55 | .It Bq Er EPERM |
fd690c8b | 56 | The caller tried to set the hostname and was not the super-user. |
931b8415 CL |
57 | .El |
58 | .Sh SEE ALSO | |
59 | .Xr gethostid 2 | |
60 | .Sh BUGS | |
61 | Host names are limited to | |
62 | .Dv MAXHOSTNAMELEN | |
63 | (from | |
64 | .Ao Pa sys/param.h Ac ) | |
a9172a1e | 65 | characters, currently 64. |
931b8415 CL |
66 | .Sh HISTORY |
67 | The | |
68 | .Nm | |
69 | function call appeared in | |
70 | .Bx 4.2 . |