c++ - Multiple default gateways getting -


i have program in c++ getting default gateway, works okay until try on pc witch has few default gateways. here code:

dword err,adapterinfosize =0;     pip_adapter_info padapterinfo, padapt;     if ((err = getadaptersinfo(null, &adapterinfosize)) != 0) {         if (err != error_buffer_overflow){             std::cout<<"error s05\n";             cin.ignore();         }     }     if ((padapterinfo = (pip_adapter_info) globalalloc(gptr, adapterinfosize)) == null) {         std::cout<<"error s06\n";         cin.ignore();     }     if ((err = getadaptersinfo(padapterinfo, &adapterinfosize)) != 0) {         std::cout<<"error s07\n";         cin.ignore();     }     padapt = padapterinfo;     while (padapt){         dfltgw = padapt->gatewaylist.ipaddress.string;         break;     }     padapt = padapterinfo;     cout << endl << "default gateway: " << dfltgw << endl; 

on pc have virtual network of virtualbox output: 0.0.0.0 , on pc have 1 default gateway right ip.

so how can fix it?

fixed adding:

for (int izjson = 0; izjson < 50; izjson++) {         string checkdf = padapterinfo->gatewaylist.ipaddress.string;         if(checkdf != "0.0.0.0") {             dfltgw = checkdf;             break;         }         padapterinfo = padapterinfo->next; // next adapter info     } 

thanks @sergeya


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -