HOSTNAME(1): Add -m flag

This commit is contained in:
Sebastian Huber 2014-11-10 08:27:55 +01:00
parent 026abfb7ae
commit e6405ea0cb
2 changed files with 38 additions and 2 deletions

View File

@ -46,6 +46,7 @@ static char sccsid[] = "@(#)hostname.c 8.1 (Berkeley) 5/31/93";
#include <rtems/netcmds-config.h> #include <rtems/netcmds-config.h>
#include <machine/rtems-bsd-program.h> #include <machine/rtems-bsd-program.h>
#include <machine/rtems-bsd-commands.h> #include <machine/rtems-bsd-commands.h>
#include <rtems/mdns.h>
#endif /* __rtems__ */ #endif /* __rtems__ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD$"); __FBSDID("$FreeBSD$");
@ -78,7 +79,7 @@ static int hostname_command(int argc, char *argv[])
rtems_shell_cmd_t rtems_shell_HOSTNAME_Command = { rtems_shell_cmd_t rtems_shell_HOSTNAME_Command = {
.name = "hostname", .name = "hostname",
.usage = "hostname [-fs] [name-of-host]", .usage = "hostname [-fms] [name-of-host]",
.topic = "net", .topic = "net",
.command = hostname_command .command = hostname_command
}; };
@ -93,10 +94,15 @@ main(int argc, char *argv[])
memset(&getopt_data, 0, sizeof(getopt_data)); memset(&getopt_data, 0, sizeof(getopt_data));
#define optind getopt_data.optind #define optind getopt_data.optind
#define getopt(argc, argv, opt) getopt_r(argc, argv, "+" opt, &getopt_data) #define getopt(argc, argv, opt) getopt_r(argc, argv, "+" opt, &getopt_data)
int mflag = 0;
#endif /* __rtems__ */ #endif /* __rtems__ */
sflag = 0; sflag = 0;
#ifndef __rtems__
while ((ch = getopt(argc, argv, "fs")) != -1) while ((ch = getopt(argc, argv, "fs")) != -1)
#else /* __rtems__ */
while ((ch = getopt(argc, argv, "fms")) != -1)
#endif /* __rtems__ */
switch (ch) { switch (ch) {
case 'f': case 'f':
/* /*
@ -108,6 +114,11 @@ main(int argc, char *argv[])
case 's': case 's':
sflag = 1; sflag = 1;
break; break;
#ifdef __rtems__
case 'm':
mflag = 1;
break;
#endif /* __rtems__ */
case '?': case '?':
default: default:
usage(); usage();
@ -119,8 +130,24 @@ main(int argc, char *argv[])
usage(); usage();
if (*argv) { if (*argv) {
#ifdef __rtems__
if (mflag) {
if (rtems_mdns_sethostname(*argv)) {
err(1, "rtems_mdns_sethostname");
}
} else {
#endif /* __rtems__ */
if (sethostname(*argv, (int)strlen(*argv))) if (sethostname(*argv, (int)strlen(*argv)))
err(1, "sethostname"); err(1, "sethostname");
#ifdef __rtems__
}
} else if (mflag) {
if (rtems_mdns_gethostname(hostname, sizeof(hostname))) {
err(1, "rtems_mdns_gethostname");
}
(void)printf("%s\n", hostname);
#endif /* __rtems__ */
} else { } else {
if (gethostname(hostname, (int)sizeof(hostname))) if (gethostname(hostname, (int)sizeof(hostname)))
err(1, "gethostname"); err(1, "gethostname");
@ -138,6 +165,6 @@ static void
usage(void) usage(void)
{ {
(void)fprintf(stderr, "usage: hostname [-fs] [name-of-host]\n"); (void)fprintf(stderr, "usage: hostname [-fms] [name-of-host]\n");
exit(1); exit(1);
} }

View File

@ -285,6 +285,15 @@ Make sure that the interface flag IFF_UP and the interface driver flag
IFF_DRV_RUNNING is set in case the link is up, otherwise ether_output() will IFF_DRV_RUNNING is set in case the link is up, otherwise ether_output() will
return the error status ENETDOWN. return the error status ENETDOWN.
== Shell Commands
=== HOSTNAME(1)
In addition to the standard options the RTEMS version of the HOSTNAME(1)
command supports the -m flag to set/get the multicast hostname of the
mDNS resolver instance. See also rtems_mdns_sethostname() and
rtems_mdns_gethostname().
== Issues and TODO == Issues and TODO
* Per-CPU data should be enabled once the new stack is ready for SMP. * Per-CPU data should be enabled once the new stack is ready for SMP.