You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.4 KiB

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>
// Packet dump function for debugging
static void dump_packet(const char* direction, const uint8_t* data, size_t len, struct sockaddr_storage* addr) {
printf("[DUMP] %s packet: %zd bytes ", direction, len);
// Print address if provided
if (addr) {
if (addr->ss_family == AF_INET) {
struct sockaddr_in* sin = (struct sockaddr_in*)addr;
printf("to/from %s:%d ",
inet_ntoa(sin->sin_addr),
ntohs(sin->sin_port));
}
}
// Print first 64 bytes
printf("data: ");
for (size_t i = 0; i < len && i < 64; i++) {
printf("%02x", data[i]);
if (i % 4 == 3) printf(" ");
}
if (len > 64) printf("...");
// If it's INIT packet, parse fields
if (len > 0 && data[0] == 0x02) { // ETCP_INIT_REQUEST
if (len >= 15) { // Minimum INIT size: code(1) + node_id(8) + mtu(2) + keepalive(2) + pubkey(2 at least)
uint64_t node_id = 0;
memcpy(&node_id, data + 1, 8);
uint16_t mtu = (data[9] << 8) | data[10];
uint16_t keepalive = (data[11] << 8) | data[12];
printf(" | INIT: node_id=%llu mtu=%d keepalive=%d",
(unsigned long long)node_id, mtu, keepalive);
}
}
printf("\n");
}