summaryrefslogtreecommitdiffstats
path: root/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@oarcorp.com>2012-10-11 19:03:46 -0500
committerJoel Sherrill <joel.sherrill@oarcorp.com>2012-10-11 19:03:46 -0500
commit44ffbd53c6b956ef12d2e530d04ec5b530c2b161 (patch)
tree6a5e1d2f36b5e420a9b9386490f3d4d32e5fe511 /freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
parentUserspace Makefile: Clean up yacc/lex handling to avoid conflicts (diff)
downloadrtems-libbsd-44ffbd53c6b956ef12d2e530d04ec5b530c2b161.tar.bz2
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.
Diffstat (limited to 'freebsd-userspace/commands/sbin/ifconfig/ifconfig.c')
-rw-r--r--freebsd-userspace/commands/sbin/ifconfig/ifconfig.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c b/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
index 8487ccbf..3c1a16f4 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