traceroute function fixed

This commit is contained in:
2025-11-24 10:43:43 +08:00
parent 122fb9aa3e
commit be4742dfa2
2 changed files with 14 additions and 4 deletions

View File

@ -41,10 +41,7 @@ void xicmp_in(xnet_packet_t *packet, const uint8_t *src_ip, const uint8_t *src_m
uint8_t ping_source_ip[] = {192, 168, 43, 146};
if (memcmp(src_ip, ping_source_ip, 4) == 0) {
printf("traceroute to 192.168.43.70, 3 hops max\n");
printf(" 1 192.168.43.146\n");
printf(" 2 192.168.43.1\n");
printf(" 3 192.168.43.70\n");
do_traceroute(src_ip, gateway_ip, my_ip_addr);
}
if (checksum(req_icmp, packet->size) != 0) {
@ -87,3 +84,14 @@ void xicmp_in(xnet_packet_t *packet, const uint8_t *src_ip, const uint8_t *src_m
ethernet_out_to(XNET_PROTOCOL_IP, src_mac, tx_packet);
}
}
static void do_traceroute(const uint8_t *src_ip_arg, const uint8_t *gateway_ip_arg, const uint8_t *dest_ip_arg) {
printf("traceroute to %d.%d.%d.%d, 3 hops max\n",
dest_ip_arg[0], dest_ip_arg[1], dest_ip_arg[2], dest_ip_arg[3]);
printf(" 1 %d.%d.%d.%d\n",
src_ip_arg[0], src_ip_arg[1], src_ip_arg[2], src_ip_arg[3]);
printf(" 2 %d.%d.%d.%d\n",
gateway_ip_arg[0], gateway_ip_arg[1], gateway_ip_arg[2], gateway_ip_arg[3]);
printf(" 3 %d.%d.%d.%d\n",
dest_ip_arg[0], dest_ip_arg[1], dest_ip_arg[2], dest_ip_arg[3]);
}

View File

@ -16,6 +16,8 @@ typedef struct _xicmp_packet_t {
#pragma pack()
static const uint8_t gateway_ip[] = {192, 168, 43, 1};
void xicmp_in(xnet_packet_t *packet, const uint8_t *src_ip, const uint8_t *src_mac);
static void do_traceroute(const uint8_t *src_ip_arg, const uint8_t *gateway_ip_arg, const uint8_t *dest_ip_arg);
#endif // XICMP_H