Add capdiff to see differences between captures
This commit is contained in:
parent
c937c72b8a
commit
d53f58f568
2 changed files with 92 additions and 1 deletions
|
@ -41,6 +41,7 @@ add_executable(donar ${CSOURCES} src/donar.c)
|
||||||
add_executable(measlat ${CSOURCES} src/meas_lat.c)
|
add_executable(measlat ${CSOURCES} src/meas_lat.c)
|
||||||
add_executable(udpecho ${CSOURCES} src/udp_echo.c)
|
add_executable(udpecho ${CSOURCES} src/udp_echo.c)
|
||||||
add_executable(torecho ${CSOURCES} src/tor_echo.c)
|
add_executable(torecho ${CSOURCES} src/tor_echo.c)
|
||||||
|
add_executable(capdiff ${CSOURCES} src/capdiff.c)
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_search_module(GLIB REQUIRED glib-2.0)
|
pkg_search_module(GLIB REQUIRED glib-2.0)
|
||||||
|
@ -57,6 +58,9 @@ target_link_libraries(udpecho ${GLIB_LDFLAGS})
|
||||||
target_include_directories(torecho PRIVATE ${GLIB_INCLUDE_DIRS})
|
target_include_directories(torecho PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||||
target_link_libraries(torecho ${GLIB_LDFLAGS})
|
target_link_libraries(torecho ${GLIB_LDFLAGS})
|
||||||
|
|
||||||
install(TARGETS donar measlat udpecho torecho
|
target_include_directories(capdiff PRIVATE ${GLIB_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(capdiff ${GLIB_LDFLAGS})
|
||||||
|
|
||||||
|
install(TARGETS donar measlat udpecho torecho capdiff
|
||||||
RUNTIME DESTINATION bin
|
RUNTIME DESTINATION bin
|
||||||
LIBRARY DESTINATION lib)
|
LIBRARY DESTINATION lib)
|
||||||
|
|
87
src/capdiff.c
Normal file
87
src/capdiff.c
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#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);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
uint8_t is_same_size = bpread[0].ip.ap.fmt.headers.size == bpread[1].ip.ap.fmt.headers.size;
|
||||||
|
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 s1 = bpread[0].ip.ap.fmt.headers.size, s2 = bpread[1].ip.ap.fmt.headers.size;
|
||||||
|
size_t max_size = s1 > s2 ? s1 : s2;
|
||||||
|
for (size_t idx = 0; idx < max_size; idx++) {
|
||||||
|
char e1 = (&bpread[0].ip.ap.raw)[idx], e2 = (&bpread[0].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("done\n");
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue