문제

sniffex.c libpcap을 기반으로하는 프로그램이며, 일부 패킷 정보를 스니핑하고 표시합니다. URG, ACK, PSH, RST, SYN 및 FIN 인 TCP 플래그 값을 인쇄하기 위해 어떻게 수정합니까? 도와주세요..

도움이 되었습니까?

해결책

Sniff_TCP가 사용되는이 코드를 확인하면 인쇄하십시오.th_flags 이 구조의 구성원이 필요한 콘티안 깃발.

/* TCP header */
    struct sniff_tcp {
        u_short th_sport;   /* source port */
        u_short th_dport;   /* destination port */
        tcp_seq th_seq;     /* sequence number */
        tcp_seq th_ack;     /* acknowledgement number */

        u_char th_offx2;    /* data offset, rsvd */
    #define TH_OFF(th)  (((th)->th_offx2 & 0xf0) >> 4)
        u_char th_flags;
    #define TH_FIN 0x01
    #define TH_SYN 0x02
    #define TH_RST 0x04
    #define TH_PUSH 0x08
    #define TH_ACK 0x10
    #define TH_URG 0x20
    #define TH_ECE 0x40
    #define TH_CWR 0x80
    #define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
        u_short th_win;     /* window */
        u_short th_sum;     /* checksum */
        u_short th_urp;     /* urgent pointer */
};

일반적으로 당신은 이와 같은 것을 가질 것입니다 (약간 추악하면 더 잘할 수 있습니다) :

//this is already there in the code:
    printf("   Src port: %d\n", ntohs(tcp->th_sport));
    printf("   Dst port: %d\n", ntohs(tcp->th_dport))

//you add:
    if (tcp->th_flags & TH_ECE){
        printf("   Flag: TH_ECE");
    }
    if (tcp->th_flags & TH_RST){
        printf("   Flag: TH_RST");
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top