title: Get proper IP and MAC addres in Winsock
body: <p>I'm trying to get external IP and MAC address using Winsock. On my computer I have installed VirtualBox. When I trying to get IP and MAC address of my computer I get 2 addresses. One for computer and one for VirtualBox. Here is my function for get IP and MAC addresses:</p>
  
  <pre><code>long NetUtils::getLocalIpAddress()
  {
      if( localIpAddress == -1)
      {
          WSAData wsaData;
          if (WSAStartup(MAKEWORD(1, 1), &amp;wsaData) != 0) {
              std::cout &lt;&lt; "WSAStartup Error " &lt;&lt; "WSAGetLastError" &lt;&lt;std::endl;
              localIpAddress = -1;
              WSACleanup();
              return localIpAddress;
          }
  
          char ac[80];
          if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR) {
              std::cout &lt;&lt; "Error " &lt;&lt; WSAGetLastError() &lt;&lt;" when getting local host name." &lt;&lt; std::endl;
              localIpAddress = -1;
              WSACleanup();
              return localIpAddress;
          }
  
          struct hostent *phe = gethostbyname(ac);
          if (phe == 0) {
              std::cout &lt;&lt; "Yow! Bad host lookup." &lt;&lt; std::endl;
              localIpAddress = -1;
              WSACleanup();
              return localIpAddress;
          }
  
          for (int i = 0; phe-&gt;h_addr_list[i] != 0; ++i) {
              struct in_addr addr;
              memcpy(&amp;addr, phe-&gt;h_addr_list[i], sizeof(struct in_addr));
              std::cout &lt;&lt; "Address " &lt;&lt; i &lt;&lt; ": " &lt;&lt; inet_ntoa(addr) &lt;&lt; " - "  &lt;&lt; addr.S_un.S_addr &lt;&lt; std::endl;
          }
  
          WSACleanup();
          return localIpAddress;
      }
  }
  
  long NetUtils::getLocalMacAddress()
  {
      IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information 
      // for up to 16 NICs
      DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer
  
      DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
          AdapterInfo,                 // [out] buffer to receive data
          &amp;dwBufLen);                  // [in] size of receive data buffer
      assert(dwStatus == ERROR_SUCCESS);  // Verify return value is 
      // valid, no buffer overflow
  
      PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
      // current adapter info
      do {
          PrintMACaddress(pAdapterInfo-&gt;Address); // Print MAC address
          pAdapterInfo = pAdapterInfo-&gt;Next;    // Progress through 
          // linked list
      }
      while(pAdapterInfo);                    // Terminate if last adapter
  
      return 0;
  }
  
  void NetUtils::PrintMACaddress(unsigned char MACData[])
  {
      printf("%02X-%02X-%02X-%02X-%02X-%02X\n", 
      MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
  
  }
  </code></pre>
  
  <p>In my program I need to get only IP and MAC of my computer. How can I check what addresses is adresses of my computer and what is for something else?</p>