| 1 |
/* -*- coding: utf-8 -*- |
/* -*- coding: utf-8 -*- |
| 2 |
darkstattype.c - Program to decode darkstat's dumpfile. |
darkstattype.c - Program to decode darkstat's dumpfile. |
| 3 |
|
|
| 4 |
$Ximalas$ |
$Ximalas$ |
| 5 |
|
|
| 6 |
Tested on FreeBSD/amd64 stable/9 r263290 with clang 3.3. |
Tested on FreeBSD/i386 stable/8 r255624 with gcc 4.2.1. |
| 7 |
|
Tested on FreeBSD/amd64 stable/9 r263963 with clang 3.3. |
| 8 |
|
Tested on FreeBSD/amd64 stable/9 r263963 with clang 3.3 using -m32. |
| 9 |
|
|
| 10 |
Copyright © 2014, Trond Endrestøl <Trond.Endrestol@ximalas.info> |
Copyright © 2014, Trond Endrestøl <Trond.Endrestol@ximalas.info> |
| 11 |
All rights reserved. |
All rights reserved. |
| 12 |
|
|
| 13 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 14 |
modification, are permitted provided that the following conditions are met: |
modification, are permitted provided that the following conditions are met: |
| 15 |
|
|
| 16 |
1. Redistributions of source code must retain the above copyright notice, this |
1. Redistributions of source code must retain the above copyright notice, this |
| 17 |
list of conditions and the following disclaimer. |
list of conditions and the following disclaimer. |
| 18 |
2. Redistributions in binary form must reproduce the above copyright notice, |
2. Redistributions in binary form must reproduce the above copyright notice, |
| 19 |
this list of conditions and the following disclaimer in the documentation |
this list of conditions and the following disclaimer in the documentation |
| 20 |
and/or other materials provided with the distribution. |
and/or other materials provided with the distribution. |
| 21 |
|
|
| 22 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 23 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 61 |
case 'f': |
case 'f': |
| 62 |
follow_specification = !follow_specification; |
follow_specification = !follow_specification; |
| 63 |
break; |
break; |
| 64 |
|
|
| 65 |
case 'h': |
case 'h': |
| 66 |
show_usage(EXIT_SUCCESS); |
show_usage(EXIT_SUCCESS); |
| 67 |
break; |
break; |
| 68 |
|
|
| 69 |
case 'v': |
case 'v': |
| 70 |
show_version(); |
show_version(); |
| 71 |
break; |
break; |
| 72 |
|
|
| 73 |
case '?': |
case '?': |
| 74 |
/*FALLTHROUGH*/ |
/*FALLTHROUGH*/ |
| 75 |
default: |
default: |
| 76 |
fprintf(stderr, "%s: illegal option -%c\n\n", progname, optopt); |
fprintf(stderr, "%s: illegal option -%c\n\n", |
| 77 |
|
progname, optopt); |
| 78 |
show_usage(EXIT_FAILURE); |
show_usage(EXIT_FAILURE); |
| 79 |
break; |
break; |
| 80 |
} // switch |
} // switch |
| 81 |
} // while |
} // while |
| 82 |
argc -= optind; |
argc -= optind; |
| 83 |
argv += optind; |
argv += optind; |
| 84 |
|
|
| 85 |
if (*argv == NULL) { |
if (*argv == NULL) { |
| 86 |
fprintf(stderr, "%s: missing filename\n\n", progname); |
fprintf(stderr, "%s: missing filename\n\n", |
| 87 |
|
progname); |
| 88 |
show_usage(EXIT_FAILURE); |
show_usage(EXIT_FAILURE); |
| 89 |
} // if |
} // if |
| 90 |
|
|
| 91 |
while (*argv != NULL) { |
while (*argv != NULL) { |
| 92 |
filename = *argv; |
filename = *argv; |
| 93 |
|
|
| 94 |
decode_file(); |
decode_file(); |
| 95 |
|
|
| 96 |
argv++; |
argv++; |
| 97 |
} // while |
} // while |
| 98 |
|
|
| 99 |
return EXIT_SUCCESS; |
return EXIT_SUCCESS; |
| 100 |
} // main() |
} // main() |
| 101 |
|
|
| 102 |
void show_usage(int exitcode) |
void show_usage(int exitcode) |
| 103 |
{ |
{ |
| 104 |
fprintf((exitcode == EXIT_SUCCESS) ? stdout : stderr, |
fprintf((exitcode == EXIT_SUCCESS) ? stdout : stderr, |
| 105 |
"Usage: %s [-f] [-h] [-v] filename ...\n" |
"Usage: %s [-f | -h | -v] filename [...]\n" |
| 106 |
" E.g.: %s darkstat.db\n\n" |
" E.g.: %s darkstat.db\n\n" |
| 107 |
|
|
| 108 |
"Options:\n" |
"Options:\n" |
| 109 |
"-f\tToggle follow strict specification, default is false.\n" |
"-f\tToggle follow strict specification, default is false.\n" |
| 110 |
"-h\tShow this help message and exit.\n" |
"-h\tShow this help message and exit.\n" |
| 111 |
"-v\tShow version and copyright and exit.\n", |
"-v\tShow version and copyright and exit.\n", |
| 112 |
progname, progname); |
progname, progname); |
| 113 |
|
|
| 114 |
exit(exitcode); |
exit(exitcode); |
| 115 |
} // show_usage() |
} // show_usage() |
| 116 |
|
|
| 117 |
void show_version(void) |
void show_version(void) |
| 118 |
{ |
{ |
| 119 |
puts("darkstattype 1.0"); |
puts("darkstattype 1.0"); |
| 120 |
puts("$Ximalas$"); |
puts("$Ximalas$"); |
| 160 |
void print_indentation(void); |
void print_indentation(void); |
| 161 |
|
|
| 162 |
void print_time_t(time_t t); |
void print_time_t(time_t t); |
| 163 |
|
|
| 164 |
void decode_file(void) |
void decode_file(void) |
| 165 |
{ |
{ |
| 166 |
void decode_host_db_v1(void); |
void decode_host_db_v1(void); |
| 167 |
void decode_graph_db_v1(void); |
void decode_graph_db_v1(void); |
| 168 |
|
|
| 169 |
uint32_t fileheader; |
uint32_t fileheader; |
| 170 |
uint32_t sectionheader; |
uint32_t sectionheader; |
| 171 |
|
|
| 172 |
uint32_t i; |
uint32_t i; |
| 173 |
|
|
| 174 |
if ( (file = fopen(filename, "rb")) == NULL) { |
if ( (file = fopen(filename, "rb")) == NULL) { |
| 175 |
fprintf(stderr, "%s: fopen(\"%s\") = %s (%d)\n", progname, filename, strerror(errno), errno); |
fprintf(stderr, "%s: fopen(\"%s\") = %s (%d)\n", |
| 176 |
|
progname, filename, strerror(errno), errno); |
| 177 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 178 |
} // if |
} // if |
| 179 |
|
|
| 180 |
#define FILE_HEADER_V1 0xDA314159U |
#define FILE_HEADER_V1 0xDA314159U |
| 181 |
|
|
| 182 |
if ( (fileheader = read32u()) != FILE_HEADER_V1) { // not darkstat export format |
if ( (fileheader = read32u()) != FILE_HEADER_V1) { // not darkstat export format |
| 183 |
fprintf(stderr, "%s:%s:%ld: file header = 0x%x, not 0x%x\n", progname, filename, ftell(file), fileheader, FILE_HEADER_V1); |
fprintf(stderr, "%s:%s:%ld: file header = 0x%x, not 0x%x\n", |
| 184 |
|
progname, filename, ftell(file), fileheader, FILE_HEADER_V1); |
| 185 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 186 |
} // if |
} // if |
| 187 |
|
|
| 188 |
printf("File header 0x%x\n", fileheader); |
printf("File header 0x%x\n", fileheader); |
| 189 |
|
|
| 190 |
// Possible section header for host_db v1 and later graph_db v1. |
// Possible section header for host_db v1 and later graph_db v1. |
| 191 |
indent(); |
indent(); |
| 192 |
|
|
| 193 |
#define HOST_DB_V1 0xDA485301U |
#define HOST_DB_V1 0xDA485301U |
| 194 |
#define GRAPH_DB_V1 0xDA475201U |
#define GRAPH_DB_V1 0xDA475201U |
| 195 |
|
|
| 196 |
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
| 197 |
if ( (sectionheader = read32u()) == HOST_DB_V1) { |
if ( (sectionheader = read32u()) == HOST_DB_V1) { |
| 198 |
print_indentation(); |
print_indentation(); |
| 199 |
printf("Section header host_db v1 0x%x\n", sectionheader); |
printf("Section header host_db v1 0x%x\n", sectionheader); |
| 200 |
decode_host_db_v1(); |
decode_host_db_v1(); |
| 201 |
} // if |
} // if |
| 202 |
else if (sectionheader == GRAPH_DB_V1) { |
else if (sectionheader == GRAPH_DB_V1) { |
| 203 |
print_indentation(); |
print_indentation(); |
| 204 |
printf("Section header graph_db v1 0x%x\n", sectionheader); |
printf("Section header graph_db v1 0x%x\n", sectionheader); |
| 205 |
decode_graph_db_v1(); |
decode_graph_db_v1(); |
| 206 |
} // else if |
} // else if |
| 207 |
else { |
else { |
| 208 |
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); |
fprintf(stderr, |
| 209 |
|
"%s:%s:%ld: unknown section header = 0x%x, neither 0x%x nor 0x%x\n", |
| 210 |
|
progname, filename, ftell(file), sectionheader, HOST_DB_V1, |
| 211 |
|
GRAPH_DB_V1); |
| 212 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 213 |
} // else |
} // else |
| 214 |
} // for |
} // for |
| 215 |
|
|
| 216 |
exdent(); |
exdent(); |
| 217 |
|
|
| 218 |
if (fclose(file) != 0) { |
if (fclose(file) != 0) { |
| 219 |
fprintf(stderr, "%s: fclose(\"%s\") = %s (%d)\n", progname, filename, strerror(errno), errno); |
fprintf(stderr, "%s: fclose(\"%s\") = %s (%d)\n", |
| 220 |
|
progname, filename, strerror(errno), errno); |
| 221 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 222 |
} // if |
} // if |
| 223 |
} // decode_file() |
} // decode_file() |
| 224 |
|
|
| 225 |
void decode_host_db_v1(void) |
void decode_host_db_v1(void) |
| 226 |
{ |
{ |
| 227 |
void decode_host_header_v1(void); |
void decode_host_header_v1(void); |
| 228 |
void decode_host_header_v2(void); |
void decode_host_header_v2(void); |
| 229 |
void decode_host_header_v3(void); |
void decode_host_header_v3(void); |
| 230 |
|
|
| 231 |
uint32_t hostcount; |
uint32_t hostcount; |
| 232 |
uint32_t i; |
uint32_t i; |
| 233 |
|
|
| 234 |
indent(); |
indent(); |
| 235 |
|
|
| 236 |
hostcount = read32u(); |
hostcount = read32u(); |
| 237 |
|
|
| 238 |
print_indentation(); |
print_indentation(); |
| 239 |
printf("Host count %u\n", hostcount); |
printf("Host count %u\n", |
| 240 |
|
hostcount); |
| 241 |
|
|
| 242 |
for (i = 0; i < hostcount; i++) { |
for (i = 0; i < hostcount; i++) { |
| 243 |
uint32_t hostheader; |
uint32_t hostheader; |
| 244 |
|
|
| 245 |
print_indentation(); |
print_indentation(); |
| 246 |
printf("Host #%u of %u:\n", i + 1, hostcount); |
printf("Host #%u of %u:\n", |
| 247 |
|
i + 1, hostcount); |
| 248 |
|
|
| 249 |
indent(); |
indent(); |
| 250 |
|
|
| 251 |
#define HOST_HEADER_V3 0x48535403U |
#define HOST_HEADER_V3 0x48535403U |
| 252 |
#define HOST_HEADER_V2 0x48535402U |
#define HOST_HEADER_V2 0x48535402U |
| 253 |
#define HOST_HEADER_V1 0x48535401U |
#define HOST_HEADER_V1 0x48535401U |
| 254 |
|
|
| 255 |
if ( (hostheader = read32u()) == HOST_HEADER_V3) { // host header v3 |
if ( (hostheader = read32u()) == HOST_HEADER_V3) { // host header v3 |
| 256 |
print_indentation(); |
print_indentation(); |
| 257 |
printf("Host header v3 0x%x\n", hostheader); |
printf("Host header v3 0x%x\n", |
| 258 |
|
hostheader); |
| 259 |
decode_host_header_v3(); |
decode_host_header_v3(); |
| 260 |
} // if |
} // if |
| 261 |
else if (hostheader == HOST_HEADER_V2) { // host header v2 |
else if (hostheader == HOST_HEADER_V2) { // host header v2 |
| 262 |
print_indentation(); |
print_indentation(); |
| 263 |
printf("Host header v2 0x%x\n", hostheader); |
printf("Host header v2 0x%x\n", |
| 264 |
|
hostheader); |
| 265 |
decode_host_header_v2(); |
decode_host_header_v2(); |
| 266 |
} // else if |
} // else if |
| 267 |
else if (hostheader == HOST_HEADER_V1) { // host header v1 |
else if (hostheader == HOST_HEADER_V1) { // host header v1 |
| 268 |
print_indentation(); |
print_indentation(); |
| 269 |
printf("Host header v1 0x%x\n", hostheader); |
printf("Host header v1 0x%x\n", |
| 270 |
|
hostheader); |
| 271 |
decode_host_header_v1(); |
decode_host_header_v1(); |
| 272 |
} // else if |
} // else if |
| 273 |
else { // unknown host header version |
else { // unknown host header version |
| 274 |
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); |
fprintf(stderr, |
| 275 |
|
"%s:%s:%ld: unknown host header = 0x%x, neither 0x%x nor 0x%x nor 0x%x\n", |
| 276 |
|
progname, filename, ftell(file), hostheader, HOST_HEADER_V3, |
| 277 |
|
HOST_HEADER_V2, HOST_HEADER_V1); |
| 278 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 279 |
} // else |
} // else |
| 280 |
|
|
| 281 |
exdent(); |
exdent(); |
| 282 |
} // for |
} // for |
| 283 |
|
|
| 284 |
exdent(); |
exdent(); |
| 285 |
} // decode_host_db_v1() |
} // decode_host_db_v1() |
| 286 |
|
|
| 287 |
void decode_protos_data(void); |
void decode_protos_data(void); |
| 288 |
void decode_tcp_data(void); |
void decode_tcp_data(void); |
| 289 |
void decode_udp_data(void); |
void decode_udp_data(void); |
| 290 |
|
|
| 291 |
void decode_host_header_v1(void) |
void decode_host_header_v1(void) |
| 292 |
{ |
{ |
| 298 |
uint64_t bytesout; |
uint64_t bytesout; |
| 299 |
uint8_t protosdata; |
uint8_t protosdata; |
| 300 |
uint8_t tcpdata; |
uint8_t tcpdata; |
| 301 |
uint8_t udpdata; |
uint8_t udpdata; |
| 302 |
|
|
| 303 |
uint8_t i; |
uint8_t i; |
| 304 |
|
|
| 305 |
indent(); |
indent(); |
| 306 |
|
|
| 307 |
ipv4address[0] = read8u(); |
ipv4address[0] = read8u(); |
| 308 |
ipv4address[1] = read8u(); |
ipv4address[1] = read8u(); |
| 309 |
ipv4address[2] = read8u(); |
ipv4address[2] = read8u(); |
| 310 |
ipv4address[3] = read8u(); |
ipv4address[3] = read8u(); |
| 311 |
|
|
| 312 |
print_indentation(); |
print_indentation(); |
| 313 |
printf("IPv4 address %u.%u.%u.%u\n", |
printf("IPv4 address %hhu.%hhu.%hhu.%hhu\n", |
| 314 |
ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]); |
ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]); |
| 315 |
|
|
| 316 |
macaddress[0] = read8u(); |
macaddress[0] = read8u(); |
| 317 |
macaddress[1] = read8u(); |
macaddress[1] = read8u(); |
| 318 |
macaddress[2] = read8u(); |
macaddress[2] = read8u(); |
| 319 |
macaddress[3] = read8u(); |
macaddress[3] = read8u(); |
| 320 |
macaddress[4] = read8u(); |
macaddress[4] = read8u(); |
| 321 |
macaddress[5] = read8u(); |
macaddress[5] = read8u(); |
| 322 |
|
|
| 323 |
print_indentation(); |
print_indentation(); |
| 324 |
printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]); |
printf("MAC address %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", |
| 325 |
|
macaddress[0], macaddress[1], macaddress[2], |
| 326 |
|
macaddress[3], macaddress[4], macaddress[5]); |
| 327 |
|
|
| 328 |
hostnamelen = read8u(); |
hostnamelen = read8u(); |
| 329 |
|
|
| 330 |
print_indentation(); |
print_indentation(); |
| 331 |
printf("Hostname length %u\n", hostnamelen); |
printf("Hostname length %u\n", |
| 332 |
|
hostnamelen); |
| 333 |
|
|
| 334 |
for (i = 0; i < hostnamelen; i++) { |
for (i = 0; i < hostnamelen; i++) { |
| 335 |
hostname[i] = read8u(); |
hostname[i] = read8u(); |
| 336 |
} // for |
} // for |
| 337 |
hostname[i] = '\0'; |
hostname[i] = '\0'; |
| 338 |
|
|
| 339 |
print_indentation(); |
print_indentation(); |
| 340 |
printf("Hostname %s\n", hostname); |
printf("Hostname %s\n", |
| 341 |
|
hostname); |
| 342 |
|
|
| 343 |
bytesin = read64u(); |
bytesin = read64u(); |
| 344 |
|
|
| 345 |
print_indentation(); |
print_indentation(); |
| 346 |
printf("Bytes in %lu\n", bytesin); |
printf("Bytes in %llu\n", |
| 347 |
|
(unsigned long long)bytesin); |
| 348 |
|
|
| 349 |
bytesout = read64u(); |
bytesout = read64u(); |
| 350 |
|
|
| 351 |
print_indentation(); |
print_indentation(); |
| 352 |
printf("Bytes out %lu\n", bytesout); |
printf("Bytes out %llu\n", |
| 353 |
|
(unsigned long long)bytesout); |
| 354 |
|
|
| 355 |
if ( (protosdata = read8u()) != 'P') { // missing protos data |
if ( (protosdata = read8u()) != 'P') { // missing protos data |
| 356 |
fprintf(stderr, "%s:%s:%ld: expecting character P, not %c\n", progname, filename, ftell(file), protosdata); |
fprintf(stderr, |
| 357 |
|
"%s:%s:%ld: expecting character P, not %c\n", |
| 358 |
|
progname, filename, ftell(file), protosdata); |
| 359 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 360 |
} // if |
} // if |
| 361 |
|
|
| 362 |
decode_protos_data(); |
decode_protos_data(); |
| 363 |
|
|
| 364 |
if ( (tcpdata = read8u()) != 'T') { // missing tcp data |
if ( (tcpdata = read8u()) != 'T') { // missing tcp data |
| 365 |
fprintf(stderr, "%s:%s:%ld: expecting character T, not %c\n", progname, filename, ftell(file), tcpdata); |
fprintf(stderr, |
| 366 |
|
"%s:%s:%ld: expecting character T, not %c\n", |
| 367 |
|
progname, filename, ftell(file), tcpdata); |
| 368 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 369 |
} // if |
} // if |
| 370 |
|
|
| 371 |
decode_tcp_data(); |
decode_tcp_data(); |
| 372 |
|
|
| 373 |
if ( (udpdata = read8u()) != 'U') { // missing udp data |
if ( (udpdata = read8u()) != 'U') { // missing udp data |
| 374 |
fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata); |
fprintf(stderr, |
| 375 |
|
"%s:%s:%ld: expecting character U, not %c\n", |
| 376 |
|
progname, filename, ftell(file), udpdata); |
| 377 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 378 |
} // if |
} // if |
| 379 |
|
|
| 380 |
decode_udp_data(); |
decode_udp_data(); |
| 381 |
|
|
| 382 |
exdent(); |
exdent(); |
| 383 |
} // decode_host_header_v1 |
} // decode_host_header_v1 |
| 384 |
|
|
| 385 |
void decode_host_header_v2(void) |
void decode_host_header_v2(void) |
| 386 |
{ |
{ |
| 387 |
uint8_t ipv4address[4]; |
uint8_t ipv4address[4]; |
| 388 |
uint8_t macaddress[6]; |
uint8_t macaddress[6]; |
| 389 |
int64_t lastseen; |
int64_t lastseen; |
| 390 |
uint8_t hostnamelen; |
uint8_t hostnamelen; |
| 391 |
uint8_t hostname[256]; |
uint8_t hostname[256]; |
| 393 |
uint64_t bytesout; |
uint64_t bytesout; |
| 394 |
uint8_t protosdata; |
uint8_t protosdata; |
| 395 |
uint8_t tcpdata; |
uint8_t tcpdata; |
| 396 |
uint8_t udpdata; |
uint8_t udpdata; |
| 397 |
|
|
| 398 |
uint8_t i; |
uint8_t i; |
| 399 |
|
|
| 400 |
indent(); |
indent(); |
| 401 |
|
|
| 402 |
ipv4address[0] = read8u(); |
ipv4address[0] = read8u(); |
| 403 |
ipv4address[1] = read8u(); |
ipv4address[1] = read8u(); |
| 404 |
ipv4address[2] = read8u(); |
ipv4address[2] = read8u(); |
| 405 |
ipv4address[3] = read8u(); |
ipv4address[3] = read8u(); |
| 406 |
|
|
| 407 |
print_indentation(); |
print_indentation(); |
| 408 |
printf("IPv4 address %u.%u.%u.%u\n", |
printf("IPv4 address %hhu.%hhu.%hhu.%hhu\n", |
| 409 |
ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]); |
ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]); |
| 410 |
|
|
| 411 |
if (follow_specification == true) { |
if (follow_specification == true) { |
| 412 |
macaddress[0] = read8u(); |
macaddress[0] = read8u(); |
| 413 |
macaddress[1] = read8u(); |
macaddress[1] = read8u(); |
| 414 |
macaddress[2] = read8u(); |
macaddress[2] = read8u(); |
| 415 |
macaddress[3] = read8u(); |
macaddress[3] = read8u(); |
| 416 |
macaddress[4] = read8u(); |
macaddress[4] = read8u(); |
| 417 |
macaddress[5] = read8u(); |
macaddress[5] = read8u(); |
| 418 |
|
|
| 419 |
print_indentation(); |
print_indentation(); |
| 420 |
printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]); |
printf("MAC address %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", |
| 421 |
|
macaddress[0], macaddress[1], macaddress[2], |
| 422 |
|
macaddress[3], macaddress[4], macaddress[5]); |
| 423 |
|
|
| 424 |
lastseen = read64s(); |
lastseen = read64s(); |
| 425 |
|
|
| 426 |
print_indentation(); |
print_indentation(); |
| 427 |
printf("Last seen 0x%lx = %ld = ", lastseen, lastseen); |
printf("Last seen 0x%llx = %lld = ", |
| 428 |
|
(unsigned long long)lastseen, (long long)lastseen); |
| 429 |
print_time_t(lastseen); |
print_time_t(lastseen); |
| 430 |
puts(""); |
puts(""); |
| 431 |
} // if |
} // if |
| 432 |
else { |
else { |
| 433 |
lastseen = read64s(); |
lastseen = read64s(); |
| 434 |
|
|
| 435 |
print_indentation(); |
print_indentation(); |
| 436 |
printf("Last seen 0x%lx = %ld = ", lastseen, lastseen); |
printf("Last seen 0x%llx = %lld = ", |
| 437 |
|
(unsigned long long)lastseen, (long long)lastseen); |
| 438 |
print_time_t(lastseen); |
print_time_t(lastseen); |
| 439 |
puts(""); |
puts(""); |
| 440 |
|
|
| 441 |
macaddress[0] = read8u(); |
macaddress[0] = read8u(); |
| 442 |
macaddress[1] = read8u(); |
macaddress[1] = read8u(); |
| 443 |
macaddress[2] = read8u(); |
macaddress[2] = read8u(); |
| 444 |
macaddress[3] = read8u(); |
macaddress[3] = read8u(); |
| 445 |
macaddress[4] = read8u(); |
macaddress[4] = read8u(); |
| 446 |
macaddress[5] = read8u(); |
macaddress[5] = read8u(); |
| 447 |
|
|
| 448 |
print_indentation(); |
print_indentation(); |
| 449 |
printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]); |
printf("MAC address %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", |
| 450 |
|
macaddress[0], macaddress[1], macaddress[2], |
| 451 |
|
macaddress[3], macaddress[4], macaddress[5]); |
| 452 |
} // else |
} // else |
| 453 |
|
|
| 454 |
hostnamelen = read8u(); |
hostnamelen = read8u(); |
| 455 |
|
|
| 456 |
print_indentation(); |
print_indentation(); |
| 457 |
printf("Hostname length %u\n", hostnamelen); |
printf("Hostname length %hhu\n", |
| 458 |
|
hostnamelen); |
| 459 |
|
|
| 460 |
for (i = 0; i < hostnamelen; i++) { |
for (i = 0; i < hostnamelen; i++) { |
| 461 |
hostname[i] = read8u(); |
hostname[i] = read8u(); |
| 462 |
} // for |
} // for |
| 463 |
hostname[i] = '\0'; |
hostname[i] = '\0'; |
| 464 |
|
|
| 465 |
print_indentation(); |
print_indentation(); |
| 466 |
printf("Hostname %s\n", hostname); |
printf("Hostname %s\n", |
| 467 |
|
hostname); |
| 468 |
|
|
| 469 |
bytesin = read64u(); |
bytesin = read64u(); |
| 470 |
|
|
| 471 |
print_indentation(); |
print_indentation(); |
| 472 |
printf("Bytes in %lu\n", bytesin); |
printf("Bytes in %llu\n", |
| 473 |
|
(unsigned long long)bytesin); |
| 474 |
|
|
| 475 |
bytesout = read64u(); |
bytesout = read64u(); |
| 476 |
|
|
| 477 |
print_indentation(); |
print_indentation(); |
| 478 |
printf("Bytes out %lu\n", bytesout); |
printf("Bytes out %llu\n", |
| 479 |
|
(unsigned long long)bytesout); |
| 480 |
|
|
| 481 |
if ( (protosdata = read8u()) != 'P') { // missing protos data |
if ( (protosdata = read8u()) != 'P') { // missing protos data |
| 482 |
fprintf(stderr, "%s:%s:%ld: expecting character P, not %c\n", progname, filename, ftell(file), protosdata); |
fprintf(stderr, |
| 483 |
|
"%s:%s:%ld: expecting character P, not %c\n", |
| 484 |
|
progname, filename, ftell(file), protosdata); |
| 485 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 486 |
} // if |
} // if |
| 487 |
|
|
| 488 |
decode_protos_data(); |
decode_protos_data(); |
| 489 |
|
|
| 490 |
if ( (tcpdata = read8u()) != 'T') { // missing tcp data |
if ( (tcpdata = read8u()) != 'T') { // missing tcp data |
| 491 |
fprintf(stderr, "%s:%s:%ld: expecting character T, not %c\n", progname, filename, ftell(file), tcpdata); |
fprintf(stderr, |
| 492 |
|
"%s:%s:%ld: expecting character T, not %c\n", |
| 493 |
|
progname, filename, ftell(file), tcpdata); |
| 494 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 495 |
} // if |
} // if |
| 496 |
|
|
| 497 |
decode_tcp_data(); |
decode_tcp_data(); |
| 498 |
|
|
| 499 |
if ( (udpdata = read8u()) != 'U') { // missing udp data |
if ( (udpdata = read8u()) != 'U') { // missing udp data |
| 500 |
fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata); |
fprintf(stderr, |
| 501 |
|
"%s:%s:%ld: expecting character U, not %c\n", |
| 502 |
|
progname, filename, ftell(file), udpdata); |
| 503 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 504 |
} // if |
} // if |
| 505 |
|
|
| 506 |
decode_udp_data(); |
decode_udp_data(); |
| 507 |
|
|
| 508 |
exdent(); |
exdent(); |
| 509 |
} // decode_host_header_v2 |
} // decode_host_header_v2 |
| 510 |
|
|
| 511 |
void decode_host_header_v3(void) |
void decode_host_header_v3(void) |
| 512 |
{ |
{ |
| 513 |
uint8_t addressfamily; |
uint8_t addressfamily; |
| 514 |
uint8_t ipv4address[4]; |
uint8_t ipv4address[4]; |
| 515 |
uint16_t ipv6address[8]; |
uint16_t ipv6address[8]; |
| 516 |
uint8_t macaddress[6]; |
uint8_t macaddress[6]; |
| 517 |
int64_t lastseen; |
int64_t lastseen; |
| 518 |
uint8_t hostnamelen; |
uint8_t hostnamelen; |
| 519 |
uint8_t hostname[256]; |
uint8_t hostname[256]; |
| 520 |
uint64_t bytesin; |
uint64_t bytesin; |
| 521 |
uint64_t bytesout; |
uint64_t bytesout; |
| 522 |
uint8_t protosdata; |
uint8_t protosdata; |
| 523 |
uint8_t tcpdata; |
uint8_t tcpdata; |
| 524 |
uint8_t udpdata; |
uint8_t udpdata; |
| 525 |
|
|
| 526 |
uint8_t i; |
uint8_t i; |
| 527 |
|
|
| 528 |
indent(); |
indent(); |
| 529 |
|
|
| 530 |
if ( (addressfamily = read8u()) == 0x04) { // IPv4 address |
#define A_F_4 0x04 |
| 531 |
|
#define A_F_6 0x06 |
| 532 |
|
|
| 533 |
|
if ( (addressfamily = read8u()) == A_F_4) { // IPv4 address |
| 534 |
print_indentation(); |
print_indentation(); |
| 535 |
printf("IPv4 address family (0x%02x)\n", addressfamily); |
printf("IPv4 address family (0x%02hhx)\n", |
| 536 |
|
addressfamily); |
| 537 |
|
|
| 538 |
ipv4address[0] = read8u(); |
ipv4address[0] = read8u(); |
| 539 |
ipv4address[1] = read8u(); |
ipv4address[1] = read8u(); |
| 540 |
ipv4address[2] = read8u(); |
ipv4address[2] = read8u(); |
| 541 |
ipv4address[3] = read8u(); |
ipv4address[3] = read8u(); |
| 542 |
|
|
| 543 |
print_indentation(); |
print_indentation(); |
| 544 |
printf("IPv4 address %u.%u.%u.%u\n", |
printf("IPv4 address %hhu.%hhu.%hhu.%hhu\n", |
| 545 |
ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]); |
ipv4address[0], ipv4address[1], ipv4address[2], ipv4address[3]); |
| 546 |
} // if |
} // if |
| 547 |
else if (addressfamily == 0x06) { // IPv6 address |
else if (addressfamily == A_F_6) { // IPv6 address |
| 548 |
print_indentation(); |
print_indentation(); |
| 549 |
printf("IPv6 address family (0x%02x)\n", addressfamily); |
printf("IPv6 address family (0x%02hhx)\n", |
| 550 |
|
addressfamily); |
| 551 |
|
|
| 552 |
ipv6address[0] = read16u(); |
ipv6address[0] = read16u(); |
| 553 |
ipv6address[1] = read16u(); |
ipv6address[1] = read16u(); |
| 554 |
ipv6address[2] = read16u(); |
ipv6address[2] = read16u(); |
| 555 |
ipv6address[3] = read16u(); |
ipv6address[3] = read16u(); |
| 556 |
ipv6address[4] = read16u(); |
ipv6address[4] = read16u(); |
| 557 |
ipv6address[5] = read16u(); |
ipv6address[5] = read16u(); |
| 558 |
ipv6address[6] = read16u(); |
ipv6address[6] = read16u(); |
| 559 |
ipv6address[7] = read16u(); |
ipv6address[7] = read16u(); |
| 560 |
|
|
| 561 |
print_indentation(); |
print_indentation(); |
| 562 |
printf("IPv6 address %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", |
printf("IPv6 address %04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx:%04hx\n", |
| 563 |
ipv6address[0], |
ipv6address[0], ipv6address[1], ipv6address[2], ipv6address[3], |
| 564 |
ipv6address[1], |
ipv6address[4], ipv6address[5], ipv6address[6], ipv6address[7]); |
|
ipv6address[2], |
|
|
ipv6address[3], |
|
|
ipv6address[4], |
|
|
ipv6address[5], |
|
|
ipv6address[6], |
|
|
ipv6address[7]); |
|
| 565 |
} // else if |
} // else if |
| 566 |
else { // unknown address family |
else { // unknown address family |
| 567 |
fprintf(stderr, "%s:%s:%ld: unknown address family = 0x%x, neither 0x%x nor 0x%x\n", progname, filename, ftell(file), addressfamily, 0x04, 0x06); |
fprintf(stderr, |
| 568 |
|
"%s:%s:%ld: unknown address family = 0x%hhx, neither 0x%x nor 0x%x\n", |
| 569 |
|
progname, filename, ftell(file), addressfamily, A_F_4, A_F_6); |
| 570 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 571 |
} // else |
} // else |
| 572 |
|
|
| 573 |
if (follow_specification == true) { |
if (follow_specification == true) { |
| 574 |
macaddress[0] = read8u(); |
macaddress[0] = read8u(); |
| 575 |
macaddress[1] = read8u(); |
macaddress[1] = read8u(); |
| 576 |
macaddress[2] = read8u(); |
macaddress[2] = read8u(); |
| 577 |
macaddress[3] = read8u(); |
macaddress[3] = read8u(); |
| 578 |
macaddress[4] = read8u(); |
macaddress[4] = read8u(); |
| 579 |
macaddress[5] = read8u(); |
macaddress[5] = read8u(); |
| 580 |
|
|
| 581 |
print_indentation(); |
print_indentation(); |
| 582 |
printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]); |
printf("MAC address %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", |
| 583 |
|
macaddress[0], macaddress[1], macaddress[2], |
| 584 |
|
macaddress[3], macaddress[4], macaddress[5]); |
| 585 |
|
|
| 586 |
lastseen = read64s(); |
lastseen = read64s(); |
| 587 |
|
|
| 588 |
print_indentation(); |
print_indentation(); |
| 589 |
printf("Last seen 0x%lx = %ld = ", lastseen, lastseen); |
printf("Last seen 0x%llx = %lld = ", |
| 590 |
|
(unsigned long long)lastseen, (long long)lastseen); |
| 591 |
print_time_t(lastseen); |
print_time_t(lastseen); |
| 592 |
puts(""); |
puts(""); |
| 593 |
} // if |
} // if |
| 594 |
else { |
else { |
| 595 |
lastseen = read64s(); |
lastseen = read64s(); |
| 596 |
|
|
| 597 |
print_indentation(); |
print_indentation(); |
| 598 |
printf("Last seen 0x%lx = %ld = ", lastseen, lastseen); |
printf("Last seen 0x%llx = %lld = ", |
| 599 |
|
(unsigned long long)lastseen, (long long)lastseen); |
| 600 |
print_time_t(lastseen); |
print_time_t(lastseen); |
| 601 |
puts(""); |
puts(""); |
| 602 |
|
|
| 603 |
macaddress[0] = read8u(); |
macaddress[0] = read8u(); |
| 604 |
macaddress[1] = read8u(); |
macaddress[1] = read8u(); |
| 605 |
macaddress[2] = read8u(); |
macaddress[2] = read8u(); |
| 606 |
macaddress[3] = read8u(); |
macaddress[3] = read8u(); |
| 607 |
macaddress[4] = read8u(); |
macaddress[4] = read8u(); |
| 608 |
macaddress[5] = read8u(); |
macaddress[5] = read8u(); |
| 609 |
|
|
| 610 |
print_indentation(); |
print_indentation(); |
| 611 |
printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n", macaddress[0], macaddress[1], macaddress[2], macaddress[3], macaddress[4], macaddress[5]); |
printf("MAC address %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", |
| 612 |
|
macaddress[0], macaddress[1], macaddress[2], |
| 613 |
|
macaddress[3], macaddress[4], macaddress[5]); |
| 614 |
} // else |
} // else |
| 615 |
|
|
| 616 |
hostnamelen = read8u(); |
hostnamelen = read8u(); |
| 617 |
|
|
| 618 |
print_indentation(); |
print_indentation(); |
| 619 |
printf("Hostname length %u\n", hostnamelen); |
printf("Hostname length %hhu\n", |
| 620 |
|
hostnamelen); |
| 621 |
|
|
| 622 |
for (i = 0; i < hostnamelen; i++) { |
for (i = 0; i < hostnamelen; i++) { |
| 623 |
hostname[i] = read8u(); |
hostname[i] = read8u(); |
| 624 |
} // for |
} // for |
| 625 |
hostname[i] = '\0'; |
hostname[i] = '\0'; |
| 626 |
|
|
| 627 |
print_indentation(); |
print_indentation(); |
| 628 |
printf("Hostname %s\n", hostname); |
printf("Hostname %s\n", |
| 629 |
|
hostname); |
| 630 |
|
|
| 631 |
bytesin = read64u(); |
bytesin = read64u(); |
| 632 |
|
|
| 633 |
print_indentation(); |
print_indentation(); |
| 634 |
printf("Bytes in %lu\n", bytesin); |
printf("Bytes in %llu\n", |
| 635 |
|
(unsigned long long)bytesin); |
| 636 |
|
|
| 637 |
bytesout = read64u(); |
bytesout = read64u(); |
| 638 |
|
|
| 639 |
print_indentation(); |
print_indentation(); |
| 640 |
printf("Bytes out %lu\n", bytesout); |
printf("Bytes out %llu\n", |
| 641 |
|
(unsigned long long)bytesout); |
| 642 |
|
|
| 643 |
if ( (protosdata = read8u()) != 'P') { // missing protos data |
if ( (protosdata = read8u()) != 'P') { // missing protos data |
| 644 |
fprintf(stderr, "%s:%s:%ld: expecting character P, not %c\n", progname, filename, ftell(file), protosdata); |
fprintf(stderr, |
| 645 |
|
"%s:%s:%ld: expecting character P, not %c\n", |
| 646 |
|
progname, filename, ftell(file), protosdata); |
| 647 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 648 |
} // if |
} // if |
| 649 |
|
|
| 650 |
decode_protos_data(); |
decode_protos_data(); |
| 651 |
|
|
| 652 |
if ( (tcpdata = read8u()) != 'T') { // missing tcp data |
if ( (tcpdata = read8u()) != 'T') { // missing tcp data |
| 653 |
fprintf(stderr, "%s:%s:%ld: expecting character T, not %c\n", progname, filename, ftell(file), tcpdata); |
fprintf(stderr, |
| 654 |
|
"%s:%s:%ld: expecting character T, not %c\n", |
| 655 |
|
progname, filename, ftell(file), tcpdata); |
| 656 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 657 |
} // if |
} // if |
| 658 |
|
|
| 659 |
decode_tcp_data(); |
decode_tcp_data(); |
| 660 |
|
|
| 661 |
if ( (udpdata = read8u()) != 'U') { // missing udp data |
if ( (udpdata = read8u()) != 'U') { // missing udp data |
| 662 |
fprintf(stderr, "%s:%s:%ld: expecting character U, not %c\n", progname, filename, ftell(file), udpdata); |
fprintf(stderr, |
| 663 |
|
"%s:%s:%ld: expecting character U, not %c\n", |
| 664 |
|
progname, filename, ftell(file), udpdata); |
| 665 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 666 |
} // if |
} // if |
| 667 |
|
|
| 668 |
decode_udp_data(); |
decode_udp_data(); |
| 669 |
|
|
| 670 |
exdent(); |
exdent(); |
| 671 |
} // decode_host_header_v3 |
} // decode_host_header_v3 |
| 672 |
|
|
| 673 |
void decode_protos_data(void) |
void decode_protos_data(void) |
| 674 |
{ |
{ |
| 675 |
uint8_t ipprotocount; |
uint8_t ipprotocount; |
| 676 |
|
|
| 677 |
uint8_t i; |
uint8_t i; |
| 678 |
|
|
| 679 |
ipprotocount = read8u(); |
ipprotocount = read8u(); |
| 680 |
|
|
| 681 |
print_indentation(); |
print_indentation(); |
| 682 |
printf("IP Proto count %u\n", ipprotocount); |
printf("IP Proto count %hhu\n", |
| 683 |
|
ipprotocount); |
| 684 |
|
|
| 685 |
indent(); |
indent(); |
| 686 |
|
|
| 687 |
for (i = 0; i < ipprotocount; i++) { |
for (i = 0; i < ipprotocount; i++) { |
| 688 |
uint8_t proto; |
uint8_t proto; |
| 689 |
uint64_t in; |
uint64_t in; |
| 690 |
uint64_t out; |
uint64_t out; |
| 691 |
|
|
| 692 |
print_indentation(); |
print_indentation(); |
| 693 |
printf("Protocol #%u of %u:\n", i + 1, ipprotocount); |
printf("Protocol #%u of %hhu:\n", |
| 694 |
|
i + 1, ipprotocount); |
| 695 |
|
|
| 696 |
proto = read8u(); |
proto = read8u(); |
| 697 |
|
|
| 698 |
indent(); |
indent(); |
| 699 |
print_indentation(); |
print_indentation(); |
| 700 |
printf("Protocol 0x%02x\n", proto); |
printf("Protocol 0x%02hhx\n", |
| 701 |
|
proto); |
| 702 |
|
|
| 703 |
in = read64u(); |
in = read64u(); |
| 704 |
|
|
| 705 |
print_indentation(); |
print_indentation(); |
| 706 |
printf("In %lu\n", in); |
printf("In %llu\n", |
| 707 |
|
(unsigned long long)in); |
| 708 |
|
|
| 709 |
out = read64u(); |
out = read64u(); |
| 710 |
|
|
| 711 |
print_indentation(); |
print_indentation(); |
| 712 |
printf("Out %lu\n", out); |
printf("Out %llu\n", |
| 713 |
|
(unsigned long long)out); |
| 714 |
|
|
| 715 |
exdent(); |
exdent(); |
| 716 |
} // for |
} // for |
| 717 |
|
|
| 718 |
exdent(); |
exdent(); |
| 719 |
} // decode_protos_data(); |
} // decode_protos_data(); |
| 720 |
|
|
| 721 |
void decode_tcp_data(void) |
void decode_tcp_data(void) |
| 722 |
{ |
{ |
| 723 |
uint8_t tcpprotocount; |
uint8_t tcpprotocount; |
| 724 |
|
|
| 725 |
uint16_t i; |
uint16_t i; |
| 726 |
|
|
| 727 |
tcpprotocount = read16u(); |
tcpprotocount = read16u(); |
| 728 |
|
|
| 729 |
print_indentation(); |
print_indentation(); |
| 730 |
printf("TCP proto count %u\n", tcpprotocount); |
printf("TCP proto count %hhu\n", |
| 731 |
|
tcpprotocount); |
| 732 |
|
|
| 733 |
indent(); |
indent(); |
| 734 |
|
|
| 735 |
for (i = 0; i < tcpprotocount; i++) { |
for (i = 0; i < tcpprotocount; i++) { |
| 736 |
uint16_t port; |
uint16_t port; |
| 737 |
uint64_t syn; |
uint64_t syn; |
| 738 |
uint64_t in; |
uint64_t in; |
| 739 |
uint64_t out; |
uint64_t out; |
| 740 |
|
|
| 741 |
port = read16u(); |
port = read16u(); |
| 742 |
|
|
| 743 |
print_indentation(); |
print_indentation(); |
| 744 |
printf("Port %u:\n", port); |
printf("Port %hu:\n", |
| 745 |
|
port); |
| 746 |
|
|
| 747 |
syn = read64u(); |
syn = read64u(); |
| 748 |
|
|
| 749 |
indent(); |
indent(); |
| 750 |
print_indentation(); |
print_indentation(); |
| 751 |
printf("SYN %lu\n", syn); |
printf("SYN %llu\n", |
| 752 |
|
(unsigned long long)syn); |
| 753 |
|
|
| 754 |
in = read64u(); |
in = read64u(); |
| 755 |
|
|
| 756 |
print_indentation(); |
print_indentation(); |
| 757 |
printf("In %lu\n", in); |
printf("In %llu\n", |
| 758 |
|
(unsigned long long)in); |
| 759 |
|
|
| 760 |
out = read64u(); |
out = read64u(); |
| 761 |
|
|
| 762 |
print_indentation(); |
print_indentation(); |
| 763 |
printf("Out %lu\n", out); |
printf("Out %llu\n", |
| 764 |
|
(unsigned long long)out); |
| 765 |
|
|
| 766 |
exdent(); |
exdent(); |
| 767 |
} // for |
} // for |
| 768 |
|
|
| 769 |
exdent(); |
exdent(); |
| 770 |
} // decode_tcp_data() |
} // decode_tcp_data() |
| 771 |
|
|
| 772 |
void decode_udp_data(void) |
void decode_udp_data(void) |
| 773 |
{ |
{ |
| 774 |
uint8_t udpprotocount; |
uint8_t udpprotocount; |
| 775 |
|
|
| 776 |
uint16_t i; |
uint16_t i; |
| 777 |
|
|
| 778 |
udpprotocount = read16u(); |
udpprotocount = read16u(); |
| 779 |
|
|
| 780 |
print_indentation(); |
print_indentation(); |
| 781 |
printf("UDP proto count %u\n", udpprotocount); |
printf("UDP proto count %hhu\n", |
| 782 |
|
udpprotocount); |
| 783 |
|
|
| 784 |
indent(); |
indent(); |
| 785 |
|
|
| 786 |
for (i = 0; i < udpprotocount; i++) { |
for (i = 0; i < udpprotocount; i++) { |
| 787 |
uint16_t port; |
uint16_t port; |
| 788 |
uint64_t in; |
uint64_t in; |
| 789 |
uint64_t out; |
uint64_t out; |
| 790 |
|
|
| 791 |
port = read16u(); |
port = read16u(); |
| 792 |
|
|
| 793 |
print_indentation(); |
print_indentation(); |
| 794 |
printf("Port %u:\n", port); |
printf("Port %hu:\n", |
| 795 |
|
port); |
| 796 |
|
|
| 797 |
in = read64u(); |
in = read64u(); |
| 798 |
|
|
| 799 |
indent(); |
indent(); |
| 800 |
print_indentation(); |
print_indentation(); |
| 801 |
printf("In %lu\n", in); |
printf("In %llu\n", |
| 802 |
|
(unsigned long long)in); |
| 803 |
|
|
| 804 |
out = read64u(); |
out = read64u(); |
| 805 |
|
|
| 806 |
print_indentation(); |
print_indentation(); |
| 807 |
printf("Out %lu\n", out); |
printf("Out %llu\n", |
| 808 |
|
(unsigned long long)out); |
| 809 |
|
|
| 810 |
exdent(); |
exdent(); |
| 811 |
} // for |
} // for |
| 812 |
|
|
| 813 |
exdent(); |
exdent(); |
| 814 |
} // decode_udp_data() |
} // decode_udp_data() |
| 815 |
|
|
| 816 |
void decode_graph_db_v1(void) |
void decode_graph_db_v1(void) |
| 817 |
{ |
{ |
| 818 |
int64_t lasttime; |
int64_t lasttime; |
| 819 |
|
|
| 820 |
uint32_t i; |
uint32_t i; |
| 821 |
|
|
| 822 |
lasttime = read64s(); |
lasttime = read64s(); |
| 823 |
|
|
| 824 |
indent(); |
indent(); |
| 825 |
print_indentation(); |
print_indentation(); |
| 826 |
printf("Last time 0x%lx = %ld = ", lasttime, lasttime); |
printf("Last time 0x%llx = %lld = ", |
| 827 |
|
(unsigned long long)lasttime, (long long)lasttime); |
| 828 |
print_time_t(lasttime); |
print_time_t(lasttime); |
| 829 |
puts(""); |
puts(""); |
| 830 |
|
|
| 831 |
for (i = 0; i < 4; i++) { |
for (i = 0; i < 4; i++) { |
| 832 |
uint8_t nbars; |
uint8_t nbars; |
| 833 |
uint8_t idxlastbar; |
uint8_t idxlastbar; |
| 834 |
|
|
| 835 |
uint32_t j; |
uint32_t j; |
| 836 |
|
|
| 837 |
print_indentation(); |
print_indentation(); |
| 838 |
printf("Graph #%u of 4:\n", i + 1); |
printf("Graph #%u of 4:\n", |
| 839 |
|
i + 1); |
| 840 |
|
|
| 841 |
nbars = read8u(); |
nbars = read8u(); |
| 842 |
|
|
| 843 |
indent(); |
indent(); |
| 844 |
print_indentation(); |
print_indentation(); |
| 845 |
printf("Number of bars %u\n", nbars); |
printf("Number of bars %hhu\n", |
| 846 |
|
nbars); |
| 847 |
|
|
| 848 |
idxlastbar = read8u(); |
idxlastbar = read8u(); |
| 849 |
|
|
| 850 |
print_indentation(); |
print_indentation(); |
| 851 |
printf("Index of last bar %u\n", idxlastbar); |
printf("Index of last bar %hhu\n", |
| 852 |
|
idxlastbar); |
| 853 |
|
|
| 854 |
indent(); |
indent(); |
| 855 |
for (j = 0; j < idxlastbar; j++) { |
for (j = 0; j < idxlastbar; j++) { |
| 856 |
uint64_t in; |
uint64_t in; |
| 857 |
uint64_t out; |
uint64_t out; |
| 858 |
|
|
| 859 |
print_indentation(); |
print_indentation(); |
| 860 |
printf("Bar #%u of %u:\n", j + 1, idxlastbar); |
printf("Bar #%u of %hhu:\n", |
| 861 |
|
j + 1, idxlastbar); |
| 862 |
|
|
| 863 |
in = read64u(); |
in = read64u(); |
| 864 |
|
|
| 865 |
indent(); |
indent(); |
| 866 |
print_indentation(); |
print_indentation(); |
| 867 |
printf("In %lu\n", in); |
printf("In %llu\n", |
| 868 |
|
(unsigned long long)in); |
| 869 |
|
|
| 870 |
out = read64u(); |
out = read64u(); |
| 871 |
|
|
| 872 |
print_indentation(); |
print_indentation(); |
| 873 |
printf("Out %lu\n", out); |
printf("Out %llu\n", |
| 874 |
|
(unsigned long long)out); |
| 875 |
|
|
| 876 |
exdent(); |
exdent(); |
| 877 |
} // for |
} // for |
| 878 |
exdent(); |
exdent(); |
| 879 |
|
|
| 880 |
exdent(); |
exdent(); |
| 881 |
} // for |
} // for |
| 882 |
|
|
| 883 |
exdent(); |
exdent(); |
| 884 |
} // decode_graph_db_v1() |
} // decode_graph_db_v1() |
| 885 |
|
|
| 886 |
void handle_file_error(void); |
void handle_file_error(void); |
| 887 |
|
|
| 888 |
uint8_t read8u(void) |
uint8_t read8u(void) |
| 889 |
{ |
{ |
| 1018 |
|
|
| 1019 |
#ifdef __LITTLE_ENDIAN__ |
#ifdef __LITTLE_ENDIAN__ |
| 1020 |
p2[1] = ntohl(p1[0]); |
p2[1] = ntohl(p1[0]); |
| 1021 |
p2[0] = ntohl(p1[1]); |
p2[0] = ntohl(p1[1]); |
| 1022 |
v = tmp; |
v = tmp; |
| 1023 |
#endif |
#endif |
| 1024 |
|
|
| 1025 |
return v; |
return v; |
| 1026 |
} // read64s() |
} // read64s() |
| 1027 |
|
|
| 1028 |
void handle_file_error(void) |
void handle_file_error(void) |
| 1029 |
{ |
{ |
| 1030 |
int saved_errno = errno; |
int saved_errno = errno; |
| 1031 |
|
|
| 1032 |
if (feof(file) != 0) { |
if (feof(file) != 0) { |
| 1033 |
fprintf(stderr, "%s:%s:%ld: premature end-of-file\n", progname, filename, ftell(file)); |
fprintf(stderr, |
| 1034 |
|
"%s:%s:%ld: premature end-of-file\n", |
| 1035 |
|
progname, filename, ftell(file)); |
| 1036 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 1037 |
} // if |
} // if |
| 1038 |
|
|
| 1039 |
if (ferror(file) != 0) { |
if (ferror(file) != 0) { |
| 1040 |
fprintf(stderr, "%s:%s:%ld: file error, errno = %s (%d)\n", progname, filename, ftell(file), strerror(saved_errno), saved_errno); |
fprintf(stderr, |
| 1041 |
|
"%s:%s:%ld: file error, errno = %s (%d)\n", |
| 1042 |
|
progname, filename, ftell(file), |
| 1043 |
|
strerror(saved_errno), saved_errno); |
| 1044 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 1045 |
} // if |
} // if |
| 1046 |
} // handle_file_error() |
} // handle_file_error() |
| 1047 |
|
|
| 1048 |
int64_t indentation = 0LL; |
int64_t indentation = 0LL; |
| 1049 |
|
|
| 1050 |
void indent(void) |
void indent(void) |
| 1051 |
{ |
{ |
| 1052 |
if (indentation < (INT64_MAX - 2LL)) { |
if (indentation < (INT64_MAX - 2LL)) { |
| 1053 |
indentation += 2LL; |
indentation += 2LL; |
| 1054 |
} // if |
} // if |
| 1055 |
} // indent() |
} // indent() |
| 1056 |
|
|
| 1057 |
void exdent(void) |
void exdent(void) |
| 1058 |
{ |
{ |
| 1071 |
putchar(' '); |
putchar(' '); |
| 1072 |
} // for |
} // for |
| 1073 |
} // print_indentation() |
} // print_indentation() |
| 1074 |
|
|
| 1075 |
void print_time_t(time_t t) |
void print_time_t(time_t t) |
| 1076 |
{ |
{ |
| 1077 |
struct tm *stm; |
struct tm *stm; |
| 1078 |
char buffer[1024]; |
char buffer[1024]; |
| 1079 |
|
|
| 1080 |
stm = gmtime(&t); |
stm = gmtime(&t); |
| 1081 |
|
|
| 1082 |
// ISO 8601 format |
// ISO 8601 format |
| 1083 |
if (strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S%z", stm) == 0) { |
if (strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%S%z", stm) == 0) { |
| 1084 |
int saved_errno = errno; |
int saved_errno = errno; |
| 1085 |
|
|
| 1086 |
fprintf(stderr, "%s:%s:%ld: strftime() error, errno = %s (%d)\n", progname, filename, ftell(file), strerror(saved_errno), saved_errno); |
fprintf(stderr, |
| 1087 |
|
"%s:%s:%ld: strftime() error, errno = %s (%d)\n", |
| 1088 |
|
progname, filename, ftell(file), |
| 1089 |
|
strerror(saved_errno), saved_errno); |
| 1090 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
| 1091 |
} // if |
} // if |
| 1092 |
|
|
| 1093 |
fputs(buffer, stdout); |
fputs(buffer, stdout); |
| 1094 |
} // print_time_t() |
} // print_time_t() |
| 1095 |
|
|
| 1096 |
// darkstattype.c |
// darkstattype.c |