File: dumbnet.c

package info (click to toggle)
libdumbnet 1.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,768 kB
  • sloc: ansic: 11,563; sh: 4,203; python: 261; makefile: 92
file content (96 lines) | stat: -rw-r--r-- 1,861 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * dnet.c
 *
 * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
 *
 * $Id$
 */

#include "config.h"

#include <sys/types.h>

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "dumbnet.h"
#include "mod.h"

/*
 * XXX - new modules should be registered here
 */
extern struct mod mod_addr;
extern struct mod mod_hex;
extern struct mod mod_rand;
extern struct mod mod_eth;
extern struct mod mod_arp;
extern struct mod mod_ip;
extern struct mod mod_icmp;
extern struct mod mod_tcp;
extern struct mod mod_udp;
extern struct mod mod_send;
extern struct mod mod_fw;
extern struct mod mod_intf;
extern struct mod mod_route;

static struct mod *modules[] = {
	&mod_addr, &mod_hex, &mod_rand, &mod_eth, &mod_arp, &mod_ip, &mod_icmp,
	&mod_tcp, &mod_udp, &mod_send, &mod_fw, &mod_intf, &mod_route, NULL
};

static void
print_modules(int type, char *string)
{
	struct mod **m;
	int i;
	
	fprintf(stderr, "%s commands:\n", string);
	for (i = 1, m = modules; *m != NULL; m++) {
		if ((m[0]->type & type) != 0) {
			fprintf(stderr, "%-10s", m[0]->name);
			if ((i++ % 8) == 0)
				fprintf(stderr, "\n");
		}
	}
	fprintf(stderr, "\n\n");
}

static void
print_usage(void)
{
	fprintf(stderr, "Usage: dnet <command> <args> ...\n\n");

	print_modules(MOD_TYPE_DATA, "Payload generation");
	print_modules(MOD_TYPE_ENCAP, "Packet encapsulation");
	print_modules(MOD_TYPE_XMIT, "Packet transmission");
	print_modules(MOD_TYPE_KERN, "Kernel interface");
}

static int
do_command(int argc, char *argv[])
{
	struct mod **m;

	for (m = modules; *m != NULL; m++) {
		if (strcmp(argv[0], m[0]->name) == 0)
			return (m[0]->main(argc, argv));
	}
	return (-1);
}

int
main(int argc, char *argv[])
{
	if (argc < 2) {
		print_usage();
		exit(1);
	}
	if (do_command(argc - 1, argv + 1) < 0) {
		print_usage();
		exit(1);
	}
	exit(0);
}