From 74fc3b4576596094d7cc5ebbaf3c21c9c74fb760 Mon Sep 17 00:00:00 2001 From: oliverschmidt Date: Fri, 4 Jan 2008 23:23:29 +0000 Subject: [PATCH] Made netsim gateway ip addr on Windows/Cygwin configurable at the command line. --- platform/netsim/main.c | 22 +++++++++++++++++++--- platform/netsim/node.c | 12 ++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/platform/netsim/main.c b/platform/netsim/main.c index 7492b2445..ee0dd843b 100644 --- a/platform/netsim/main.c +++ b/platform/netsim/main.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: main.c,v 1.8 2007/11/28 12:54:42 adamdunkels Exp $ + * $Id: main.c,v 1.9 2008/01/04 23:23:29 oliverschmidt Exp $ */ /** @@ -59,6 +59,9 @@ #include #include #include +#include + +in_addr_t gwaddr; void netsim_init(void); @@ -158,6 +161,16 @@ main_add_base(int x, int y) int main(int argc, char **argv) { +#ifdef __CYGWIN__ + if(argc < 3 || inet_addr(argv[1]) == INADDR_NONE || + inet_addr(argv[2]) == INADDR_NONE) { + printf("usage: " + "\n"); + exit(1); + } + gwaddr = inet_addr(argv[2]); +#endif /* __CYGWIN__ */ + /* system("ifconfig tap0 inet 192.168.250.1");*/ /* system("route delete 172.16.0.0/16"); system("route add 172.16.0.0/16 192.168.250.2");*/ @@ -179,7 +192,12 @@ main(int argc, char **argv) usleep(100); } #endif /* 0 */ + +#ifdef __CYGWIN__ + if(argc > 3 && strcmp(argv[3], "-q") == 0) { +#else /* __CYGWIN__ */ if(argc > 1 && strcmp(argv[1], "-q") == 0) { +#endif /* __CYGWIN__ */ display_init(idle, 50, 0); } else { display_init(idle, 50, 1); @@ -188,14 +206,12 @@ main(int argc, char **argv) signal(SIGCHLD, sigchld_handler); - display_run(); return 0; argv = argv; argc = argc; - } /*-----------------------------------------------------------------------------------*/ char *arg_alloc(char size) {return NULL;} diff --git a/platform/netsim/node.c b/platform/netsim/node.c index 7f292338f..b84303d96 100644 --- a/platform/netsim/node.c +++ b/platform/netsim/node.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: node.c,v 1.9 2007/11/28 13:01:02 nvt-se Exp $ + * $Id: node.c,v 1.10 2008/01/04 23:23:29 oliverschmidt Exp $ */ #include "node.h" #include "contiki.h" @@ -38,6 +38,9 @@ #include "net/rime.h" #include #include +#include + +extern in_addr_t gwaddr; static clock_time_t drift, timer; @@ -59,10 +62,13 @@ node_init(int id, int posx, int posy, int b) /* node.type = NODE_TYPE_NORMAL;*/ if(b) { +#ifdef __CYGWIN__ + addr = *(uip_ipaddr_t *)&gwaddr; +#else /* __CYGWIN__ */ uip_ipaddr(&addr, 192,168,1,2); +#endif /* __CYGWIN__ */ } else { uip_ipaddr(&addr, 172,16,posx,posy); - } uip_sethostaddr(&addr); @@ -73,8 +79,6 @@ node_init(int id, int posx, int posy, int b) nodeaddr.u8[1] = posy; rimeaddr_set_node_addr(&nodeaddr); } - - drift = rand() % 95726272;