I'm trying to compare the values in these two char pointers but i'm getting strange outputs:
The first one is (libpcap IP address):
const char* ip_source = inet_ntop(AF_INET, &ip->ip_src, buffer1, sizeof(buffer1)); //192.168.56.1
The second one is:
char *host_ip = inet_ntoa(((struct sockaddr_in*)a->addr)->sin_addr); //192.168.56.1
I've tried using if (*ip_source == *host_ip)
, if (strcmp(ip_source, host_ip) == 0)
and if (strncmp(ip_source, host_ip, strlen(host_ip))
.
How do I compare the IP addresses stored in these two variables to see if both IP addresses are the same?
This is the code:
if (strncmp(ip_source, host_ip, strlen(host_ip)) == 0) // if sent local > remote
{
printf(" RST/ACK Detected [Local > Remote]\n");
}
else // if sent remote > local
{
printf(" RST/ACK Detected [Remote > Local]\n");
}
This is the result:
Packet number 2386:
current time: 2015-04-11 15:07:59.412
From(src): 192.168.56.1 <---- Local (IP stored in *host_ip)
To(dst): 192.168.56.2 <---- Remote
Protocol: TCP
Src port: 1864
Dst port: 49750
Seq Num: 0
Ack Num: 3556812524
RST/ACK Detected [Remote > Local] <--- Wrong
In this case it's returning -2