Added command line options for debug and ping output.

This commit is contained in:
christiaans 2006-04-19 07:30:02 +00:00
parent bce92dd2f6
commit 3cc467e481
3 changed files with 112 additions and 54 deletions

View File

@ -49,3 +49,13 @@ For Linux you might need to create a device node with
Finally, "simhost" also includes a simple web server; the URL is
of course http://192.168.0.2/.
* Simhost has some extra features that can be
selected with command line options.
To enable runtime debug output (project must be build with -DLWIP_DEBUG):
# ./simhost -d
To ping any host, e.g. the gateway:
# ./simhost -p 192.168.0.1

View File

@ -65,8 +65,8 @@
#define TCP_QLEN_DEBUG DBG_ON
#define TCP_RST_DEBUG DBG_ON
#define DBG_TYPES_ON (DBG_ON|DBG_TRACE|DBG_STATE|DBG_FRESH|DBG_HALT)
extern unsigned char debug_flags;
#define DBG_TYPES_ON debug_flags
/* ---------- Memory options ---------- */
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which

View File

@ -32,6 +32,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include "lwip/opt.h"
@ -74,6 +75,32 @@
#include "lwip/sockets.h"
#endif
/* ping out destination cmd option */
unsigned char ping_flag;
struct ip_addr ping_addr;
/* nonstatic debug cmd option, exported in lwipopts.h */
unsigned char debug_flags;
static struct option longopts[] = {
/* turn on debugging output (if build with LWIP_DEBUG) */
{"debug", no_argument, NULL, 'd'},
/* ping destination */
{"ping", required_argument, NULL, 'p'},
/* new command line options go here! */
{NULL, 0, NULL, 0}
};
#define NUM_OPTS ((sizeof(longopts) / sizeof(struct option)) - 1)
void usage(void)
{
unsigned char i;
printf("options:\n");
for (i = 0; i < NUM_OPTS; i++) {
printf("-%c --%s\n",longopts[i].val, longopts[i].name);
}
}
static void
tcp_debug_timeout(void *data)
@ -190,18 +217,15 @@ static void
ping_thread(void *arg)
{
struct raw_pcb *raw;
struct ip_addr dest_addr;
if (!(raw = raw_new(IP_PROTO_ICMP))) return;
raw_recv(raw,ping_recv,NULL);
IP4_ADDR(&dest_addr,192,168,2,1);
while (1)
{
printf("ping send\n");
ping_send(raw,&dest_addr);
ping_send(raw,&ping_addr);
sleep(1);
}
/* Never reaches this */
@ -250,18 +274,15 @@ static void
ping_thread(void *arg)
{
int s;
struct ip_addr dest_addr;
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
return;
}
IP4_ADDR(&dest_addr,192,168,2,1);
while (1) {
printf("sending ping\n");
ping_send(s,&dest_addr);
ping_recv(s,&dest_addr);
ping_send(s,&ping_addr);
ping_recv(s,&ping_addr);
sleep(1);
}
}
@ -359,7 +380,10 @@ main_thread(void *arg)
#endif
#if LWIP_RAW
/* @todo remove dependency on RAW PCB support */
if(ping_flag) {
sys_thread_new(ping_thread, NULL, DEFAULT_THREAD_PRIO);
}
#endif
printf("Applications started.\n");
@ -380,6 +404,30 @@ main_thread(void *arg)
int
main(int argc, char **argv)
{
int ch;
ping_flag = 0;
/* use debug flags defined by debug.h */
debug_flags = (DBG_OFF|DBG_TRACE|DBG_STATE|DBG_FRESH|DBG_HALT);
while ((ch = getopt_long(argc, argv, "dp:", longopts, NULL)) != -1) {
switch (ch) {
case 'd':
debug_flags |= DBG_ON;
break;
case 'p':
ping_flag = !0;
/* which one is used? lwip's or our local inet_aton()? */
inet_aton(optarg, &ping_addr);
printf("Using %"X32_F" to ping\n",ping_addr.addr);
break;
default:
usage();
break;
}
}
argc -= optind;
argv += optind;
#ifdef PERF
perf_init("/tmp/simhost.perf");
#endif /* PERF */