The following commit has been merged in the master branch: commit 9e12bb8c73d2791f151354eed7567bedd2256ade Author: Andreas Langer an.langer@gmx.de Date: Thu Aug 10 02:39:10 2006 +0200
visualation server ( early alpha )
diff --git a/batman.c b/batman.c index d895e96..caee894 100755 --- a/batman.c +++ b/batman.c @@ -801,6 +801,31 @@ void purge() update_routes(); */ }
+void send_vis_packet() +{ + struct list_head *pos; + struct orig_node *orig_node; + char orig_str[ADDR_STR_LEN]; + + char *packet; + +// addr_to_string(orig_node->orig, orig_str, ADDR_STR_LEN); +// addr_to_string(orig_node->router, orig_str2, ADDR_STR_LEN); +// printf("%s, %s, %i\n",orig_str, orig_str2,orig_node->packet_count); + + list_for_each(pos, &orig_list) { + orig_node = list_entry(pos, struct orig_node, list); + + + addr_to_string(orig_node->orig, orig_str, ADDR_STR_LEN); + printf("%s\n",orig_str); + } + +// addr_to_string(packet->route,orig_str,sizeof(orig_str)); +// addr_to_string(orig_node->router,orig_str2,sizeof(orig_str2)); +// printf("sende %s %s",orig_str,orig_str2); +// send_packet((unsigned char*)packet, sizeof(struct packet), &vis_if.addr, vis_if.sock); +}
@@ -840,6 +865,8 @@ int batman() output(" \n \n");
schedule_own_packet(); + if(vis_if.addr.sin_addr.s_addr) + send_vis_packet();
list_for_each(forw_pos, &forw_list) { forw_node = list_entry(forw_pos, struct forw_node, list); diff --git a/batman.h b/batman.h index b9e9120..6d1e21e 100755 --- a/batman.h +++ b/batman.h @@ -51,9 +51,8 @@ extern unsigned int pref_gateway; extern int found_ifs;
extern struct list_head if_list; - - - +extern struct vis_if vis_if; + struct packet { unsigned long orig; @@ -122,7 +121,10 @@ struct batman_if struct packet out; };
- +struct vis_if { + int sock; + struct sockaddr_in addr; +};
/* static void update_routes(); diff --git a/linux.c b/linux.c index a08d392..db0052a 100755 --- a/linux.c +++ b/linux.c @@ -37,6 +37,8 @@ #include "batman.h" #include "list.h"
+struct vis_if vis_if; + static struct timeval start_time; static int stop;
@@ -114,6 +116,9 @@ void close_all_sockets() batman_if = list_entry(if_pos, struct batman_if, list); close(batman_if->recv_sock); } + + if(vis_if.sock) + close(vis_if.sock); }
void add_del_route(unsigned int dest, unsigned int router, int del, char *dev, int sock) @@ -182,6 +187,19 @@ void *alloc_memory(int len) return res; }
+void *realloc_memory(void *ptr, int len) +{ + void *res = realloc(ptr,len); + + if (res == NULL) + { + fprintf(stderr, "Out of memory\n"); + exit(1); + } + + return res; +} + void free_memory(void *mem) { free(mem); @@ -292,6 +310,7 @@ int main(int argc, char *argv[]) struct ifreq int_req; int on = 1, res, optchar, found_args = 1; char str1[16], str2[16], *dev; + unsigned int vis_server = 0;
dev = NULL; memset(&tmp_pref_gw, 0, sizeof (struct in_addr)); @@ -380,12 +399,12 @@ int main(int argc, char *argv[]) errno = 0; if ( inet_pton(AF_INET, optarg, &tmp_pref_gw) < 1 ) {
- printf( "Invalid preferred gateway IP specified: %s\n", optarg ); + printf( "Invalid preferred visualation server IP specified: %s\n", optarg ); exit(EXIT_FAILURE);
}
- pref_gateway = tmp_pref_gw.s_addr; + vis_server = tmp_pref_gw.s_addr;
found_args += 2; @@ -476,6 +495,14 @@ int main(int argc, char *argv[])
}
+ if(vis_server) + { + memset(&vis_if.addr, 0, sizeof(vis_if.addr)); + vis_if.addr.sin_family = AF_INET; + vis_if.addr.sin_port = htons(1967); + vis_if.addr.sin_addr.s_addr = vis_server; + vis_if.sock = socket( PF_INET, SOCK_DGRAM, 0); + }
if (found_ifs == 0) { diff --git a/os.h b/os.h index 44a7360..7d4ff54 100755 --- a/os.h +++ b/os.h @@ -29,6 +29,7 @@ void output(char *format, ...); void add_del_route(unsigned int dest, unsigned int router, int del, char *dev, int sock); int is_aborted(); void *alloc_memory(int len); +void *realloc_memory(void *ptr, int len); void free_memory(void *mem); void addr_to_string(unsigned int addr, char *str, int len); int receive_packet(unsigned char *buff, int len, unsigned int *neigh, unsigned int timeout, struct batman_if **if_incoming);