Commit ed01ef0a authored by Marek Lindner's avatar Marek Lindner

[batctl] a few code beautifications

parent e1c83d92
......@@ -128,7 +128,6 @@ static void parse_hosts_file(struct hashtable_t *hash, const char path[])
void bat_hosts_init(void)
{
unsigned int i;
#define CONF_DIR_LEN 256
char confdir[CONF_DIR_LEN];
char *homedir;
......@@ -143,6 +142,7 @@ void bat_hosts_init(void)
for (i = 0; i < sizeof(bat_hosts_path) / sizeof(char *); i++) {
strcpy(confdir, "");
if (strlen(bat_hosts_path[i]) >= 2
&& bat_hosts_path[i][0] == '~' && bat_hosts_path[i][1] == '/') {
strncpy(confdir, homedir, CONF_DIR_LEN);
......@@ -152,6 +152,7 @@ void bat_hosts_init(void)
strncpy(confdir, bat_hosts_path[i], CONF_DIR_LEN);
confdir[CONF_DIR_LEN - 1] = '\0';
}
parse_hosts_file(host_hash, confdir);
}
}
......
......@@ -25,6 +25,7 @@
#include <netinet/ether.h>
#define HOST_NAME_MAX_LEN 50
#define CONF_DIR_LEN 256
struct bat_host {
......
/* Copyright (C) 2007 B.A.T.M.A.N. contributors:
* Andreas Langer <a.langer@q-dsl.de>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
......@@ -23,22 +23,24 @@
#include "functions.h"
double time_diff( struct timeval *start, struct timeval *end ) {
unsigned long sec = (unsigned long) end->tv_sec - start->tv_sec;
double time_diff(struct timeval *start, struct timeval *end)
{
unsigned long sec = (unsigned long)end->tv_sec - start->tv_sec;
unsigned long usec = (unsigned long)end->tv_usec - start->tv_usec;
if(sec > (unsigned long)end->tv_sec) {
if (sec > (unsigned long)end->tv_sec) {
sec += 1000000000UL;
--sec;
}
if(usec > (unsigned long)end->tv_usec) {
if (usec > (unsigned long)end->tv_usec) {
usec += 1000000000UL;
--usec;
}
if ( sec > 0 )
if (sec > 0)
usec = 1000000 * sec + usec;
return (double)usec/1000;
return (double)usec / 1000;
}
......@@ -65,7 +65,7 @@ int ping(int argc, char **argv)
{
struct icmp_packet icmp_packet_out, icmp_packet_in;
struct timeval start, end, tv;
struct ether_addr *dst_mac = NULL;
struct ether_addr *dst_mac = NULL;
struct bat_host *bat_host;
ssize_t read_len;
fd_set read_socket;
......@@ -194,28 +194,27 @@ int ping(int argc, char **argv)
goto sleep;
}
if (read_len == 0)
if ((unsigned int)read_len < sizeof(icmp_packet_in)) {
printf("Warning - dropping received packet as it is smaller than expected (%d): %d\n",
sizeof(icmp_packet_in), read_len);
goto sleep;
}
gettimeofday(&end, (struct timezone*)0);
if ((read_len == sizeof(icmp_packet_in)) && (icmp_packet_in.msg_type == ECHO_REPLY)) {
switch (icmp_packet_in.msg_type) {
case ECHO_REPLY:
gettimeofday(&end, (struct timezone*)0);
time_delta = time_diff(&start, &end);
printf("%d bytes from %s icmp_seq=%u ttl=%d time=%.2f ms\n",
read_len, dst_string, ntohs(icmp_packet_in.seqno),
icmp_packet_in.ttl, time_delta);
read_len, dst_string, ntohs(icmp_packet_in.seqno),
icmp_packet_in.ttl, time_delta);
if (time_delta < min || min == 0.0)
if ((time_delta < min) || (min == 0.0))
min = time_delta;
if (time_delta > max)
max = time_delta;
avg += time_delta;
packets_in++;
goto sleep;
}
switch(icmp_packet_in.msg_type) {
break;
case DESTINATION_UNREACHABLE:
printf("From %s icmp_seq=%u Destination Host Unreachable\n", dst_string, ntohs(icmp_packet_in.seqno));
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment