fixed ip addr output
This commit is contained in:
13
srcs/main.c
13
srcs/main.c
@ -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)
|
||||
|
Reference in New Issue
Block a user