bool FindPartnerIP(const IPAddress& ip, IPAddress& partner) { Interfaces interfaces; Interfaces::const_iterator it; for (it = interfaces.begin(); it != interfaces.end(); ++it) { Interface::const_iterator it2 = std::find(it->second.begin(), it->second.end(), ip); if (it2 != it->second.end()) break; } if (it != interfaces.end()) { for (Interface::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) { if (it2->Family() == IPFamily::IPv4) { partner = *it2; return true; } } } return false; }
int main() { using namespace util::net; Interfaces interfaces; for (Interfaces::const_iterator it1 = interfaces.begin(); it1 != interfaces.end(); ++it1) { std::cout << it1->first << std::endl; for (Interface::const_iterator it2 = it1->second.begin(); it2 != it1->second.end(); ++it2) { std::cout << "\t" << *it2 << std::endl; } } }