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