int VBoxNetDhcp::hostDnsServers(const ComHostPtr& host, const RTNETADDRIPV4& networkid, const AddressToOffsetMapping& mapping, AddressList& servers) { ComBstrArray strs; HRESULT hrc = host->COMGETTER(NameServers)(ComSafeArrayAsOutParam(strs)); if (FAILED(hrc)) return VERR_NOT_FOUND; /* * Recent fashion is to run dnsmasq on 127.0.1.1 which we * currently can't map. If that's the only nameserver we've got, * we need to use DNS proxy for VMs to reach it. */ bool fUnmappedLoopback = false; for (size_t i = 0; i < strs.size(); ++i) { RTNETADDRIPV4 addr; int rc; rc = RTNetStrToIPv4Addr(com::Utf8Str(strs[i]).c_str(), &addr); if (RT_FAILURE(rc)) continue; if (addr.au8[0] == 127) { AddressToOffsetMapping::const_iterator remap(mapping.find(addr)); if (remap != mapping.end()) { int offset = remap->second; addr.u = RT_H2N_U32(RT_N2H_U32(networkid.u) + offset); } else { fUnmappedLoopback = true; continue; } } servers.push_back(addr); } if (servers.empty() && fUnmappedLoopback) { RTNETADDRIPV4 proxy; proxy.u = networkid.u | RT_H2N_U32_C(1U); servers.push_back(proxy); } return VINF_SUCCESS; }
/** * @note: const dropped here, because of map<K,V>::operator[] which isn't const, map<K,V>::at() has const * variant but it's C++11. */ int hostDnsServers(const ComHostPtr& host, const RTNETADDRIPV4& networkid, /*const*/ AddressToOffsetMapping& mapping, AddressList& servers) { servers.clear(); ComBstrArray strs; if (SUCCEEDED(host->COMGETTER(NameServers)(ComSafeArrayAsOutParam(strs)))) { RTNETADDRIPV4 addr; int rc; for (unsigned int i = 0; i < strs.size(); ++i) { rc = RTNetStrToIPv4Addr(com::Utf8Str(strs[i]).c_str(), &addr); if (RT_SUCCESS(rc)) { if (addr.au8[0] == 127) { /* XXX: here we want map<K,V>::at(const K& k) const */ if (mapping[addr] != 0) { addr.u = RT_H2N_U32(RT_N2H_U32(networkid.u) + mapping[addr]); } else continue; /* XXX: Warning here (local mapping wasn't registered) */ } servers.push_back(addr); } } } else return VERR_NOT_FOUND; return VINF_SUCCESS; }
int SearchTask::valueSearchResults() { const int cbRate = 15; int scans = 0; int length; unsigned int readLen; unsigned long section, size; char finalDumpBytes[3]; char *dataBuf; switch (m_searchValueType) { case SEARCH_VALUE_TYPE_1BYTE: length = 1; break; case SEARCH_VALUE_TYPE_2BYTE: length = 2; break; default: length = 4; break; } unsigned resListSize = getNumberOfResults(*m_results); for (ResultList::iterator it=m_results->begin(); it!=m_results->end(); ++it) //read each section { if (it->second.size() == 0) continue; AddressList keep; m_valueSearcher.clear(); section = it->first; size = it->second.size(); if (size > 10) //lets grab the chunk! { if (m_cancel) return TASK_ERROR_CANCEL; if (section+RANGE_INTERVAL < 0xFFFFFFFF-3 && m_ccapi->readMemory(section+RANGE_INTERVAL, 3) == 0) { dataBuf = m_ccapi->getData(readLen); memcpy(finalDumpBytes, dataBuf, readLen); } if (m_ccapi->readMemory(section, RANGE_INTERVAL) == 0) { dataBuf = m_ccapi->getData(readLen); if (m_ccapi->insertData(readLen, finalDumpBytes, 3)) { for (AddressList::iterator addrIt = it->second.begin(); addrIt != it->second.end();) //read all addresses in a section { if (m_valueSearcher.digestValue(&dataBuf[((*addrIt)->address) - section], *addrIt, section)) //we need to keep it! keep.push_back(*addrIt); addrIt++; if (scans % cbRate == 0) progressCallback(this, scans, resListSize); scans++; } it->second = keep; } } } else { for (AddressList::iterator addrIt = it->second.begin(); addrIt != it->second.end();) //read all addresses in asection { if (m_cancel) return TASK_ERROR_CANCEL; if (m_ccapi->readMemory(((*addrIt)->address), length) == 0) { dataBuf = m_ccapi->getData(readLen); if (m_valueSearcher.digestValue(dataBuf, *addrIt, section)) //we need to keep it! keep.push_back(*addrIt); addrIt++; if (scans % cbRate == 0) progressCallback(this, scans, resListSize); scans++; } } it->second = keep; } } m_taskState = Task::COMPLETE; progressCallback(this, resListSize, resListSize); return TASK_ERROR_NONE; }