nfctool: sniffer: Change the sniffer hexdump prototype
authorSamuel Ortiz <sameo@linux.intel.com>
Thu, 2 May 2013 10:48:04 +0000 (12:48 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 2 May 2013 10:48:51 +0000 (12:48 +0200)
Take an indentation length instead of a generic prefix, as this is
what's only used anyway.

tools/nfctool/llcp-decode.c
tools/nfctool/snep-decode.c
tools/nfctool/sniffer.c
tools/nfctool/sniffer.h

index bb5dcfd..159c0b2 100644 (file)
@@ -406,7 +406,7 @@ static int llcp_print_i(struct sniffer_packet *packet)
        }
 
        sniffer_print_hexdump(stdout, packet->llcp.data,  packet->llcp.data_len,
-                               "  ", TRUE);
+                               2, TRUE);
 
        return 0;
 }
@@ -514,7 +514,7 @@ int llcp_print_pdu(guint8 *data, guint32 data_len, struct timeval *timestamp)
 
        default:
                sniffer_print_hexdump(stdout, packet.llcp.data,
-                                     packet.llcp.data_len, "  ", TRUE);
+                                     packet.llcp.data_len, 2, TRUE);
                break;
        }
 
index fd52a44..35a7d43 100644 (file)
@@ -129,7 +129,7 @@ static int snep_frag_append(struct snep_frag *frag,
                snep_printf("End of fragmented message\n");
 
                sniffer_print_hexdump(stdout, frag->buffer, frag->buffer_size,
-                                     MSG_INDENT, TRUE);
+                                     6, TRUE);
 
                snep_frag_delete(frag->index);
        }
@@ -144,7 +144,7 @@ static int snep_decode_info(struct sniffer_packet *packet)
        if (packet->snep.data_len <= packet->snep.real_len) {
                /* Message is not fragmented */
                sniffer_print_hexdump(stdout, packet->snep.data,
-                                     packet->snep.data_len, MSG_INDENT, TRUE);
+                                     packet->snep.data_len, 6, TRUE);
 
                return 0;
        }
index 913ed27..8a6de03 100644 (file)
@@ -158,7 +158,7 @@ static void pcap_file_cleanup(void)
  *
  */
 void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
-                          gchar *line_prefix, gboolean print_len)
+                          guint8 indent, gboolean print_len)
 {
        guint8 digits;
        guint32 offset;
@@ -180,8 +180,8 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
                output_len = len;
 
        if (print_len) {
-               if (line_prefix)
-                       fprintf(file, "%s", line_prefix);
+               if (indent)
+                       fprintf(file, "%*c", indent, ' ');
 
                fprintf(file, "Total length: %u bytes\n", len);
        }
@@ -206,8 +206,8 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
                if (++digits >= 16) {
                        *hexa = ' ';
                        strcpy(human, "|");
-                       if (line_prefix)
-                               fprintf(file, "%s", line_prefix);
+                       if (indent)
+                               fprintf(file, "%*c", indent, ' ');
                        fprintf(file, "%s\n", line);
 
                        digits = 0;
@@ -219,14 +219,14 @@ void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
        if ((output_len & 0xF) != 0) {
                *hexa = ' ';
                strcpy(human, "|");
-               if (line_prefix)
-                       fprintf(file, "%s", line_prefix);
+               if (indent)
+                       fprintf(file, "%*c", indent, ' ');
                fprintf(file, "%s\n", line);
        }
 
        if (output_len != len) {
-               if (line_prefix)
-                       fprintf(file, "%s", line_prefix);
+               if (indent)
+                       fprintf(file, "%*c", indent, ' ');
                fprintf(file, "--- truncated ---\n");
        }
 }
index 6aa5ca5..9fdafe8 100644 (file)
@@ -60,6 +60,6 @@ int sniffer_init(void);
 void sniffer_cleanup(void);
 
 void sniffer_print_hexdump(FILE *file, guint8 *data, guint32 len,
-                          gchar *line_prefix, gboolean print_len);
+                          guint8 indent, gboolean print_len);
 
 #endif /* __SNIFFER_H */