Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

dnet.c

Go to the documentation of this file.
00001 /*
00002  * dnet.c
00003  *
00004  * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
00005  *
00006  * $Id: dnet.c,v 1.5 2002/03/29 06:07:49 dugsong Exp $
00007  */
00008 
00009 #include "config.h"
00010 
00011 #include <sys/types.h>
00012 
00013 #include <err.h>
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include <unistd.h>
00018 
00019 #include "dnet.h"
00020 #include "mod.h"
00021 
00022 /*
00023  * XXX - new modules should be registered here
00024  */
00025 extern struct mod mod_addr;
00026 extern struct mod mod_hex;
00027 extern struct mod mod_rand;
00028 extern struct mod mod_eth;
00029 extern struct mod mod_arp;
00030 extern struct mod mod_ip;
00031 extern struct mod mod_icmp;
00032 extern struct mod mod_tcp;
00033 extern struct mod mod_udp;
00034 extern struct mod mod_send;
00035 extern struct mod mod_fw;
00036 extern struct mod mod_intf;
00037 extern struct mod mod_route;
00038 
00039 static struct mod *modules[] = {
00040         &mod_addr, &mod_hex, &mod_rand, &mod_eth, &mod_arp, &mod_ip, &mod_icmp,
00041         &mod_tcp, &mod_udp, &mod_send, &mod_fw, &mod_intf, &mod_route, NULL
00042 };
00043 
00044 static void
00045 print_modules(int type, char *string)
00046 {
00047         struct mod **m;
00048         int i;
00049         
00050         fprintf(stderr, "%s commands:\n", string);
00051         for (i = 1, m = modules; *m != NULL; m++) {
00052                 if ((m[0]->type & type) != 0) {
00053                         fprintf(stderr, "%-10s", m[0]->name);
00054                         if ((i++ % 8) == 0)
00055                                 fprintf(stderr, "\n");
00056                 }
00057         }
00058         fprintf(stderr, "\n\n");
00059 }
00060 
00061 static void
00062 print_usage(void)
00063 {
00064         fprintf(stderr, "Usage: dnet <command> <args> ...\n\n");
00065 
00066         print_modules(MOD_TYPE_DATA, "Payload generation");
00067         print_modules(MOD_TYPE_ENCAP, "Packet encapsulation");
00068         print_modules(MOD_TYPE_XMIT, "Packet transmission");
00069         print_modules(MOD_TYPE_KERN, "Kernel interface");
00070 }
00071 
00072 static int
00073 do_command(int argc, char *argv[])
00074 {
00075         struct mod **m;
00076 
00077         for (m = modules; *m != NULL; m++) {
00078                 if (strcmp(argv[0], m[0]->name) == 0)
00079                         return (m[0]->main(argc, argv));
00080         }
00081         return (-1);
00082 }
00083 
00084 int
00085 main(int argc, char *argv[])
00086 {
00087         if (argc < 2) {
00088                 print_usage();
00089                 exit(1);
00090         }
00091         if (do_command(argc - 1, argv + 1) < 0) {
00092                 print_usage();
00093                 exit(1);
00094         }
00095         exit(0);
00096 }

Generated on Sun May 14 14:51:11 2006 by  doxygen 1.4.2