fixed ip addr output

This commit is contained in:
2025-05-19 14:19:17 +02:00
parent 02be5f8ac1
commit 5f4180862d

View File

@ -317,12 +317,17 @@ int main(int argc, char** argv) {
clock_gettime(CLOCK_MONOTONIC, &recvt);
struct ip* ip_header = (struct ip*)buf;
struct ip *cp = (struct ip*) ((unsigned char*)ip_header + (ip_header->ip_hl << 2) + sizeof(struct icmphdr));
struct ip* cp =
(struct ip*)((unsigned char*)ip_header + (ip_header->ip_hl << 2) + sizeof(struct icmphdr));
char strip[INET_ADDRSTRLEN] = {0};
char strip2[INET_ADDRSTRLEN] = {0};
inet_ntop(AF_INET, &(cp->ip_src.s_addr), strip, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(cp->ip_dst.s_addr), strip2, INET_ADDRSTRLEN);
char strip3[INET_ADDRSTRLEN] = {0};
char strip4[INET_ADDRSTRLEN] = {0};
inet_ntop(AF_INET, &(ip_header->ip_src.s_addr), strip, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(ip_header->ip_dst.s_addr), strip2, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(cp->ip_src.s_addr), strip3, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(cp->ip_dst.s_addr), strip4, INET_ADDRSTRLEN);
struct icmphdr* icmp_reply = (struct icmphdr*)(buf + (ip_header->ip_hl << 2));
if (icmp_reply->type != ICMP_ECHOREPLY) {
@ -343,7 +348,7 @@ int main(int argc, char** argv) {
printf("%d bytes from %s: %s\n", ntohs(ip_header->ip_len) - (ip_header->ip_hl << 2), strip, str);
if (arguments.verbose) {
print_ip_hdr(cp, strip, strip2);
print_ip_hdr(cp, strip3, strip4);
}
if (!stop)