///////////////// // Performs a search for the given IP, returns a record with information about the IP GeoRecord GeoIPDatabase::lookup(const std::string& ip) const { GeoRecord res; if (!m_file) return res; // IP check unsigned long l_ip = convertIp(ip); if (!l_ip) { res.continentCode = "UN"; res.countryCode = "HCK"; res.countryCode3 = "HCK"; res.countryName = "Hackerland"; res.region = "Pirate area"; res.city = "No City"; return res; } // Find the record int record = seekRecord(l_ip); // Get information if (m_dbType == GEOIP_CITY_EDITION_REV0 || m_dbType == GEOIP_CITY_EDITION_REV1) return extractRecordCity(record); else if (m_dbType == GEOIP_COUNTRY_EDITION) return extractRecordCtry(record); errors << "The Geo IP database has an unsupported format" << endl; return res; }
int main (int argc, char** argv) { char* str = argv[1]; int* res = convertIp(str); if (res == NULL) printf("Invalid input\n"); else { for (int i = 0; i < 4; i++) printf("%d ", res[i]); printf("\n"); } }
void TopologyDialog::getEdgeInfo() { qDebug() << "get edge info"; QByteArray datagram; QHostAddress address; QDataStream in(&datagram, QIODevice::ReadOnly); char msgRecv[256]; char dstIp[256]; char nextHop[256]; int nread = 0; int count; do { datagram.resize(udpSocket->pendingDatagramSize()); udpSocket->readDatagram(datagram.data(), datagram.size(), &address); } while(udpSocket->hasPendingDatagrams()); nread = in.readRawData(msgRecv, 256); if (nread > 0) { msgRecv[nread ] = '\0'; qDebug() << QString(msgRecv) << address.toString(); count = getEdgeCount(msgRecv); for (int i = 0; i < count; i++) { sscanf(msgRecv + i*16, "%8s%8s", dstIp, nextHop); convertIp(dstIp); convertIp(nextHop); qDebug() << "dstIp:" << dstIp << "nextHop:" << nextHop; if (QString(nextHop) == "0.0.0.0") { addToGraph(address.toString(), dstIp); } else { addToGraph(address.toString(), nextHop); } } } }