bool DpdkDeviceList::verifyHugePagesAndDpdkDriver() { std::string execResult = executeShellCommand("cat /proc/meminfo | grep -s HugePages_Total | awk '{print $2}'"); // trim '\n' at the end execResult.erase(std::remove(execResult.begin(), execResult.end(), '\n'), execResult.end()); // convert the result to long char* endPtr; long totalHugePages = strtol(execResult.c_str(), &endPtr, 10); LOG_DEBUG("Total number of huge-pages is %lu", totalHugePages); if (totalHugePages <= 0) { LOG_ERROR("Huge pages aren't set, DPDK cannot be initialized. Please run <PcapPlusPlus_Root>/setup_dpdk.sh"); return false; } execResult = executeShellCommand("lsmod | grep -s igb_uio"); if (execResult == "") { LOG_ERROR("igb_uio driver isn't loaded, DPDK cannot be initialized. Please run <PcapPlusPlus_Root>/setup_dpdk.sh"); return false; } else LOG_DEBUG("igb_uio driver is loaded"); return true; }
void ChatSession::slotLinkClicked(const QString& link) { QStringList list = DomUtil::readListEntry(*m_dom,"/urls/available","type"); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) if(QString(link).startsWith(*it)) executeShellCommand(DomUtil::readEntry(*m_dom,QString("/urls/" + *it + "/command")).replace(QRegExp("%l"),link)); }
void PcapLiveDeviceList::setDnsServers() { #ifdef WIN32 FIXED_INFO * fixedInfo; ULONG ulOutBufLen; DWORD dwRetVal; IP_ADDR_STRING * pIPAddr; uint8_t buf1[sizeof(FIXED_INFO)]; fixedInfo = (FIXED_INFO *) buf1; ulOutBufLen = sizeof( FIXED_INFO ); dwRetVal = GetNetworkParams( fixedInfo, &ulOutBufLen ); uint8_t buf2[ulOutBufLen]; if(ERROR_BUFFER_OVERFLOW == dwRetVal) { fixedInfo = (FIXED_INFO *)buf2; } if ((dwRetVal = GetNetworkParams( fixedInfo, &ulOutBufLen )) != 0) LOG_ERROR("Call to GetNetworkParams failed. Return Value: %08lx\n", dwRetVal); else { m_DnsServers.push_back(IPv4Address(fixedInfo->DnsServerList.IpAddress.String)); int i = 1; LOG_DEBUG("Default DNS server IP #%d: %s\n", i++, fixedInfo->DnsServerList.IpAddress.String ); pIPAddr = fixedInfo->DnsServerList.Next; while ( pIPAddr ) { m_DnsServers.push_back(IPv4Address(pIPAddr->IpAddress.String)); LOG_DEBUG("Default DNS server IP #%d: %s\n", i++, pIPAddr->IpAddress.String); pIPAddr = pIPAddr -> Next; } } #elif LINUX std::string command = "nmcli dev list | grep IP4.DNS"; std::string dnsServersInfo = executeShellCommand(command); if (dnsServersInfo == "") { LOG_DEBUG("Error retrieving DNS server list: call to nmcli gave no output"); return; } std::istringstream stream(dnsServersInfo); std::string line; int i = 1; while(std::getline(stream, line)) { std::istringstream lineStream(line); std::string headline; std::string dnsIP; lineStream >> headline; lineStream >> dnsIP; IPv4Address dnsIPAddr(dnsIP); if (!dnsIPAddr.isValid()) continue; if (std::find(m_DnsServers.begin(), m_DnsServers.end(), dnsIPAddr) == m_DnsServers.end()) { m_DnsServers.push_back(dnsIPAddr); LOG_DEBUG("Default DNS server IP #%d: %s\n", i++, dnsIPAddr.toString().c_str()); } } #elif MAC_OS_X SCDynamicStoreRef dynRef = SCDynamicStoreCreate(kCFAllocatorSystemDefault, CFSTR("iked"), NULL, NULL); if (dynRef == NULL) { LOG_DEBUG("Couldn't set DNS server list: failed to retrieve SCDynamicStore"); return; } CFDictionaryRef dnsDict = (CFDictionaryRef)SCDynamicStoreCopyValue(dynRef,CFSTR("State:/Network/Global/DNS")); if (dnsDict == NULL) { LOG_DEBUG("Couldn't set DNS server list: failed to get DNS dictionary"); CFRelease(dynRef); return; } CFArrayRef serverAddresses = (CFArrayRef)CFDictionaryGetValue(dnsDict, CFSTR("ServerAddresses")); if (serverAddresses == NULL) { LOG_DEBUG("Couldn't set DNS server list: server addresses array is null"); CFRelease(dynRef); CFRelease(dnsDict); return; } CFIndex count = CFArrayGetCount(serverAddresses); for (CFIndex i = 0; i < count; i++) { CFStringRef serverAddress = (CFStringRef)CFArrayGetValueAtIndex(serverAddresses, i); if (serverAddress == NULL) continue; uint8_t buf[20]; char* serverAddressCString = (char*)buf; CFStringGetCString(serverAddress, serverAddressCString, 20, kCFStringEncodingUTF8); m_DnsServers.push_back(IPv4Address(serverAddressCString)); LOG_DEBUG("Default DNS server IP #%d: %s\n", (int)(i+1), serverAddressCString); } CFRelease(dynRef); CFRelease(dnsDict); #endif }
void PcapLiveDevice::setDefaultGateway() { #ifdef WIN32 ULONG outBufLen = sizeof (IP_ADAPTER_INFO); uint8_t buffer[outBufLen]; PIP_ADAPTER_INFO adapterInfo = (IP_ADAPTER_INFO*)buffer; DWORD retVal = 0; retVal = GetAdaptersInfo(adapterInfo, &outBufLen); uint8_t buffer2[outBufLen]; if (retVal == ERROR_BUFFER_OVERFLOW) adapterInfo = (IP_ADAPTER_INFO *)buffer2; retVal = GetAdaptersInfo(adapterInfo, &outBufLen); if (retVal == NO_ERROR) { PIP_ADAPTER_INFO curAdapterInfo = adapterInfo; while (curAdapterInfo != NULL) { std::string name(m_Name); if (name.find(curAdapterInfo->AdapterName) != std::string::npos) m_DefaultGateway = IPv4Address(curAdapterInfo->GatewayList.IpAddress.String); curAdapterInfo = curAdapterInfo->Next; } } else { LOG_ERROR("Error retrieving default gateway address"); } #elif LINUX std::ifstream routeFile("/proc/net/route"); std::string line; while (std::getline(routeFile, line)) { std::stringstream lineStream(line); std::string interfaceName; std::getline(lineStream, interfaceName, '\t'); if (interfaceName != std::string(m_Name)) continue; std::string interfaceDest; std::getline(lineStream, interfaceDest, '\t'); if (interfaceDest != "00000000") continue; std::string interfaceGateway; std::getline(lineStream, interfaceGateway, '\t'); uint32_t interfaceGatewayIPInt; std::stringstream interfaceGatewayStream; interfaceGatewayStream << std::hex << interfaceGateway; interfaceGatewayStream >> interfaceGatewayIPInt; m_DefaultGateway = IPv4Address(interfaceGatewayIPInt); } #elif MAC_OS_X std::string ifaceStr = std::string(m_Name); std::string command = "netstat -nr | grep default | grep " + ifaceStr; std::string ifaceInfo = executeShellCommand(command); if (ifaceInfo == "") { LOG_DEBUG("Error retrieving default gateway address: couldn't get netstat output"); return; } // remove the word "default" ifaceInfo.erase(0, 7); // remove spaces while (ifaceInfo.at(0) == ' ') ifaceInfo.erase(0,1); // erase string after gateway IP address ifaceInfo.resize(ifaceInfo.find(' ', 0)); m_DefaultGateway = IPv4Address(ifaceInfo); #endif }