【转载】linux环境下tcpdump源代码分析
生活随笔
收集整理的這篇文章主要介紹了
【转载】linux环境下tcpdump源代码分析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
linux環境下tcpdump源代碼分析
原文鏈接 ?http://blog.csdn.net/han_dawei/article/details/12615199 主題?Tcpdump?源碼分析 作者:韓大衛 @ 吉林師范大學 tcpdump.c 是tcpdump 工具的main.c, 本文旨對tcpdump的框架有簡單了解,只展示linux平臺使用的一部分核心代碼。 Tcpdump 的使用目的就是打印出指定條件的報文,即使有再多的正則表達式作為過濾條件。所以只要懂得tcpdump -nXXi eth0 的實現原理即可。 進入main之前,先看一些頭文件 netdissect.h里定義了一個數據結構struct netdissect_options來描述tcdpump支持的所有參數動作,每一個參數有對應的flag, 在tcpdump 的main 里面, 會根據用戶的傳入的參數來增加相應flag數值, 最后根據這些flag數值來實現特定動作。各個參數含義請參考源代碼注釋。 struct netdissect_options { int ndo_aflag; /* translate network and broadcast addresses */ //打印出以太網頭部 int ndo_eflag; /* print ethernet header */ int ndo_fflag; /* don't translate "foreign" IP address */ int ndo_Kflag; /* don't check TCP checksums */ //不將地址轉換為名字 int ndo_nflag; /* leave addresses as numbers */ int ndo_Nflag; /* remove domains from printed host names */ int ndo_qflag; /* quick (shorter) output */ int ndo_Rflag; /* print sequence # field in AH/ESP*/ int ndo_sflag; /* use the libsmi to translate OIDs */ int ndo_Sflag; /* print raw TCP sequence numbers */ // 報文到達時間 int ndo_tflag; /* print packet arrival time */ int ndo_Uflag; /* "unbuffered" output of dump files */ int ndo_uflag; /* Print undecoded NFS handles */ //詳細信息 int ndo_vflag; /* verbose */ // 十六進制打印報文 int ndo_xflag; /* print packet in hex */ // 十六進制和ASCII碼打印報文 int ndo_Xflag; /* print packet in hex/ascii */ //以ASCII碼顯示打印報文 int ndo_Aflag; /* print packet only in ascii observing TAB, * LF, CR and SPACE as graphical chars */ ... //默認的打印函數 void (*ndo_default_print)(netdissect_options *, register const u_char *bp, register u_int length); void (*ndo_info)(netdissect_options *, int verbose); ... } interface.h 接口頭文件,定義了一堆宏就為了方便調用struct netdissect_options里的成員。轉載于:https://www.cnblogs.com/Recan/p/6034520.html
總結
以上是生活随笔為你收集整理的【转载】linux环境下tcpdump源代码分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 表单打印功能
- 下一篇: MySQL之练习题5