GeoIP::GeoIP(std::string input_file) { //Open file std::ifstream inputFile(input_file.c_str()); //Check file if(!inputFile.good()) { std::cerr << "Could not open input file '" << input_file << "'.\n"; } std::string line; //Loop through lines of the IP database file while(inputFile.good() && std::getline(inputFile, line)) { //Info std::vector< std::string > parsedLine; const std::string seperators = "\",\""; //Split lines split(parsedLine, line, seperators, true); //Make new IP Range and add range to the 'database' database.push_back(Range(Ip(parsedLine[0]), Ip(parsedLine[1]), parsedLine[5])); } std::cout << "Database constructed with " << database.size() << " items." << std::endl; }
Ip ClientSocket::receiveAnnounce(int port, char *message, int dataSize) { if (!udpBound) { udpBound = true; // bind struct sockaddr_in my_addr; my_addr.sin_family = AF_INET; // host byte order my_addr.sin_port = htons(port); // short, network byte order my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP memset(&(my_addr.sin_zero), 0, 8); // zero the rest of the struct if (bind(udpsockfd,(struct sockaddr*)&my_addr, sizeof(struct sockaddr)) == SOCKET_ERROR) { perror("bind error"); } } struct sockaddr_in their_addr; // connector’s address information int addr_len = sizeof(struct sockaddr); int numbytes = recvfrom(udpsockfd, message, dataSize - 1, 0, (struct sockaddr*)&their_addr, (socklen_t*)&addr_len); if (numbytes == SOCKET_ERROR) { throw SocketException("exiting receive"); } message[numbytes] = '\0'; return Ip(inet_ntoa(their_addr.sin_addr)); }
Expression* sintactico::Ip() { if(CurrentToken->tipo == ADMIRACION) { CurrentToken = Lexer->NexToken(); Expression* izq = J(); Expression* der = Ip(); if(der != NULL) return new exprDeni(der,Lexer->linea); return izq; } return NULL; }
//returns "c" which is the last index needed to get the last s-values key rmsMgSigStart(const keyM & pk, mgSig & rv, keyV aG, keyV aHP, const int index) { int rows = pk[0].size(); int cols = pk.size(); if (cols < 2) { printf("Error! What is c if cols = 1!"); } int i = 0, j = 0; key c, c_old, c0, L, R, Hi; sc_0(c_old.bytes); vector<ge_dsmp> Ip(rows); rv.ss = keyM(cols, rv.II); unsigned char m2[96]; for (i = 0; i < rows; i++) { memcpy(m2, pk[index][i].bytes, 32); memcpy(m2 + 32, aG[i].bytes, 32); memcpy(m2 + 64, aHP[i].bytes, 32); precomp(Ip[i], rv.II[i]); sc_add(c_old.bytes, c_old.bytes, cn_fast_hash96(m2).bytes); } int oldi = index; i = (index + 1) % cols; while (i != index) { rv.ss[i] = skvGen(rows); sc_0(c.bytes); for (j = 0; j < rows; j++) { addKeys2(L, rv.ss[i][j], c_old, pk[i][j]); hashToPoint(Hi, pk[i][j]); addKeys3(R, rv.ss[i][j], Hi, c_old, Ip[j]); memcpy(m2, pk[i][j].bytes, 32); memcpy(m2 + 32, L.bytes, 32); memcpy(m2 + 64, R.bytes, 32); sc_add(c.bytes, c.bytes, cn_fast_hash96(m2).bytes); } c_old = copy(c); if (i == 0) { c0 = copy(c); } oldi = i; i = (i + 1) % cols; } return c; }
// ---------------------------------------------------------------------------- // SnoopNetStatWin // ---------------------------------------------------------------------------- SnoopNetStatWin::SnoopNetStatWin() { dwTcpSize = 0; dwUdpSize = 0; pTcp = NULL; pUdp = NULL; if ( (hDLL = LoadLibraryA("Iphlpapi.dll")) == NULL ) { LOG_FATAL("fail to LoadLibrary 'Iphlpapi.dll'\n"); return; } GetExtendedTcpTable = (GetExtendedTcpTable_t)GetProcAddress(hDLL, "GetExtendedTcpTable"); GetExtendedUdpTable = (GetExtendedUdpTable_t)GetProcAddress(hDLL, "GetExtendedUdpTable"); if (GetExtendedTcpTable == NULL) { LOG_FATAL("GetExtendedTcpTable is null"); return; } if (GetExtendedUdpTable == NULL) { LOG_FATAL("GetExtendedUdpTable is null"); return; } SnoopInterfaces& intfs = SnoopInterfaces::instance(); for (int i = 1; i < intfs.count(); i++) { SnoopNetInfo netInfo; netInfo.adapterIndex = i; Ip ip = netInfo.ip; if (ip != 0) myIpList.push_back(ip); } myIpList.push_back(Ip("127.0.0.1")); foreach (Ip ip, myIpList) { LOG_DEBUG("ip=%s", qPrintable(ip.str())); }
Device::Device(int numberOfInterface, std::vector<std::string> names, std::vector<std::string> ip) { for(int i = 0; i < numberOfInterface; i++) { qDebug() << names.at(i).c_str(); addNetworkInterface(names.at(i), Mac(), Ip(ip.at(i), 24), true); } }