#include #include #include "packet.h" int main(int argc, char** argv) { if (argc != 3) { fprintf(stderr, "Usage %s ./cap.0 ./cap.1\n", argv[0]); exit(EXIT_FAILURE); } uint8_t verbose = 0; FILE *fd[2]; size_t sz[2]; for (int i = 0; i < 2; i++) { if ((fd[i] = fopen(argv[i+1], "r")) == NULL) { perror("Unable to open file"); exit(EXIT_FAILURE); } fseek(fd[i], 0, SEEK_END); sz[i] = ftell(fd[i]); fseek(fd[i], 0, SEEK_SET); } if (sz[0] != sz[1]) { printf("[!!] %s has %ld entries, %s has %ld entries\n", argv[1], sz[0]/sizeof(struct buffer_packet), argv[2], sz[1]/sizeof(struct buffer_packet)); } else if (verbose) { printf("[OK] %s and %s have %ld entries\n", argv[1], argv[2], sz[0]/sizeof(struct buffer_packet)); } size_t to_read = sz[0] < sz[1] ? sz[0] : sz[1]; 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++) fread(&bpread[i], sizeof(struct buffer_packet), 1, fd[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++) { fclose(fd[i]); } printf("parsed %d packets\n", expected_id); return 0; }