title: Get Peer IP Address and Port
body: <p>I manage to get the host information from particular requested network adapter using code below but i have no idea how to get peer ip address from host ip address.  </p>
  
  <pre><code>struct sockaddr_in *sa = (struct sockaddr_in *)&amp;item-&gt;ifr_addr;
      ipAddr = ntohl(*((u_int32_t *)&amp;sa-&gt;sin_addr));
      if (pIpAddr != NULL)
      {
          *pIpAddr = ipAddr;
      }
  
      // Get the MAC address
      if ( ioctl(s, SIOCGIFHWADDR, item) &lt; 0 )
      {
          printf("_GetMacAddress : SIOCGIFHWADDR failed!\n");
          return 0;
      }
      else
      {
          struct sockaddr *eth = (struct sockaddr *) &amp;item-&gt;ifr_ifru.ifru_hwaddr;
          unsigned long *low = (unsigned long *)&amp;eth-&gt;sa_data[2];
          unsigned short *high = (unsigned short*)&amp;eth-&gt;sa_data[0];
          //printf("%s : MAC = 0x%04x, 0x%08x", ntohs(*high), ntohl(*low));
  
          printf("Interface %8s : IP %3d.%3d.%3d.%3d : MAC = %02x:%02x:%02x:%02x:%02x:%02x\n",
              item-&gt;ifr_name,
              ((ipAddr &gt;&gt; 24)&amp;0xff), ((ipAddr &gt;&gt; 16)&amp;0xff), ((ipAddr &gt;&gt; 8)&amp;0xff), (ipAddr&amp;0xff),
              ((ntohs(*high)&gt;&gt; 8)&amp;0x00ff), (ntohs(*high)&amp;0x00ff),
              ((ntohl(*low)&gt;&gt; 24)&amp;0x00ff), ((ntohl(*low)&gt;&gt; 16)&amp;0x00ff), ((ntohl(*low)&gt;&gt; 8)&amp;0x00ff), (ntohl(*low)&amp;0x00ff));
  
          if ((pMacHigh != NULL) &amp;&amp; (pMacLow != NULL))
          {
              *pMacHigh = *high;
              *pMacLow = *low;
          }
      }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>_GetMaxNetworkInterfaces 3
  Interface       lo : IP 127.  0.  0.  1 : MAC = 00:00:00:00:00:00
  Interface   enp4s0 : IP 192.168.128. 88 : MAC = f4:8e:38:ea:88:23
  Interface   wlp5s0 : IP 192.168. 53. 63 : MAC = b8:81:98:b7:71:90
  </code></pre>