batctl: tcpdump - cleanup tt_query packet parser

Message ID 1308061362-28727-1-git-send-email-lindner_marek@yahoo.de
State Accepted, archived
Commit 5e42d990f203fdb11e7409cb04b6be4fd9d64a09
Headers

Commit Message

Marek Lindner June 14, 2011, 2:22 p.m. UTC
  Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 tcpdump.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)
  

Comments

Marek Lindner June 15, 2011, 6:41 p.m. UTC | #1
On Tuesday, June 14, 2011 04:22:42 PM Marek Lindner wrote:
> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
> ---
>  tcpdump.c |   30 +++++++++++++++++++++++-------
>  1 files changed, 23 insertions(+), 7 deletions(-)

Applied in revision 5e42d99.

Regards,
Marek
  

Patch

diff --git a/tcpdump.c b/tcpdump.c
index 4e09274..5500899 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -254,6 +254,7 @@  static void dump_vlan(unsigned char *packet_buff, ssize_t buff_len, int read_opt
 static void dump_batman_tt(unsigned char *packet_buff, ssize_t buff_len, int read_opt, int time_printed)
 {
 	struct tt_query_packet *tt_query_packet;
+	char *tt_desc, *tt_data, tt_type;
 
 	LEN_CHECK((size_t)buff_len - sizeof(struct ether_header), sizeof(struct tt_query_packet), "BAT TT");
 
@@ -262,17 +263,32 @@  static void dump_batman_tt(unsigned char *packet_buff, ssize_t buff_len, int rea
 	if (!time_printed)
 		print_time();
 
+	switch (tt_query_packet->flags & TT_QUERY_TYPE_MASK) {
+	case TT_REQUEST:
+		tt_desc = "request";
+		tt_data = "crc";
+		tt_type = 'Q';
+		break;
+	case TT_RESPONSE:
+		tt_desc = "response";
+		tt_data = "entries";
+		tt_type = 'P';
+		break;
+	default:
+		tt_desc = "unknown";
+		tt_data = "unknown";
+		tt_type = '?';
+		break;
+	}
+
 	printf("BAT %s > ",
 	       get_name_by_macaddr((struct ether_addr *)tt_query_packet->src, read_opt));
 
-	printf("%s: TT %s, ttvn %d, %s %d, ttl %2d, v %d, flags [%c%c%c], length %zu\n",
+	printf("%s: TT %s, ttvn %d, %s %d, ttl %2d, v %d, flags [%c%c], length %zu\n",
 	       get_name_by_macaddr((struct ether_addr *)tt_query_packet->dst, read_opt),
-	       tt_query_packet->flags & TT_RESPONSE ? "response" : "request",
-	       tt_query_packet->ttvn, tt_query_packet->flags & TT_RESPONSE ? "entries" : "crc",
-	       ntohs(tt_query_packet->tt_data), tt_query_packet->ttl, tt_query_packet->version,
-	       (tt_query_packet->flags & TT_REQUEST ? 'Q' : '.'),
-	       (tt_query_packet->flags & TT_RESPONSE ? 'P' : '.'),
-	       (tt_query_packet->flags & TT_FULL_TABLE ? 'F' : '.'),
+	       tt_desc, tt_query_packet->ttvn, tt_data, ntohs(tt_query_packet->tt_data),
+	       tt_query_packet->ttl, tt_query_packet->version,
+	       tt_type, (tt_query_packet->flags & TT_FULL_TABLE ? 'F' : '.'),
 	       (size_t)buff_len - sizeof(struct ether_header));
 }