--- trunk/darkstattype.c 2014/03/19 08:51:24 4 +++ trunk/darkstattype.c 2014/03/19 14:02:41 6 @@ -36,8 +36,8 @@ #include #include -const char * progname = NULL; -const char * filename = NULL; +const char *progname = NULL; +const char *filename = NULL; FILE *file = NULL; int main(int argc, char **argv) @@ -164,8 +164,10 @@ void decode_file(void) exit(EXIT_FAILURE); } // if - if ( (fileheader = read32u()) != 0xDA314159U) { // not darkstat export format - fprintf(stderr, "%s:%s: file header = 0x%x, not 0x%x\n", progname, filename, fileheader, 0xDA314159U); +#define FILE_HEADER_V1 0xDA314159U + + if ( (fileheader = read32u()) != FILE_HEADER_V1) { // not darkstat export format + fprintf(stderr, "%s:%s: file header = 0x%x, not 0x%x\n", progname, filename, fileheader, FILE_HEADER_V1); exit(EXIT_FAILURE); } // if @@ -174,19 +176,22 @@ void decode_file(void) // Possible section header for host_db v1 and later graph_db v1. indent(); +#define HOST_DB_V1 0xDA485301U +#define GRAPH_DB_V1 0xDA475201U + for (i = 0; i < 2; i++) { - if ( (sectionheader = read32u()) == 0xDA485301U) { + if ( (sectionheader = read32u()) == HOST_DB_V1) { print_indentation(); - printf("Section header 0x%x\n", sectionheader); + printf("Section header host_db v1 0x%x\n", sectionheader); decode_host_db_v1(); } // if - else if (sectionheader == 0xDA475201U) { + else if (sectionheader == GRAPH_DB_V1) { print_indentation(); - printf("Section header 0x%x\n", sectionheader); + printf("Section header graph_db v1 0x%x\n", sectionheader); decode_graph_db_v1(); } // else if else { - fprintf(stderr, "%s:%s: unknown section header = 0x%x, neither 0x%x nor 0x%x\n", progname, filename, sectionheader, 0xDA485301U, 0xDA475201U); + fprintf(stderr, "%s:%s: unknown section header = 0x%x, neither 0x%x nor 0x%x\n", progname, filename, sectionheader, HOST_DB_V1, GRAPH_DB_V1); exit(EXIT_FAILURE); } // else } // for @@ -218,23 +223,27 @@ void decode_host_db_v1(void) indent(); - if ( (hostheader = read32u()) == 0x48535403U) { // host header v3 +#define HOST_HEADER_V3 0x48535403U +#define HOST_HEADER_V2 0x48535402U +#define HOST_HEADER_V1 0x48535401U + + if ( (hostheader = read32u()) == HOST_HEADER_V3) { // host header v3 print_indentation(); printf("Host header v3 0x%x\n", hostheader); decode_host_header_v3(); } // if - else if (hostheader == 0x48535402U) { // host header v2 + else if (hostheader == HOST_HEADER_V2) { // host header v2 print_indentation(); printf("Host header v2 0x%x\n", hostheader); decode_host_header_v2(); } // else if - else if (hostheader == 0x48535401U) { // host header v1 + else if (hostheader == HOST_HEADER_V1) { // host header v1 print_indentation(); printf("Host header v1 0x%x\n", hostheader); decode_host_header_v1(); } // else if else { // unknown host header version - fprintf(stderr, "%s:%s: unknown host header = 0x%x, neither 0x%x nor 0x%x nor 0x%x\n", progname, filename, hostheader, 0x48535403U, 0x48535402U, 0x48535401U); + fprintf(stderr, "%s:%s: unknown host header = 0x%x, neither 0x%x nor 0x%x nor 0x%x\n", progname, filename, hostheader, HOST_HEADER_V3, HOST_HEADER_V2, HOST_HEADER_V1); exit(EXIT_FAILURE); } // else @@ -369,7 +378,7 @@ void decode_host_header_v2(void) lastseen = read64s(); print_indentation(); - printf("Last seen %ld = ", lastseen); + printf("Last seen 0x%lx = %ld = ", lastseen, lastseen); print_time_t(lastseen); puts(""); @@ -510,7 +519,7 @@ void decode_host_header_v3(void) lastseen = read64s(); print_indentation(); - printf("Last seen %ld = ", lastseen); + printf("Last seen 0x%lx = %ld = ", lastseen, lastseen); print_time_t(lastseen); puts(""); @@ -586,7 +595,7 @@ void decode_protos_data(void) indent(); print_indentation(); - printf("Protocol 0x%x\n", proto); + printf("Protocol 0x%02x\n", proto); in = read64u(); @@ -700,7 +709,7 @@ void decode_graph_db_v1(void) indent(); print_indentation(); - printf("Last time %ld = ", lasttime); + printf("Last time 0x%lx = %ld = ", lasttime, lasttime); print_time_t(lasttime); puts("");