Files
rtems/cpukit/libmisc/shell/main_route.c
Ralf Corsepius 3421e5201f * libmisc/shell/main_help.c: Make rtems_shell_help_cmd,
rtems_shell_help static.
	* libmisc/shell/main_hexdump.c: Make main_hexdump static.
	* libmisc/shell/main_id.c: Make rtems_shell_main_id static.
	* libmisc/shell/main_ifconfig.c: Make rtems_shell_main_ifconfig static.
	* libmisc/shell/main_ln.c: Make rtems_shell_main_ln static.
	* libmisc/shell/main_logoff.c: Make rtems_shell_main_logoff static.
	* libmisc/shell/main_ls.c: Make rtems_shell_main_ls static.
	* libmisc/shell/main_mallocinfo.c: Include <rtems/libcsupport.h>.
	Remove private decls of malloc_info,
	rtems_shell_print_unified_work_area_message.
	Make rtems_shell_main_malloc_info static.
	* libmisc/shell/main_medit.c: Remove private decl of
	rtems_shell_main_mdump.
	Make rtems_shell_main_medit static.
	* libmisc/shell/main_mfill.c: Make rtems_shell_main_mfill static.
	* libmisc/shell/main_mkdir.c: Make rtems_shell_main_mkdir static.
	* libmisc/shell/main_mknod.c: Make rtems_shell_main_mknod static.
	* libmisc/shell/main_mmove.c: Remove private decl of
	rtems_shell_main_mdump.
	Make rtems_shell_main_mmove static.
	* libmisc/shell/main_mount.c: Make rtems_shell_main_mount static.
	* libmisc/shell/main_msdosfmt.c: Make rtems_shell_main_msdos_format
	static.
	* libmisc/shell/main_mv.c: Include "internal.h".
	Make rtems_shell_mv_exit, rtems_shell_main_mv static.
	Remove private decls of strmode rtems_shell_main_cp,
	rtems_shell_main_rm.
	* libmisc/shell/main_mwdump.c: Make rtems_shell_main_mwdump static.
	* libmisc/shell/main_netstats.c: Make rtems_shell_main_netstats
	static.
	* libmisc/shell/main_perioduse.c: Make rtems_shell_main_perioduse
	static.
	* libmisc/shell/main_pwd.c: Make rtems_shell_main_pwd static.
	* libmisc/shell/main_rm.c: Include "internal.h".
	Make rtems_shell_rm_exit static.
	Remove private decl of strmode.
	* libmisc/shell/main_rmdir.c: Make rtems_shell_main_rmdir static.
	libmisc/shell/main_route.c: Make rtems_shell_main_route static.
	* libmisc/shell/main_setenv.c: Make rtems_shell_main_setenv static.
	* libmisc/shell/main_sleep.c: Make rtems_shell_main_sleep static.
	* libmisc/shell/main_stackuse.c: Make rtems_shell_main_stackuse static.
	* libmisc/shell/main_time.c: Make rtems_shell_main_time static.
	* libmisc/shell/main_tty.c: Make rtems_shell_main_tty static.
	* libmisc/shell/main_umask.c: Make rtems_shell_main_umask static.
	* libmisc/shell/main_unmount.c: Make rtems_shell_main_unmount
	static.
	* libmisc/shell/main_unsetenv.c: Make rtems_shell_main_unsetenv
	static.
	* libmisc/shell/main_whoami.c: Make rtems_shell_main_whoami static.
	* libmisc/shell/main_wkspaceinfo.c: Make
	rtems_shell_main_wkspace_info static.
2011-12-04 10:22:51 +00:00

154 lines
3.4 KiB
C

/*
* ROUTE Command Implmentation
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <rtems.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/shell.h>
#include "internal.h"
static int rtems_shell_main_route(
int argc,
char *argv[]
)
{
int cmd;
struct sockaddr_in dst;
struct sockaddr_in gw;
struct sockaddr_in netmask;
int f_host;
int f_gw = 0;
int cur_idx;
int flags;
int rc;
memset(&dst, 0, sizeof(dst));
memset(&gw, 0, sizeof(gw));
memset(&netmask, 0, sizeof(netmask));
dst.sin_len = sizeof(dst);
dst.sin_family = AF_INET;
dst.sin_addr.s_addr = inet_addr("0.0.0.0");
gw.sin_len = sizeof(gw);
gw.sin_family = AF_INET;
gw.sin_addr.s_addr = inet_addr("0.0.0.0");
netmask.sin_len = sizeof(netmask);
netmask.sin_family = AF_INET;
netmask.sin_addr.s_addr = inet_addr("255.255.255.0");
if (argc < 2) {
rtems_bsdnet_show_inet_routes();
return 0;
}
if (strcmp(argv[1], "add") == 0) {
cmd = RTM_ADD;
} else if (strcmp(argv[1], "del") == 0) {
cmd = RTM_DELETE;
} else {
printf("invalid command: %s\n", argv[1]);
printf("\tit should be 'add' or 'del'\n");
return -1;
}
if (argc < 3) {
printf("not enough arguments\n");
return -1;
}
if (strcmp(argv[2], "-host") == 0) {
f_host = 1;
} else if (strcmp(argv[2], "-net") == 0) {
f_host = 0;
} else {
printf("Invalid type: %s\n", argv[1]);
printf("\tit should be '-host' or '-net'\n");
return -1;
}
if (argc < 4) {
printf("not enough arguments\n");
return -1;
}
inet_pton(AF_INET, argv[3], &dst.sin_addr);
cur_idx = 4;
while(cur_idx < argc) {
if (strcmp(argv[cur_idx], "gw") == 0) {
if ((cur_idx +1) >= argc) {
printf("no gateway address\n");
return -1;
}
f_gw = 1;
inet_pton(AF_INET, argv[cur_idx + 1], &gw.sin_addr);
cur_idx += 1;
} else if(strcmp(argv[cur_idx], "netmask") == 0) {
if ((cur_idx +1) >= argc) {
printf("no netmask address\n");
return -1;
}
f_gw = 1;
inet_pton(AF_INET, argv[cur_idx + 1], &netmask.sin_addr);
cur_idx += 1;
} else {
printf("Unknown argument\n");
return -1;
}
cur_idx += 1;
}
flags = RTF_STATIC;
if (f_gw != 0) {
flags |= RTF_GATEWAY;
}
if (f_host != 0) {
flags |= RTF_HOST;
}
rc = rtems_bsdnet_rtrequest(
cmd,
(struct sockaddr *)&dst,
(struct sockaddr *)&gw,
(struct sockaddr *)&netmask,
flags,
NULL
);
if (rc < 0) {
printf("Error adding route\n");
}
return 0;
}
rtems_shell_cmd_t rtems_shell_ROUTE_Command = {
"route", /* name */
"TBD", /* usage */
"network", /* topic */
rtems_shell_main_route, /* command */
NULL, /* alias */
NULL /* next */
};