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
|
464
|
9 USE_HOSTNAME(NEWTOY(hostname, NULL, TOYFLAG_BIN))
|
463
|
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) {
|
464
|
26 if (sethostname(hostname, strlen(hostname)))
|
463
|
27 perror_exit("cannot set hostname to '%s'", hostname);
|
|
28 } else {
|
464
|
29 if (gethostname(toybuf, sizeof(toybuf)))
|
463
|
30 perror_exit("cannot get hostname");
|
464
|
31 xputs(toybuf);
|
463
|
32 }
|
|
33 }
|