463
|
1 /* vi: set sw=4 ts=4:
|
|
2 *
|
|
3 * hostname.c - Get/Set the hostname
|
|
4 *
|
|
5 * Copyright 2012 Andre Renaud <andre@bluewatersys.com>
|
|
6 *
|
|
7 * Not in SUSv4.
|
|
8
|
|
9 USE_HOSTNAME(NEWTOY(hostname, "", TOYFLAG_BIN))
|
|
10
|
|
11 config HOSTNAME
|
|
12 bool "hostname"
|
|
13 default n
|
|
14 help
|
|
15 usage: hostname [newname]
|
|
16
|
|
17 Get/Set the current hostname
|
|
18 */
|
|
19
|
|
20 #include "toys.h"
|
|
21
|
|
22 void hostname_main(void)
|
|
23 {
|
|
24 const char *hostname = toys.optargs[0];
|
|
25 if (hostname) {
|
|
26 int len = strlen(hostname);
|
|
27 if (sethostname(hostname, len))
|
|
28 perror_exit("cannot set hostname to '%s'", hostname);
|
|
29 } else {
|
|
30 char buffer[256];
|
|
31 if (gethostname(buffer, sizeof(buffer)))
|
|
32 perror_exit("cannot get hostname");
|
|
33 xprintf("%s\n", buffer);
|
|
34 }
|
|
35 }
|