summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/command.c19
-rw-r--r--lib/command.h2
-rw-r--r--tests/common-cli.c2
3 files changed, 13 insertions, 10 deletions
diff --git a/lib/command.c b/lib/command.c
index 9485beddd9..510699f91b 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1541,6 +1541,14 @@ DEFUN (show_startup_config,
return CMD_SUCCESS;
}
+int
+cmd_hostname_set (const char *hostname)
+{
+ XFREE (MTYPE_HOST, host.name);
+ host.name = hostname ? XSTRDUP (MTYPE_HOST, hostname) : NULL;
+ return CMD_SUCCESS;
+}
+
/* Hostname configuration */
DEFUN (config_hostname,
hostname_cmd,
@@ -1556,11 +1564,7 @@ DEFUN (config_hostname,
return CMD_WARNING;
}
- if (host.name)
- XFREE (MTYPE_HOST, host.name);
-
- host.name = XSTRDUP (MTYPE_HOST, word->arg);
- return CMD_SUCCESS;
+ return cmd_hostname_set (word->arg);
}
DEFUN (config_no_hostname,
@@ -1570,10 +1574,7 @@ DEFUN (config_no_hostname,
"Reset system's network name\n"
"Host name of this router\n")
{
- if (host.name)
- XFREE (MTYPE_HOST, host.name);
- host.name = NULL;
- return CMD_SUCCESS;
+ return cmd_hostname_set (NULL);
}
/* VTY interface password set. */
diff --git a/lib/command.h b/lib/command.h
index 3c3c3ae370..8986703708 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -424,6 +424,8 @@ extern void cmd_terminate (void);
extern void cmd_exit (struct vty *vty);
extern int cmd_list_cmds (struct vty *vty, int do_permute);
+extern int cmd_hostname_set (const char *hostname);
+
/* NOT safe for general use; call this only if DEV_BUILD! */
extern void grammar_sandbox_init (void);
diff --git a/tests/common-cli.c b/tests/common-cli.c
index dc1f052bc2..7f7d253e6c 100644
--- a/tests/common-cli.c
+++ b/tests/common-cli.c
@@ -72,7 +72,7 @@ main (int argc, char **argv)
/* Library inits. */
cmd_init (1);
- host.name = XSTRDUP(MTYPE_HOST,"test");
+ cmd_hostname_set ("test");
vty_init (master);
memory_init ();