fixed ip addr output
This commit is contained in:
15
srcs/main.c
15
srcs/main.c
@ -162,7 +162,7 @@ double nsqrt(double a, double prec) {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_ip_hdr(struct ip* ip_header, char * ipsrc, char *ipdst) {
|
void print_ip_hdr(struct ip* ip_header, char* ipsrc, char* ipdst) {
|
||||||
printf("IP Hdr dump:\n ");
|
printf("IP Hdr dump:\n ");
|
||||||
for (size_t i = 0; i < sizeof(*ip_header); i++) {
|
for (size_t i = 0; i < sizeof(*ip_header); i++) {
|
||||||
printf("%02x", *((unsigned char*)ip_header + i));
|
printf("%02x", *((unsigned char*)ip_header + i));
|
||||||
@ -317,12 +317,17 @@ int main(int argc, char** argv) {
|
|||||||
clock_gettime(CLOCK_MONOTONIC, &recvt);
|
clock_gettime(CLOCK_MONOTONIC, &recvt);
|
||||||
|
|
||||||
struct ip* ip_header = (struct ip*)buf;
|
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 strip[INET_ADDRSTRLEN] = {0};
|
||||||
char strip2[INET_ADDRSTRLEN] = {0};
|
char strip2[INET_ADDRSTRLEN] = {0};
|
||||||
inet_ntop(AF_INET, &(cp->ip_src.s_addr), strip, INET_ADDRSTRLEN);
|
char strip3[INET_ADDRSTRLEN] = {0};
|
||||||
inet_ntop(AF_INET, &(cp->ip_dst.s_addr), strip2, INET_ADDRSTRLEN);
|
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));
|
struct icmphdr* icmp_reply = (struct icmphdr*)(buf + (ip_header->ip_hl << 2));
|
||||||
|
|
||||||
if (icmp_reply->type != ICMP_ECHOREPLY) {
|
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);
|
printf("%d bytes from %s: %s\n", ntohs(ip_header->ip_len) - (ip_header->ip_hl << 2), strip, str);
|
||||||
|
|
||||||
if (arguments.verbose) {
|
if (arguments.verbose) {
|
||||||
print_ip_hdr(cp, strip, strip2);
|
print_ip_hdr(cp, strip3, strip4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stop)
|
if (!stop)
|
||||||
|
Reference in New Issue
Block a user