[rtems-libbsd commit] Add ifconfig command as RTEMS Shell command
Joel Sherrill
joel at rtems.org
Fri Oct 12 00:01:45 UTC 2012
Module: rtems-libbsd
Branch: master
Commit: 44ffbd53c6b956ef12d2e530d04ec5b530c2b161
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=44ffbd53c6b956ef12d2e530d04ec5b530c2b161
Author: Joel Sherrill <joel.sherrill at oarcorp.com>
Date: Thu Oct 11 19:03:46 2012 -0500
Add ifconfig command as RTEMS Shell command
This is enough to be able to invoke the ifconfig command but it
calls exit() which is inappropriate.
The "struct option" in the ifconfig code conflicts with a structure
of the same name in newlib's and glibc's getopt.h.
---
.../commands/sbin/ifconfig/af_inet6.c | 4 ++
freebsd-userspace/commands/sbin/ifconfig/ifclone.c | 4 ++
.../commands/sbin/ifconfig/ifconfig.c | 50 +++++++++++++++++++-
.../commands/sbin/ifconfig/ifconfig.h | 12 +++++
freebsd-userspace/commands/sbin/ifconfig/ifgroup.c | 4 ++
freebsd-userspace/rtems/include/namespace.h | 1 +
.../rtems/include/rtems/netcmds-config.h | 4 +-
testsuite/netshell01/shellconfig.c | 4 +-
8 files changed, 78 insertions(+), 5 deletions(-)
diff --git a/freebsd-userspace/commands/sbin/ifconfig/af_inet6.c b/freebsd-userspace/commands/sbin/ifconfig/af_inet6.c
index c09c778..ff0df5b 100644
--- a/freebsd-userspace/commands/sbin/ifconfig/af_inet6.c
+++ b/freebsd-userspace/commands/sbin/ifconfig/af_inet6.c
@@ -540,7 +540,11 @@ in6_Lopt_cb(const char *optarg __unused)
{
ip6lifetime++; /* print IPv6 address lifetime */
}
+#ifdef __rtems__
+static struct ifconfig_option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb };
+#else
static struct option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb };
+#endif
static __constructor void
inet6_ctor(void)
diff --git a/freebsd-userspace/commands/sbin/ifconfig/ifclone.c b/freebsd-userspace/commands/sbin/ifconfig/ifclone.c
index 3dc5a37..7929208 100644
--- a/freebsd-userspace/commands/sbin/ifconfig/ifclone.c
+++ b/freebsd-userspace/commands/sbin/ifconfig/ifclone.c
@@ -183,7 +183,11 @@ clone_Copt_cb(const char *optarg __unused)
list_cloners();
exit(0);
}
+#ifdef __rtems__
+static struct ifconfig_option clone_Copt = { .opt = "C", .opt_usage = "[-C]", .cb = clone_Copt_cb };
+#else
static struct option clone_Copt = { .opt = "C", .opt_usage = "[-C]", .cb = clone_Copt_cb };
+#endif
static __constructor void
clone_ctor(void)
diff --git a/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c b/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
index 8487ccb..3c1a16f 100644
--- a/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
+++ b/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
@@ -1,3 +1,7 @@
+#ifdef __rtems__
+#define __need_getopt_newlib
+#include <getopt.h>
+#endif
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
@@ -123,6 +127,16 @@ static struct afswtch *af_getbyname(const char *name);
static struct afswtch *af_getbyfamily(int af);
static void af_other_status(int);
+#ifdef __rtems__
+static struct ifconfig_option *opts = NULL;
+
+void
+opt_register(struct ifconfig_option *p)
+{
+ p->next = opts;
+ opts = p;
+}
+#else
static struct option *opts = NULL;
void
@@ -131,12 +145,17 @@ opt_register(struct option *p)
p->next = opts;
opts = p;
}
+#endif
static void
usage(void)
{
char options[1024];
+ #ifdef __rtems__
+ struct ifconfig_option *p;
+ #else
struct option *p;
+ #endif
/* XXX not right but close enough for now */
options[0] = '\0';
@@ -172,8 +191,15 @@ main(int argc, char *argv[])
const struct sockaddr_dl *sdl;
char options[1024], *cp;
const char *ifname;
+#ifdef __rtems__
+ struct ifconfig_option *p;
+#else
struct option *p;
+#endif
size_t iflen;
+#ifdef __rtems__
+ struct getopt_data getopt_reent;
+#endif
all = downonly = uponly = namesonly = noload = verbose = 0;
@@ -181,7 +207,12 @@ main(int argc, char *argv[])
strlcpy(options, "adklmnuv", sizeof(options));
for (p = opts; p != NULL; p = p->next)
strlcat(options, p->opt, sizeof(options));
+#ifdef __rtems__
+ memset(&getopt_reent, 0, sizeof(getopt_data));
+ while ((c = getopt_r(argc, argv, options, &getopt_reent)) != -1) {
+#else
while ((c = getopt(argc, argv, options)) != -1) {
+#endif
switch (c) {
case 'a': /* scan all interfaces */
all++;
@@ -672,8 +703,8 @@ setifvnet(const char *jname, int dummy __unused, int s,
struct ifreq my_ifr;
memcpy(&my_ifr, &ifr, sizeof(my_ifr));
- my_ifr.ifr_jid = jail_getid(jname);
#ifndef __rtems__
+ my_ifr.ifr_jid = jail_getid(jname);
if (my_ifr.ifr_jid < 0)
errx(1, "%s", jail_errmsg);
#endif
@@ -688,8 +719,8 @@ setifrvnet(const char *jname, int dummy __unused, int s,
struct ifreq my_ifr;
memcpy(&my_ifr, &ifr, sizeof(my_ifr));
- my_ifr.ifr_jid = jail_getid(jname);
#ifndef __rtems__
+ my_ifr.ifr_jid = jail_getid(jname);
if (my_ifr.ifr_jid < 0)
errx(1, "%s", jail_errmsg);
#endif
@@ -1061,6 +1092,7 @@ printb(const char *s, unsigned v, const char *bits)
void
ifmaybeload(const char *name)
{
+#ifndef __rtems__
#define MOD_PREFIX_LEN 3 /* "if_" */
struct module_stat mstat;
int fileid, modid;
@@ -1107,6 +1139,7 @@ ifmaybeload(const char *name)
/* not present, we should try to load it */
kldload(ifkind);
+#endif
}
static struct cmd basic_cmds[] = {
@@ -1188,3 +1221,16 @@ ifconfig_ctor(void)
cmd_register(&basic_cmds[i]);
#undef N
}
+
+#ifdef __rtems__
+ #include <rtems/shell.h>
+
+ rtems_shell_cmd_t rtems_shell_IFCONFIG_Command = {
+ "ifconfig", /* name */
+ "ifconfig [args]", /* usage */
+ "net", /* topic */
+ main_ifconfig, /* command */
+ NULL, /* alias */
+ NULL /* next */
+ };
+#endif
diff --git a/freebsd-userspace/commands/sbin/ifconfig/ifconfig.h b/freebsd-userspace/commands/sbin/ifconfig/ifconfig.h
index a624f60..479bc2a 100644
--- a/freebsd-userspace/commands/sbin/ifconfig/ifconfig.h
+++ b/freebsd-userspace/commands/sbin/ifconfig/ifconfig.h
@@ -121,13 +121,25 @@ struct afswtch {
};
void af_register(struct afswtch *);
+#ifdef __rtems__
+struct ifconfig_option {
+#else
struct option {
+#endif
const char *opt;
const char *opt_usage;
void (*cb)(const char *arg);
+ #ifdef __rtems__
+ struct ifconfig_option *next;
+ #else
struct option *next;
+ #endif
};
+#ifdef __rtems__
+void opt_register(struct ifconfig_option *);
+#else
void opt_register(struct option *);
+#endif
extern struct ifreq ifr;
extern char name[IFNAMSIZ]; /* name of interface */
diff --git a/freebsd-userspace/commands/sbin/ifconfig/ifgroup.c b/freebsd-userspace/commands/sbin/ifconfig/ifgroup.c
index 9eaac3b..2de03e7 100644
--- a/freebsd-userspace/commands/sbin/ifconfig/ifgroup.c
+++ b/freebsd-userspace/commands/sbin/ifconfig/ifgroup.c
@@ -170,7 +170,11 @@ static struct afswtch af_group = {
.af_af = AF_UNSPEC,
.af_other_status = getifgroups,
};
+#ifdef __rtems__
+static struct ifconfig_option group_gopt = { "g:", "[-g groupname]", printgroup };
+#else
static struct option group_gopt = { "g:", "[-g groupname]", printgroup };
+#endif
static __constructor void
group_ctor(void)
diff --git a/freebsd-userspace/rtems/include/namespace.h b/freebsd-userspace/rtems/include/namespace.h
index 0b84463..83be334 100644
--- a/freebsd-userspace/rtems/include/namespace.h
+++ b/freebsd-userspace/rtems/include/namespace.h
@@ -55,6 +55,7 @@
#define _fsync fsync
#define _fstat fstat
#define _stat stat
+#define _ioctl ioctl
#define _sigprocmask sigprocmask
diff --git a/freebsd-userspace/rtems/include/rtems/netcmds-config.h b/freebsd-userspace/rtems/include/rtems/netcmds-config.h
index 932465f..f684816 100644
--- a/freebsd-userspace/rtems/include/rtems/netcmds-config.h
+++ b/freebsd-userspace/rtems/include/rtems/netcmds-config.h
@@ -25,8 +25,8 @@
extern rtems_shell_cmd_t rtems_shell_PING_Command;
extern rtems_shell_cmd_t rtems_shell_PING6_Command;
- // extern rtems_shell_cmd_t rtems_shell_IFCONFIG_Command;
- // extern rtems_shell_cmd_t rtems_shell_ROUTE_Command;
+ extern rtems_shell_cmd_t rtems_shell_IFCONFIG_Command;
+ extern rtems_shell_cmd_t rtems_shell_ROUTE_Command;
// extern rtems_shell_cmd_t rtems_shell_NETSTATS_Command;
// #endif
diff --git a/testsuite/netshell01/shellconfig.c b/testsuite/netshell01/shellconfig.c
index df3e421..ee914c7 100644
--- a/testsuite/netshell01/shellconfig.c
+++ b/testsuite/netshell01/shellconfig.c
@@ -10,7 +10,9 @@
#define CONFIGURE_SHELL_COMMANDS_ALL
#define CONFIGURE_SHELL_USER_COMMANDS \
- &rtems_shell_PING_Command
+ &rtems_shell_PING_Command, \
+ &rtems_shell_ROUTE_Command, \
+ &rtems_shell_IFCONFIG_Command
#include <rtems/shellconfig.h>
More information about the vc
mailing list