c++ - Get proper IP and MAC addres in Winsock -


i'm trying external ip , mac address using winsock. on computer have installed virtualbox. when trying ip , mac address of computer 2 addresses. 1 computer , 1 virtualbox. here function ip , mac addresses:

long netutils::getlocalipaddress() {     if( localipaddress == -1)     {         wsadata wsadata;         if (wsastartup(makeword(1, 1), &wsadata) != 0) {             std::cout << "wsastartup error " << "wsagetlasterror" <<std::endl;             localipaddress = -1;             wsacleanup();             return localipaddress;         }          char ac[80];         if (gethostname(ac, sizeof(ac)) == socket_error) {             std::cout << "error " << wsagetlasterror() <<" when getting local host name." << std::endl;             localipaddress = -1;             wsacleanup();             return localipaddress;         }          struct hostent *phe = gethostbyname(ac);         if (phe == 0) {             std::cout << "yow! bad host lookup." << std::endl;             localipaddress = -1;             wsacleanup();             return localipaddress;         }          (int = 0; phe->h_addr_list[i] != 0; ++i) {             struct in_addr addr;             memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr));             std::cout << "address " << << ": " << inet_ntoa(addr) << " - "  << addr.s_un.s_addr << std::endl;         }          wsacleanup();         return localipaddress;     } }  long netutils::getlocalmacaddress() {     ip_adapter_info adapterinfo[16];       // allocate information      // 16 nics     dword dwbuflen = sizeof(adapterinfo);  // save memory size of buffer      dword dwstatus = getadaptersinfo(      // call getadapterinfo         adapterinfo,                 // [out] buffer receive data         &dwbuflen);                  // [in] size of receive data buffer     assert(dwstatus == error_success);  // verify return value      // valid, no buffer overflow      pip_adapter_info padapterinfo = adapterinfo; // contains pointer     // current adapter info     {         printmacaddress(padapterinfo->address); // print mac address         padapterinfo = padapterinfo->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]);  } 

in program need ip , mac of computer. how can check addresses adresses of computer , else?


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -