1 /* hostname.c - Get/Set the hostname
2  *
3  * Copyright 2012 Andre Renaud <andre@bluewatersys.com>
4  *
5  * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/hostname.html
6 
7 USE_HOSTNAME(NEWTOY(hostname, NULL, TOYFLAG_BIN))
8 
9 config HOSTNAME
10   bool "hostname"
11   default y
12   help
13     usage: hostname [newname]
14 
15     Get/Set the current hostname
16 */
17 
18 #define FOR_hostname
19 #include "toys.h"
20 
hostname_main(void)21 void hostname_main(void)
22 {
23   const char *hostname = toys.optargs[0];
24   if (hostname) {
25     if (sethostname(hostname, strlen(hostname)))
26       perror_exit("set failed '%s'", hostname);
27   } else {
28     if (gethostname(toybuf, sizeof(toybuf))) perror_exit("get failed");
29     xputs(toybuf);
30   }
31 }
32