Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de --- batctl/tcpdump.c | 4 ++-- batctl/traceroute.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/batctl/tcpdump.c b/batctl/tcpdump.c index 0f62e65..8898cf8 100644 --- a/batctl/tcpdump.c +++ b/batctl/tcpdump.c @@ -335,7 +335,7 @@ static void dump_batman_ucast(unsigned char *packet_buff, ssize_t buff_len, int printf("BAT %s > ", get_name_by_macaddr((struct ether_addr *)ether_header->ether_shost, read_opt));
- printf("%s: UCAST, ttl %hu, ", + printf("%s: UCAST, ttl %hhu, ", get_name_by_macaddr((struct ether_addr *)unicast_packet->dest, read_opt), unicast_packet->ttl);
@@ -388,7 +388,7 @@ static void dump_batman_frag(unsigned char *packet_buff, ssize_t buff_len, int r printf("BAT %s > ", get_name_by_macaddr((struct ether_addr *)unicast_frag_packet->orig, read_opt));
- printf("%s: FRAG, seq %hu, ttl %hu, flags [%c], ", + printf("%s: FRAG, seq %hu, ttl %hhu, flags [%c], ", get_name_by_macaddr((struct ether_addr *)unicast_frag_packet->dest, read_opt), ntohs(unicast_frag_packet->seqno), unicast_frag_packet->ttl, (unicast_frag_packet->flags & UNI_FRAG_HEAD ? 'H' : '.')); diff --git a/batctl/traceroute.c b/batctl/traceroute.c index dc97a01..0dc796a 100644 --- a/batctl/traceroute.c +++ b/batctl/traceroute.c @@ -199,9 +199,9 @@ int traceroute(char *mesh_iface, int argc, char **argv) }
if (!bat_host) - printf("%2hu: %s", icmp_packet_out.ttl, (return_mac ? return_mac : "*")); + printf("%2hhu: %s", icmp_packet_out.ttl, (return_mac ? return_mac : "*")); else - printf("%2hu: %s (%s)", icmp_packet_out.ttl, bat_host->name, return_mac); + printf("%2hhu: %s (%s)", icmp_packet_out.ttl, bat_host->name, return_mac);
for (i = 0; i < NUM_PACKETS; i++) { if (time_delta[i])
The time_delta array is only initialised when no error occurs or only the select fails. This means that we may print uninitialised or output from previous ttl levels.
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de --- batctl/traceroute.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/batctl/traceroute.c b/batctl/traceroute.c index 0dc796a..f80ca4d 100644 --- a/batctl/traceroute.c +++ b/batctl/traceroute.c @@ -135,6 +135,7 @@ int traceroute(char *mesh_iface, int argc, char **argv)
for (i = 0; i < NUM_PACKETS; i++) { icmp_packet_out.seqno = htons(++seq_counter); + time_delta[i] = 0.0;
if (write(trace_fd, (char *)&icmp_packet_out, sizeof(icmp_packet_out)) < 0) { printf("Error - can't write to batman adv kernel file '%s': %s\n", icmp_socket, strerror(errno)); @@ -151,10 +152,8 @@ int traceroute(char *mesh_iface, int argc, char **argv)
res = select(trace_fd + 1, &read_socket, NULL, NULL, &tv);
- if (res <= 0) { - time_delta[i] = 0.0; + if (res <= 0) continue; - }
read_len = read(trace_fd, (char *)&icmp_packet_in, sizeof(icmp_packet_in));
Different variables aren't used after they are set. We can discard them without changing the behavior visible to the outside.
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de --- batctl/functions.c | 3 +-- batctl/tcpdump.c | 32 ++++++++------------------------ batctl/vis.c | 3 +-- 3 files changed, 10 insertions(+), 28 deletions(-)
diff --git a/batctl/functions.c b/batctl/functions.c index cff8b52..ce046ba 100644 --- a/batctl/functions.c +++ b/batctl/functions.c @@ -126,7 +126,6 @@ int read_file(char *dir, char *fname, int read_opt, float last_seen; char full_path[500], *buff_ptr, *space_ptr, extra_char; size_t len = 0; - ssize_t read; FILE *fp = NULL;
if (read_opt & USE_BAT_HOSTS) @@ -154,7 +153,7 @@ open: system("clear");
read: - while ((read = getline(&line_ptr, &len, fp)) != -1) { + while (getline(&line_ptr, &len, fp) != -1) { /* the buffer will be handled elsewhere */ if (read_opt & USE_READ_BUFF) break; diff --git a/batctl/tcpdump.c b/batctl/tcpdump.c index 8898cf8..ed11f22 100644 --- a/batctl/tcpdump.c +++ b/batctl/tcpdump.c @@ -84,15 +84,12 @@ static int print_time(void) return 1; }
-static void dump_arp(unsigned char *packet_buff, ssize_t buff_len, int time_printed) +static void dump_arp(unsigned char *packet_buff, ssize_t buff_len) { struct ether_arp *arphdr;
LEN_CHECK((size_t)buff_len, sizeof(struct ether_arp), "ARP");
- if (!time_printed) - time_printed = print_time(); - arphdr = (struct ether_arp *)packet_buff;
switch (ntohs(arphdr->arp_op)) { @@ -111,7 +108,7 @@ static void dump_arp(unsigned char *packet_buff, ssize_t buff_len, int time_prin } }
-static void dump_ip(unsigned char *packet_buff, ssize_t buff_len, int time_printed) +static void dump_ip(unsigned char *packet_buff, ssize_t buff_len) { struct iphdr *iphdr, *tmp_iphdr; struct tcphdr *tcphdr; @@ -121,9 +118,6 @@ static void dump_ip(unsigned char *packet_buff, ssize_t buff_len, int time_print iphdr = (struct iphdr *)packet_buff; LEN_CHECK((size_t)buff_len, (size_t)(iphdr->ihl * 4), "IP");
- if (!time_printed) - time_printed = print_time(); - switch (iphdr->protocol) { case IPPROTO_ICMP: LEN_CHECK((size_t)buff_len - (iphdr->ihl * 4), sizeof(struct icmphdr), "ICMP"); @@ -246,7 +240,7 @@ static void dump_vlan(unsigned char *packet_buff, ssize_t buff_len, int read_opt parse_eth_hdr(packet_buff + 4, buff_len - 4, read_opt, time_printed); }
-static void dump_batman_ogm(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed) +static void dump_batman_ogm(unsigned char *packet_buff, ssize_t buff_len, int read_opt) { struct ether_header *ether_header; struct batman_packet *batman_packet; @@ -256,9 +250,6 @@ static void dump_batman_ogm(unsigned char *packet_buff, ssize_t buff_len, int re ether_header = (struct ether_header *)packet_buff; batman_packet = (struct batman_packet *)(packet_buff + sizeof(struct ether_header));
- if (!time_printed) - time_printed = print_time(); - printf("BAT %s: ", get_name_by_macaddr((struct ether_addr *)batman_packet->orig, read_opt));
@@ -273,20 +264,15 @@ static void dump_batman_ogm(unsigned char *packet_buff, ssize_t buff_len, int re (size_t)buff_len - sizeof(struct ether_header)); }
-static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed) +static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int read_opt) { - struct ether_header *ether_header; struct icmp_packet *icmp_packet; char *name;
LEN_CHECK((size_t)buff_len - sizeof(struct ether_header), sizeof(struct icmp_packet), "BAT ICMP");
- ether_header = (struct ether_header *)packet_buff; icmp_packet = (struct icmp_packet *)(packet_buff + sizeof(struct ether_header));
- if (!time_printed) - time_printed = print_time(); - printf("BAT %s > ", get_name_by_macaddr((struct ether_addr *)icmp_packet->orig, read_opt));
name = get_name_by_macaddr((struct ether_addr *)icmp_packet->dst, read_opt); @@ -373,13 +359,11 @@ static void dump_batman_bcast(unsigned char *packet_buff, ssize_t buff_len, int
static void dump_batman_frag(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed) { - struct ether_header *ether_header; struct unicast_frag_packet *unicast_frag_packet;
LEN_CHECK((size_t)buff_len - ETH_HLEN, sizeof(struct unicast_frag_packet), "BAT FRAG"); LEN_CHECK((size_t)buff_len - ETH_HLEN - sizeof(struct unicast_frag_packet), (size_t)ETH_HLEN, "BAT FRAG (unpacked)");
- ether_header = (struct ether_header *)packet_buff; unicast_frag_packet = (struct unicast_frag_packet *)(packet_buff + ETH_HLEN);
if (!time_printed) @@ -411,11 +395,11 @@ static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len, int read switch (ntohs(eth_hdr->ether_type)) { case ETH_P_ARP: if ((dump_level & DUMP_TYPE_NONBAT) || (time_printed)) - dump_arp(packet_buff + ETH_HLEN, buff_len - ETH_HLEN, time_printed); + dump_arp(packet_buff + ETH_HLEN, buff_len - ETH_HLEN); break; case ETH_P_IP: if ((dump_level & DUMP_TYPE_NONBAT) || (time_printed)) - dump_ip(packet_buff + ETH_HLEN, buff_len - ETH_HLEN, time_printed); + dump_ip(packet_buff + ETH_HLEN, buff_len - ETH_HLEN); break; case ETH_P_8021Q: if ((dump_level & DUMP_TYPE_NONBAT) || (time_printed)) @@ -427,11 +411,11 @@ static void parse_eth_hdr(unsigned char *packet_buff, ssize_t buff_len, int read switch (batman_packet->packet_type) { case BAT_PACKET: if (dump_level & DUMP_TYPE_BATOGM) - dump_batman_ogm(packet_buff, buff_len, read_opt, time_printed); + dump_batman_ogm(packet_buff, buff_len, read_opt); break; case BAT_ICMP: if (dump_level & DUMP_TYPE_BATICMP) - dump_batman_icmp(packet_buff, buff_len, read_opt, time_printed); + dump_batman_icmp(packet_buff, buff_len, read_opt); break; case BAT_UNICAST: if (dump_level & DUMP_TYPE_BATUCAST) diff --git a/batctl/vis.c b/batctl/vis.c index ad612ff..4bc5954 100644 --- a/batctl/vis.c +++ b/batctl/vis.c @@ -183,7 +183,6 @@ static FILE *open_vis(char *mesh_iface) static int format(char *mesh_iface, const struct funcs *funcs) { size_t len = 0; - ssize_t read; char *line = NULL; char *orig, *from; char *duplet; @@ -202,7 +201,7 @@ static int format(char *mesh_iface, const struct funcs *funcs) if (funcs->print_header) funcs->print_header();
- while ((read = getline(&line, &len, fp)) != -1) { + while (getline(&line, &len, fp) != -1) { /* First MAC address is the originator */ orig = strtok_r(line, ",", &line_save_ptr);
On Saturday 30 October 2010 17:00:55 Sven Eckelmann wrote:
-static void dump_arp(unsigned char *packet_buff, ssize_t buff_len, int time_printed) +static void dump_arp(unsigned char *packet_buff, ssize_t buff_len) { struct ether_arp *arphdr;
LEN_CHECK((size_t)buff_len, sizeof(struct ether_arp), "ARP");
if (!time_printed)
time_printed = print_time();
arphdr = (struct ether_arp *)packet_buff; switch (ntohs(arphdr->arp_op)) {
@@ -111,7 +108,7 @@ static void dump_arp(unsigned char *packet_buff, ssize_t buff_len, int time_prin } }
I don't understand why you want to remove the time_printed stuff. Maybe it is not so clear what this is good for ? At the beginning of each line batctl tcpdump prints a timestamp by caling print_time(). The various functions to analyze the headers (e.g. ARP) can be called under different conditions: Either after the encapsulating batman-adv header had been printed (including the timestamp) or without any prior prints in which case we want to output the timestamp.
Regards, Marek
Marek Lindner wrote:
On Saturday 30 October 2010 17:00:55 Sven Eckelmann wrote:
-static void dump_arp(unsigned char *packet_buff, ssize_t buff_len, int time_printed) +static void dump_arp(unsigned char *packet_buff, ssize_t buff_len) {
struct ether_arp *arphdr; LEN_CHECK((size_t)buff_len, sizeof(struct ether_arp), "ARP");
if (!time_printed)
time_printed = print_time();
arphdr = (struct ether_arp *)packet_buff; switch (ntohs(arphdr->arp_op)) {
@@ -111,7 +108,7 @@ static void dump_arp(unsigned char *packet_buff, ssize_t buff_len, int time_prin }
}
I don't understand why you want to remove the time_printed stuff. Maybe it is not so clear what this is good for ? At the beginning of each line batctl tcpdump prints a timestamp by caling print_time(). The various functions to analyze the headers (e.g. ARP) can be called under different conditions: Either after the encapsulating batman-adv header had been printed (including the timestamp) or without any prior prints in which case we want to output the timestamp.
It is not used anywhere in the functions - so why keep it?
Best regards, Sven
Different variables aren't used after they are set. We can discard them without changing the behavior visible to the outside.
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de --- batctl/functions.c | 3 +-- batctl/tcpdump.c | 12 ++++-------- batctl/vis.c | 3 +-- 3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/batctl/functions.c b/batctl/functions.c index cff8b52..ce046ba 100644 --- a/batctl/functions.c +++ b/batctl/functions.c @@ -126,7 +126,6 @@ int read_file(char *dir, char *fname, int read_opt, float last_seen; char full_path[500], *buff_ptr, *space_ptr, extra_char; size_t len = 0; - ssize_t read; FILE *fp = NULL;
if (read_opt & USE_BAT_HOSTS) @@ -154,7 +153,7 @@ open: system("clear");
read: - while ((read = getline(&line_ptr, &len, fp)) != -1) { + while (getline(&line_ptr, &len, fp) != -1) { /* the buffer will be handled elsewhere */ if (read_opt & USE_READ_BUFF) break; diff --git a/batctl/tcpdump.c b/batctl/tcpdump.c index 8898cf8..08a662a 100644 --- a/batctl/tcpdump.c +++ b/batctl/tcpdump.c @@ -91,7 +91,7 @@ static void dump_arp(unsigned char *packet_buff, ssize_t buff_len, int time_prin LEN_CHECK((size_t)buff_len, sizeof(struct ether_arp), "ARP");
if (!time_printed) - time_printed = print_time(); + print_time();
arphdr = (struct ether_arp *)packet_buff;
@@ -122,7 +122,7 @@ static void dump_ip(unsigned char *packet_buff, ssize_t buff_len, int time_print LEN_CHECK((size_t)buff_len, (size_t)(iphdr->ihl * 4), "IP");
if (!time_printed) - time_printed = print_time(); + print_time();
switch (iphdr->protocol) { case IPPROTO_ICMP: @@ -257,7 +257,7 @@ static void dump_batman_ogm(unsigned char *packet_buff, ssize_t buff_len, int re batman_packet = (struct batman_packet *)(packet_buff + sizeof(struct ether_header));
if (!time_printed) - time_printed = print_time(); + print_time();
printf("BAT %s: ", get_name_by_macaddr((struct ether_addr *)batman_packet->orig, read_opt)); @@ -275,17 +275,15 @@ static void dump_batman_ogm(unsigned char *packet_buff, ssize_t buff_len, int re
static void dump_batman_icmp(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed) { - struct ether_header *ether_header; struct icmp_packet *icmp_packet; char *name;
LEN_CHECK((size_t)buff_len - sizeof(struct ether_header), sizeof(struct icmp_packet), "BAT ICMP");
- ether_header = (struct ether_header *)packet_buff; icmp_packet = (struct icmp_packet *)(packet_buff + sizeof(struct ether_header));
if (!time_printed) - time_printed = print_time(); + print_time();
printf("BAT %s > ", get_name_by_macaddr((struct ether_addr *)icmp_packet->orig, read_opt));
@@ -373,13 +371,11 @@ static void dump_batman_bcast(unsigned char *packet_buff, ssize_t buff_len, int
static void dump_batman_frag(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed) { - struct ether_header *ether_header; struct unicast_frag_packet *unicast_frag_packet;
LEN_CHECK((size_t)buff_len - ETH_HLEN, sizeof(struct unicast_frag_packet), "BAT FRAG"); LEN_CHECK((size_t)buff_len - ETH_HLEN - sizeof(struct unicast_frag_packet), (size_t)ETH_HLEN, "BAT FRAG (unpacked)");
- ether_header = (struct ether_header *)packet_buff; unicast_frag_packet = (struct unicast_frag_packet *)(packet_buff + ETH_HLEN);
if (!time_printed) diff --git a/batctl/vis.c b/batctl/vis.c index ad612ff..4bc5954 100644 --- a/batctl/vis.c +++ b/batctl/vis.c @@ -183,7 +183,6 @@ static FILE *open_vis(char *mesh_iface) static int format(char *mesh_iface, const struct funcs *funcs) { size_t len = 0; - ssize_t read; char *line = NULL; char *orig, *from; char *duplet; @@ -202,7 +201,7 @@ static int format(char *mesh_iface, const struct funcs *funcs) if (funcs->print_header) funcs->print_header();
- while ((read = getline(&line, &len, fp)) != -1) { + while (getline(&line, &len, fp) != -1) { /* First MAC address is the originator */ orig = strtok_r(line, ",", &line_save_ptr);
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de --- This patch is useless if we also add "batctl: Readd ping interval after each loop"
batctl/ping.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/batctl/ping.c b/batctl/ping.c index 288bd01..1ed8fac 100644 --- a/batctl/ping.c +++ b/batctl/ping.c @@ -180,6 +180,9 @@ int ping(char *mesh_iface, int argc, char **argv) packet_len, packet_len + 28);
while (!is_aborted) { + tv.tv_sec = timeout; + tv.tv_usec = 0; + if (loop_count == 0) break;
@@ -195,9 +198,6 @@ int ping(char *mesh_iface, int argc, char **argv)
start_timer();
- tv.tv_sec = timeout; - tv.tv_usec = 0; - FD_ZERO(&read_socket); FD_SET(ping_fd, &read_socket);
The option -i for ping had no visible effect. We can simply change it back to the old behaviour from battool times.
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de --- batctl/ping.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/batctl/ping.c b/batctl/ping.c index 1ed8fac..9963b24 100644 --- a/batctl/ping.c +++ b/batctl/ping.c @@ -292,9 +292,8 @@ int ping(char *mesh_iface, int argc, char **argv) }
sleep: - if ((tv.tv_sec != 0) || (tv.tv_usec != 0)) - select(0, NULL, NULL, NULL, &tv); - + if (loop_interval > 0) + sleep(loop_interval); }
if (packets_out == 0)
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de --- batctl/bisect.c | 10 +++++----- batctl/vis.c | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/batctl/bisect.c b/batctl/bisect.c index 2fa15f0..b7d8969 100644 --- a/batctl/bisect.c +++ b/batctl/bisect.c @@ -466,7 +466,7 @@ err: static int parse_log_file(char *file_path) { FILE *fd; - char line_buff[MAX_LINE], *start_ptr, *tok_ptr; + char line_buff[MAX_LINE], *start_ptr, *start_ptr_safe, *tok_ptr; char *neigh, *iface_addr, *orig, *prev_sender, rt_flag; int line_count = 0, tq, ttl, seqno, i, res, max;
@@ -483,12 +483,12 @@ static int parse_log_file(char *file_path) line_count++;
if (strstr(start_ptr, "Received BATMAN packet via NB")) { - tok_ptr = strtok(start_ptr, " "); + strtok_r(start_ptr, " ", &start_ptr_safe); neigh = iface_addr = orig = prev_sender = NULL; seqno = tq = ttl = -1;
for (i = 0; i < 21; i++) { - tok_ptr = strtok(NULL, " "); + tok_ptr = strtok_r(NULL, " ", &start_ptr_safe); if (!tok_ptr) break;
@@ -547,11 +547,11 @@ static int parse_log_file(char *file_path) max = 3; }
- tok_ptr = strtok(start_ptr, " "); + strtok_r(start_ptr, " ", &start_ptr_safe); orig = neigh = prev_sender = NULL;
for (i = 0; i < max; i++) { - tok_ptr = strtok(NULL, " "); + tok_ptr = strtok_r(NULL, " ", &start_ptr_safe); if (!tok_ptr) break;
diff --git a/batctl/vis.c b/batctl/vis.c index 4bc5954..7fba1ab 100644 --- a/batctl/vis.c +++ b/batctl/vis.c @@ -186,7 +186,7 @@ static int format(char *mesh_iface, const struct funcs *funcs) char *line = NULL; char *orig, *from; char *duplet; - char *line_save_ptr; + char *line_save_ptr, *component_save_ptr; char *duplet_save_ptr; char *endptr; char *value; @@ -207,12 +207,12 @@ static int format(char *mesh_iface, const struct funcs *funcs)
duplet_save_ptr = line_save_ptr; while ((duplet = strtok_r(NULL, ",", &duplet_save_ptr)) != NULL) { - flag = strtok(duplet, " "); + flag = strtok_r(duplet, " ", &component_save_ptr); if (!flag) continue; if (!strcmp(flag, "TQ")) { - from = strtok(NULL, " "); - value = strtok(NULL, " "); + from = strtok_r(NULL, " ", &component_save_ptr); + value = strtok_r(NULL, " ", &component_save_ptr); tq = strtoul(value, &endptr, 0); funcs->print_tq(orig, from, tq); continue; @@ -221,13 +221,13 @@ static int format(char *mesh_iface, const struct funcs *funcs) /* We have an HNA record */ if (!with_HNA) continue; - from = strtok(NULL, " "); + from = strtok_r(NULL, " ", &component_save_ptr); funcs->print_HNA(orig, from); continue; } if (!strcmp(flag, "SEC") && with_2nd) { /* We found a secondary interface MAC address. */ - from = strtok(NULL, " "); + from = strtok_r(NULL, " ", &component_save_ptr); funcs->print_2nd(orig, from); } if (!strcmp(flag, "PRIMARY") && with_2nd) {
On Saturday 30 October 2010 17:00:53 Sven Eckelmann wrote:
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de
batctl/tcpdump.c | 4 ++-- batctl/traceroute.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
All patches have been applied (revision 1858-1863). I slightly modified patch 5 to keep the current behavior if no loop interval was specified.
Thanks, Marek
b.a.t.m.a.n@lists.open-mesh.org