pcap結構–pcap_t資料類型

來源:互聯網
上載者:User

struct pcap [pcap-int.h]
{
    int fd; /* 檔案描述字,實際就是 socket */
    
        /* 在 socket 上,可以使用 select() 和 poll() 等 I/O 複用類型函數 */
    int selectable_fd;

    int snapshot; /* 使用者期望的捕獲資料包最大長度 */
    int linktype; /* 裝置類型 */
    int tzoff;        /* 時區位置,實際上沒有被使用 */
    int offset;    /* 邊界對齊位移量 */

    int break_loop; /* 強制從讀資料包迴圈中跳出的標誌 */

    struct pcap_sf sf; /* 資料包儲存到檔案的相關配置資料結構 */
    struct pcap_md md; /* 具體描述如下 */
    
    int bufsize; /* 讀緩衝區的長度 */
    u_char buffer; /* 讀緩衝區指標 */
    u_char *bp;
    int cc;
    u_char *pkt;

    /* 相關抽象操作的函數指標,最終指向特定作業系統的處理函數 */
    int    (*read_op)(pcap_t *, int cnt, pcap_handler, u_char *);
    int    (*setfilter_op)(pcap_t *, struct bpf_program *);
    int    (*set_datalink_op)(pcap_t *, int);
    int    (*getnonblock_op)(pcap_t *, char *);
    int    (*setnonblock_op)(pcap_t *, int, char *);
    int    (*stats_op)(pcap_t *, struct pcap_stat *);
    void (*close_op)(pcap_t *);

    /*如果 BPF 過濾代碼不能在核心中執行,則將其儲存並在使用者空間執行 */
    struct bpf_program fcode;

    /* 函數調用出錯資訊緩衝區 */
    char errbuf[PCAP_ERRBUF_SIZE + 1];
    
    /* 當前裝置支援的、可更改的資料鏈路類型的個數 */
    int dlt_count;
    /* 可更改的資料鏈路類型號鏈表,在 linux 下沒有使用 */
    int *dlt_list;

    /* 資料包自訂頭部,對資料包捕獲時間、捕獲長度、真實長度進行描述 [pcap.h] */
    struct pcap_pkthdr pcap_header;    
};

/* 包含了捕獲控制代碼的介面、狀態、過濾資訊  [pcap-int.h] */
struct pcap_md {
/* 捕獲狀態結構  [pcap.h] */
struct pcap_stat stat;  

    int use_bpf; /* 如果為1,則代表使用核心過濾*/
    u_long    TotPkts;
    u_long    TotAccepted; /* 被接收資料包數目 */
    u_long    TotDrops;    /* 被丟棄資料包數目 */
    long    TotMissed;    /* 在過濾進行時被介面丟棄的資料包數目 */
    long    OrigMissed; /*在過濾進行前被介面丟棄的資料包數目*/
#ifdef linux
    int    sock_packet; /* 如果為 1,則代表使用 2.0 核心的 SOCK_PACKET 模式 */
    int    timeout;    /* pcap_open_live() 函數逾時返回時間*/
    int    clear_promisc; /* 關閉時設定介面為非混雜模式 */
    int    cooked;        /* 使用 SOCK_DGRAM 類型 */
    int    lo_ifindex;    /* 迴路裝置索引號 */
    char *device;    /* 介面裝置名稱 */
    
/* 以混雜模式開啟 SOCK_PACKET 類型 socket 的 pcap_t 鏈表*/
struct pcap *next;    
#endif
};

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.