zoukankan      html  css  js  c++  java
  • packet32 -- 打印packet32捕获的包

    void PrintPackets(LPPACKET lpPacket)
    {
    
        ULONG    i, j, ulLines, ulen, ulBytesReceived;
        char    *pChar, *pLine, *base;
        char    *buf;
        u_int off=0;
        u_int tlen,tlen1;
        struct bpf_hdr *hdr;
    
        ulBytesReceived = lpPacket->ulBytesReceived;
    
    
        buf = lpPacket->Buffer;
    
        off=0;
    
        while(off<ulBytesReceived){    
            if(_kbhit())return;
            hdr=(struct bpf_hdr *)(buf+off);
            tlen1=hdr->bh_datalen;
            tlen=hdr->bh_caplen;
            printf("Packet length, captured portion: %ld, %ld
    ", tlen1, tlen);
            off+=hdr->bh_hdrlen;
    
            ulLines = (tlen + 15) / 16;
    
            pChar =(char*)(buf+off);
            base=pChar;
            off=Packet_WORDALIGN(off+tlen);
    
            //if(ulLines >10) ulLines = 10;
    
            for ( i=0; i<ulLines; i++ )
            {
    
                pLine =pChar;
    
                printf( "%08lx : ", pChar-base );
    
                ulen=tlen;
                ulen = ( ulen > 16 ) ? 16 : ulen;
                tlen -= ulen;
    
                for ( j=0; j<ulen; j++ )
                    printf( "%02x ", *(BYTE *)pChar++ );
    
                if ( ulen < 16 )
                    printf( "%*s", (16-ulen)*3, " " );
    
                pChar = pLine;
    
                for ( j=0; j<ulen; j++, pChar++ )
                    printf( "%c", isprint( (unsigned char)*pChar ) ? *pChar : '.' );
    
                printf( "
    " );
            } 
    
            printf( "
    " );
        }
    } 
  • 相关阅读:
    简单对拍
    搜索感想
    L1434滑雪
    记忆化搜索
    L3956棋盘
    USACO 数字三角形
    枚举顺序
    蓝桥计算
    用户态和内核态IO过程
    Mybatis的结果集中的Do要不要有setter
  • 原文地址:https://www.cnblogs.com/hei-hei-hei/p/7428869.html
Copyright © 2011-2022 走看看