2019-05-28 15:15:37 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2019-06-03 12:32:52 +00:00
|
|
|
#include "cap_utils.h"
|
2019-05-28 15:15:37 +00:00
|
|
|
#include "packet.h"
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2019-06-03 12:32:52 +00:00
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
|
printf("~ capdiff ~\n");
|
|
|
|
|
2019-05-28 15:15:37 +00:00
|
|
|
if (argc != 3) {
|
2019-06-03 12:32:52 +00:00
|
|
|
fprintf(stderr, "Usage %s FILE1 FILE2\n", argv[0]);
|
2019-05-28 15:15:37 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
uint8_t verbose = 0;
|
|
|
|
|
2019-06-03 12:32:52 +00:00
|
|
|
struct cap_file cf[2];
|
|
|
|
for (int i = 0; i < 2; i++) cap_load(&cf[i], argv[i+1]);
|
2019-05-28 15:15:37 +00:00
|
|
|
|
2019-06-03 12:32:52 +00:00
|
|
|
if (cf[0].sz != cf[1].sz) {
|
2019-05-28 15:15:37 +00:00
|
|
|
printf("[!!] %s has %ld entries, %s has %ld entries\n",
|
|
|
|
argv[1],
|
2019-06-03 12:32:52 +00:00
|
|
|
cf[0].sz/sizeof(struct buffer_packet),
|
2019-05-28 15:15:37 +00:00
|
|
|
argv[2],
|
2019-06-03 12:32:52 +00:00
|
|
|
cf[1].sz/sizeof(struct buffer_packet));
|
2019-05-28 15:15:37 +00:00
|
|
|
} else if (verbose) {
|
|
|
|
printf("[OK] %s and %s have %ld entries\n",
|
|
|
|
argv[1],
|
|
|
|
argv[2],
|
2019-06-03 12:32:52 +00:00
|
|
|
cf[0].sz/sizeof(struct buffer_packet));
|
2019-05-28 15:15:37 +00:00
|
|
|
}
|
|
|
|
|
2019-06-03 12:32:52 +00:00
|
|
|
size_t to_read = cf[0].sz < cf[1].sz ? cf[0].sz : cf[1].sz;
|
2019-05-28 15:15:37 +00:00
|
|
|
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++) {
|
2019-06-03 12:32:52 +00:00
|
|
|
for (int i = 0; i < 2; i++) cap_next_bp(&cf[i], &bpread[i]);
|
2019-05-28 15:15:37 +00:00
|
|
|
/*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);
|
|
|
|
}*/
|
|
|
|
|
2019-05-28 15:35:21 +00:00
|
|
|
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;
|
2019-05-28 15:15:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-05-28 15:35:21 +00:00
|
|
|
|
2019-05-28 15:15:37 +00:00
|
|
|
size_t max_size = s1 > s2 ? s1 : s2;
|
2019-05-28 15:40:49 +00:00
|
|
|
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++) {
|
2019-05-28 15:35:21 +00:00
|
|
|
char e1 = (&bpread[0].ip.ap.raw)[idx], e2 = (&bpread[1].ip.ap.raw)[idx];
|
2019-05-28 15:15:37 +00:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
|
2019-06-03 12:32:52 +00:00
|
|
|
for (int i = 0; i < 2; i++) cap_unload (&cf[i]);
|
2019-05-28 15:15:37 +00:00
|
|
|
|
2019-05-28 15:35:21 +00:00
|
|
|
printf("parsed %d packets\n", expected_id);
|
2019-05-28 15:15:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|