本文整理汇总了C++中Sniffer::getTcpSEQ方法的典型用法代码示例。如果您正苦于以下问题:C++ Sniffer::getTcpSEQ方法的具体用法?C++ Sniffer::getTcpSEQ怎么用?C++ Sniffer::getTcpSEQ使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sniffer
的用法示例。
在下文中一共展示了Sniffer::getTcpSEQ方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processPacket
void processPacket(u_char *args, const struct pcap_pkthdr* pkthdr, const u_char* packet)
{
Sniffer *snf = (Sniffer *)args;
map<string, ConnInfo>::iterator it;
u_long dstIp = snf->getDstIpRaw(packet);
int dstPort = snf->getTcpDstPort(packet);
if(snf->isRst(packet)) {
if(v)cout << "Got RST-ACK packet from " << snf->getSrcIp(packet) << " to " << snf->getDstIp(packet) << endl;
} else if(snf->isFin(packet)) {
if(v)cout << "Got FIN-ACK packet from " << snf->getSrcIp(packet) << " to " << snf->getDstIp(packet) << endl;
pthread_mutex_lock(&connMutex);
it = connsEstab.find(connId(dstIp, dstPort));
if(it != connsEstab.end()) { // we received FIN for an established TCP connection
connsEstab.erase(it); // delete the established connections
pthread_mutex_unlock(&connMutex);
pthread_mutex_lock(&countMutex);
(*snf->finNo)++; // increase number of finished connections
pthread_mutex_unlock(&countMutex);
} else {
pthread_mutex_unlock(&connMutex);
}
} else {
if(v)cout << "Got SYN-ACK packet from " << snf->getSrcIp(packet) << " to " << snf->getDstIp(packet) << endl;
}
pthread_mutex_lock(&connMutex);
it = connsInited.find(connId(dstIp, dstPort));
if(it != connsInited.end()) {
if(v)cout << "Found session " << endl;
connsInited.erase(it);
pthread_mutex_unlock(&connMutex);
if(snf->isRst(packet)) {
pthread_mutex_lock(&countMutex);
(*snf->rstNo)++;
pthread_mutex_unlock(&countMutex);
return;
} else if(snf->isFin(packet)) {
pthread_mutex_lock(&countMutex);
(*snf->finNo)++;
pthread_mutex_unlock(&countMutex);
return;
}
Pkt pkt; //This is the ACK packet that we send
pkt.srcIp = snf->getDstIpRaw(packet);
pkt.dstIp = snf->getSrcIpRaw(packet);
pkt.srcPort = snf->getTcpDstPort(packet);
pkt.dstPort = snf->getTcpSrcPort(packet);
pkt.seqn = snf->getTcpACK(packet);
pkt.ackn = snf->getTcpSEQ(packet) + 1;
pthread_mutex_lock(&ackMutex);
pktsToSend.push_back(pkt); //ACKs will be sent from this queue (to complete 3-way handshake)
pthread_mutex_unlock(&ackMutex);
} else {
pthread_mutex_unlock(&connMutex);
}
}