extern "C" void doAction(std::map<std::string, std::string> & postVars) { if(!postVars["default_gw"].empty()) { setDefaultGateway(postVars["default_gw"]); } std::vector<std::string> nameservers; for(std::map<std::string, std::string>::iterator it = postVars.begin(); it != postVars.end(); it++) { if(it->first.find("dns") != std::string::npos) { std::string defaultGW = "0.0.0.0"; if(IP::isValidHostIP(it->second, defaultGW)) { nameservers.push_back(it->second); } } } setNameservers(nameservers); for(std::vector<std::string>::iterator it = interfaces.begin(); it != interfaces.end(); it++) { std::string address = ""; std::string mask = ""; bool addressSet = false; bool maskSet = false; for(std::map<std::string, std::string>::iterator it2 = postVars.begin(); it2 != postVars.end(); it2++) { if(it2->first.find(*it) != std::string::npos) { if(it2->first == (*it + "_ip")) { address = it2->second; addressSet = true; } else if(it2->first == (*it + "_mask")) { mask = it2->second; maskSet = true; } else { } } } if(addressSet && maskSet) { setInterfaceAddress(*it, address, mask); } if(postVars[("enable_" + *it)] == "1") { setInterfaceStatus(*it, true); } else { setInterfaceStatus(*it, false); } } }
PcapLiveDevice::PcapLiveDevice(pcap_if_t* pInterface, bool calculateMTU, bool calculateMacAddress, bool calculateDefaultGateway) : IPcapDevice(), m_MacAddress(""), m_DefaultGateway(IPv4Address::Zero) { m_Name = NULL; m_Description = NULL; m_DeviceMtu = 0; m_IsLoopback = (pInterface->flags & 0x1) == PCAP_IF_LOOPBACK; int strLength = strlen(pInterface->name)+1; m_Name = new char[strLength]; strncpy((char*)m_Name, pInterface->name, strLength); strLength = 1; if (pInterface->description != NULL) strLength += strlen(pInterface->description); m_Description = new char[strLength]; if (pInterface->description != NULL) strncpy((char*)m_Description, pInterface->description, strLength); else strncpy((char*)m_Description, "", strLength); LOG_DEBUG("Added live device: name=%s; desc=%s", m_Name, m_Description); LOG_DEBUG(" Addresses:"); while (pInterface->addresses != NULL) { m_Addresses.insert(m_Addresses.end(), *(pInterface->addresses)); pInterface->addresses = pInterface->addresses->next; if (LoggerPP::getInstance().isDebugEnabled(PcapLogModuleLiveDevice) && pInterface->addresses != NULL && pInterface->addresses->addr != NULL) { char addrAsString[INET6_ADDRSTRLEN]; sockaddr2string(pInterface->addresses->addr, addrAsString); LOG_DEBUG(" %s", addrAsString); } } if (calculateMTU) { setDeviceMtu(); LOG_DEBUG(" MTU: %d", m_DeviceMtu); } if (calculateDefaultGateway) { setDefaultGateway(); LOG_DEBUG(" Default Gateway: %s", m_DefaultGateway.toString().c_str()); } //init all other members m_CaptureThreadStarted = false; m_StatsThreadStarted = false; m_IsLoopback = false; m_StopThread = false; m_CaptureThread = new PcapThread(); m_StatsThread = new PcapThread(); memset(m_CaptureThread, 0, sizeof(PcapThread)); memset(m_StatsThread, 0, sizeof(PcapThread)); m_cbOnPacketArrives = NULL; m_cbOnStatsUpdate = NULL; m_IntervalToUpdateStats = 0; m_cbOnPacketArrivesUserCookie = NULL; m_cbOnStatsUpdateUserCookie = NULL; m_CaptureCallbackMode = true; m_CapturedPackets = NULL; if (calculateMacAddress) { setDeviceMacAddress(); if (m_MacAddress.isValid()) LOG_DEBUG(" MAC addr: %s", m_MacAddress.toString().c_str()); } }