#include #include #include "cap_utils.h" #include "packet.h" int main(int argc, char** argv) { setvbuf(stdout, NULL, _IONBF, 0); printf("~ capdiff ~\n"); if (argc != 3) { fprintf(stderr, "Usage %s FILE1 FILE2\n", argv[0]); exit(EXIT_FAILURE); } uint8_t verbose = 0; struct cap_file cf[2]; for (int i = 0; i < 2; i++) cap_load(&cf[i], argv[i+1]); if (cf[0].sz != cf[1].sz) { printf("[!!] %s has %ld entries, %s has %ld entries\n", argv[1], cf[0].sz/sizeof(struct buffer_packet), argv[2], cf[1].sz/sizeof(struct buffer_packet)); } else if (verbose) { printf("[OK] %s and %s have %ld entries\n", argv[1], argv[2], cf[0].sz/sizeof(struct buffer_packet)); } size_t to_read = cf[0].sz < cf[1].sz ? cf[0].sz : cf[1].sz; size_t to_read_obj = to_read / sizeof(struct buffer_packet); uint16_t expected_id = 0; struct buffer_packet bpread[2]; for (size_t c = 0; c < to_read_obj; c++) { for (int i = 0; i < 2; i++) cap_next_bp(&cf[i], &bpread[i]); /*if (expected_id != bpread[0].ip.ap.fmt.content.clear.id || expected_id != bpread[1].ip.ap.fmt.content.clear.id) { printf("[!!] expected id is %d, %s has id %d, %s has id %d\n", expected_id, argv[1], bpread[0].ip.ap.fmt.content.clear.id, argv[2], bpread[1].ip.ap.fmt.content.clear.id); }*/ size_t s1 = bpread[0].ip.ap.fmt.headers.size, s2 = bpread[1].ip.ap.fmt.headers.size; uint8_t is_same_size = s1 == s2; if (!is_same_size) { printf("[!!] %s packet has size %d, %s packet has size %d for expected id %d\n", argv[1], bpread[0].ip.ap.fmt.headers.size, argv[2], bpread[1].ip.ap.fmt.headers.size, expected_id); } else if (verbose) { printf("[OK] %s and %s packets for expected id %d have size %d\n", argv[1], argv[2], expected_id, bpread[0].ip.ap.fmt.headers.size); } size_t max_size = s1 > s2 ? s1 : s2; for (size_t idx = sizeof(bpread[0].ip.ap.fmt.headers) + sizeof(bpread[0].ip.ap.fmt.content.clear) - sizeof(char); idx < max_size; idx++) { char e1 = (&bpread[0].ip.ap.raw)[idx], e2 = (&bpread[1].ip.ap.raw)[idx]; if (e1 != e2) { printf("[!!] for expected id %d, byte 0x%04x is different: 0x%02x vs 0x%02x\n", expected_id, (uint16_t)idx, (uint8_t)e1, (uint8_t)e2); } } expected_id++; } for (int i = 0; i < 2; i++) cap_unload (&cf[i]); printf("parsed %d packets\n", expected_id); return 0; }