summaryrefslogtreecommitdiffstats
path: root/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c')
-rw-r--r--rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c68
1 files changed, 65 insertions, 3 deletions
diff --git a/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c b/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c
index 24893748..d02e2f44 100644
--- a/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c
+++ b/rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2013, 2018 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
@@ -30,11 +30,73 @@
*/
#include <rtems/netcmds-config.h>
-#include <machine/rtems-bsd-commands.h>
+
+#include <rtems.h>
+#include <rtems/dhcpcd.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct {
+ rtems_dhcpcd_config config;
+ char *argv[RTEMS_ZERO_LENGTH_ARRAY];
+} dhcpcd_command_config;
+
+static void
+dhcpcd_command_destroy_config(const rtems_dhcpcd_config *config, int exit_code)
+{
+ char **argv;
+
+ (void)exit_code;
+
+ argv = config->argv;
+ while (*argv != NULL) {
+ free(*argv);
+ ++argv;
+ }
+
+ free(RTEMS_DECONST(rtems_dhcpcd_config *, config));
+}
+
+static int
+dhcpcd_command(int argc, char **argv)
+{
+ dhcpcd_command_config *config;
+ rtems_status_code sc;
+ int i;
+
+ config = calloc(1, sizeof(*config) + (argc + 1) * sizeof(char *));
+ if (config == NULL) {
+ fprintf(stdout, "dhcpcd error: not enough memory\n");
+ return 1;
+ }
+
+ for (i = 0; i < argc; ++i) {
+ config->argv[i] = strdup(argv[i]);
+ if (config->argv[i] == NULL) {
+ dhcpcd_command_destroy_config(&config->config, 0);
+ fprintf(stdout, "dhcpcd error: not enough memory\n");
+ return 1;
+ }
+ }
+
+ config->config.argc = argc;
+ config->config.argv = &config->argv[0];
+ config->config.destroy = dhcpcd_command_destroy_config;
+
+ sc = rtems_dhcpcd_start(&config->config);
+ if (sc != RTEMS_SUCCESSFUL) {
+ dhcpcd_command_destroy_config(&config->config, 0);
+ fprintf(stdout, "dhcpcd start failed: %s\n", rtems_status_text(sc));
+ }
+
+ return 0;
+}
rtems_shell_cmd_t rtems_shell_DHCPCD_Command = {
.name = "dhcpcd",
.usage = "dhcpcd [args]",
.topic = "net",
- .command = rtems_bsd_command_dhcpcd
+ .command = dhcpcd_command
};