当前位置: 首页>>代码示例>>C++>>正文


C++ Sniffer::isFin方法代码示例

本文整理汇总了C++中Sniffer::isFin方法的典型用法代码示例。如果您正苦于以下问题:C++ Sniffer::isFin方法的具体用法?C++ Sniffer::isFin怎么用?C++ Sniffer::isFin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sniffer的用法示例。


在下文中一共展示了Sniffer::isFin方法的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);
    }
}
开发者ID:keyeMyria,项目名称:Attack,代码行数:61,代码来源:1_captureThread.cpp


注:本文中的Sniffer::isFin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。