--- trunk/darkstattype.c 2014/03/20 09:49:12 9 +++ trunk/darkstattype.c 2014/03/21 15:40:57 10 @@ -178,7 +178,7 @@ void decode_file(void) #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); + fprintf(stderr, "%s:%s:%ld: file header = 0x%x, not 0x%x\n", progname, filename, ftell(file), fileheader, FILE_HEADER_V1); exit(EXIT_FAILURE); } // if @@ -202,7 +202,7 @@ void decode_file(void) 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, HOST_DB_V1, GRAPH_DB_V1); + fprintf(stderr, "%s:%s:%ld: unknown section header = 0x%x, neither 0x%x nor 0x%x\n", progname, filename, ftell(file), sectionheader, HOST_DB_V1, GRAPH_DB_V1); exit(EXIT_FAILURE); } // else } // for @@ -254,7 +254,7 @@ void decode_host_db_v1(void) 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, HOST_HEADER_V3, HOST_HEADER_V2, HOST_HEADER_V1); + fprintf(stderr, "%s:%s:%ld: unknown host header = 0x%x, neither 0x%x nor 0x%x nor 0x%x\n", progname, filename, ftell(file), hostheader, HOST_HEADER_V3, HOST_HEADER_V2, HOST_HEADER_V1); exit(EXIT_FAILURE); } // else @@ -327,21 +327,21 @@ void decode_host_header_v1(void) printf("Bytes out %lu\n", bytesout); if ( (protosdata = read8u()) != 'P') { // missing protos data - fprintf(stderr, "%s: expecting character P, not %c\n", progname, protosdata); + fprintf(stderr, "%s:%s:%ld: expecting character P, not %c\n", progname, filename, ftell(file), protosdata); exit(EXIT_FAILURE); } // if decode_protos_data(); if ( (tcpdata = read8u()) != 'T') { // missing tcp data - fprintf(stderr, "%s: expecting character T, not %c\n", progname, tcpdata); + fprintf(stderr, "%s:%s:%ld: expecting character T, not %c\n", progname, filename, ftell(file), tcpdata); exit(EXIT_FAILURE); } // if decode_tcp_data(); if ( (udpdata = read8u()) != 'U') { // missing udp data - fprintf(stderr, "%s: expecting character U, not %c\n", progname, udpdata); + fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata); exit(EXIT_FAILURE); } // if @@ -437,21 +437,21 @@ void decode_host_header_v2(void) printf("Bytes out %lu\n", bytesout); if ( (protosdata = read8u()) != 'P') { // missing protos data - fprintf(stderr, "%s: expecting character P, not %c\n", progname, protosdata); + fprintf(stderr, "%s:%s:%ld: expecting character P, not %c\n", progname, filename, ftell(file), protosdata); exit(EXIT_FAILURE); } // if decode_protos_data(); if ( (tcpdata = read8u()) != 'T') { // missing tcp data - fprintf(stderr, "%s: expecting character T, not %c\n", progname, tcpdata); + fprintf(stderr, "%s:%s:%ld: expecting character T, not %c\n", progname, filename, ftell(file), tcpdata); exit(EXIT_FAILURE); } // if decode_tcp_data(); if ( (udpdata = read8u()) != 'U') { // missing udp data - fprintf(stderr, "%s: expecting character U, not %c\n", progname, udpdata); + fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata); exit(EXIT_FAILURE); } // if @@ -533,7 +533,7 @@ void decode_host_header_v3(void) ipv6address[15]); } // else if else { // unknown address family - fprintf(stderr, "%s:%s: unknown address family = 0x%x, neither 0x%x nor 0x%x\n", progname, filename, addressfamily, 0x04, 0x06); + fprintf(stderr, "%s:%s:%ld: unknown address family = 0x%x, neither 0x%x nor 0x%x\n", progname, filename, ftell(file), addressfamily, 0x04, 0x06); exit(EXIT_FAILURE); } // else @@ -598,21 +598,21 @@ void decode_host_header_v3(void) printf("Bytes out %lu\n", bytesout); if ( (protosdata = read8u()) != 'P') { // missing protos data - fprintf(stderr, "%s: expecting character P, not %c\n", progname, protosdata); + fprintf(stderr, "%s:%s:%ld: expecting character P, not %c\n", progname, filename, ftell(file), protosdata); exit(EXIT_FAILURE); } // if decode_protos_data(); if ( (tcpdata = read8u()) != 'T') { // missing tcp data - fprintf(stderr, "%s: expecting character T, not %c\n", progname, tcpdata); + fprintf(stderr, "%s:%s:%ld: expecting character T, not %c\n", progname, filename, ftell(file), tcpdata); exit(EXIT_FAILURE); } // if decode_tcp_data(); if ( (udpdata = read8u()) != 'U') { // missing udp data - fprintf(stderr, "%s: expecting character U, not %c\n", progname, udpdata); + fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata); exit(EXIT_FAILURE); } // if @@ -973,13 +973,15 @@ void handle_file_error(void) void handle_file_error(void) { + int saved_errno = errno; + if (feof(file) != 0) { - fprintf(stderr, "%s:%s: premature end-of-file\n", progname, filename); + fprintf(stderr, "%s:%s:%ld: premature end-of-file\n", progname, filename, ftell(file)); exit(EXIT_FAILURE); } // if if (ferror(file) != 0) { - fprintf(stderr, "%s:%s: file error, errno = %s (%d)\n", progname, filename, strerror(errno), errno); + fprintf(stderr, "%s:%s:%ld: file error, errno = %s (%d)\n", progname, filename, ftell(file), strerror(saved_errno), saved_errno); exit(EXIT_FAILURE); } // if } // handle_file_error() @@ -1018,7 +1020,9 @@ void print_time_t(time_t t) // ISO 8601 format if (strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S%z", stm) == 0) { - fprintf(stderr, "%s:%s: strftime() error, errno = %s (%d)\n", progname, filename, strerror(errno), errno); + int saved_errno = errno; + + fprintf(stderr, "%s:%s:%ld: strftime() error, errno = %s (%d)\n", progname, filename, ftell(file), strerror(saved_errno), saved_errno); exit(EXIT_FAILURE); } // if