Bez popisu

sniffer_8h_source.html 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.9.1"/>
  7. <title>My Project: sniffer.h Source File</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  12. <script type="text/javascript" src="search/searchdata.js"></script>
  13. <script type="text/javascript" src="search/search.js"></script>
  14. <script type="text/javascript">
  15. $(document).ready(function() { init_search(); });
  16. </script>
  17. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  18. </head>
  19. <body>
  20. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  21. <div id="titlearea">
  22. <table cellspacing="0" cellpadding="0">
  23. <tbody>
  24. <tr style="height: 56px;">
  25. <td style="padding-left: 0.5em;">
  26. <div id="projectname">My Project
  27. </div>
  28. </td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. </div>
  33. <!-- end header part -->
  34. <!-- Generated by Doxygen 1.8.9.1 -->
  35. <script type="text/javascript">
  36. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  37. </script>
  38. <div id="navrow1" class="tabs">
  39. <ul class="tablist">
  40. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  41. <li><a href="annotated.html"><span>Classes</span></a></li>
  42. <li class="current"><a href="files.html"><span>Files</span></a></li>
  43. <li>
  44. <div id="MSearchBox" class="MSearchBoxInactive">
  45. <span class="left">
  46. <img id="MSearchSelect" src="search/mag_sel.png"
  47. onmouseover="return searchBox.OnSearchSelectShow()"
  48. onmouseout="return searchBox.OnSearchSelectHide()"
  49. alt=""/>
  50. <input type="text" id="MSearchField" value="Search" accesskey="S"
  51. onfocus="searchBox.OnSearchFieldFocus(true)"
  52. onblur="searchBox.OnSearchFieldFocus(false)"
  53. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  54. </span><span class="right">
  55. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  56. </span>
  57. </div>
  58. </li>
  59. </ul>
  60. </div>
  61. <div id="navrow2" class="tabs2">
  62. <ul class="tablist">
  63. <li><a href="files.html"><span>File&#160;List</span></a></li>
  64. </ul>
  65. </div>
  66. </div><!-- top -->
  67. <!-- window showing the filter options -->
  68. <div id="MSearchSelectWindow"
  69. onmouseover="return searchBox.OnSearchSelectShow()"
  70. onmouseout="return searchBox.OnSearchSelectHide()"
  71. onkeydown="return searchBox.OnSearchSelectKey(event)">
  72. </div>
  73. <!-- iframe showing the search results (closed by default) -->
  74. <div id="MSearchResultsWindow">
  75. <iframe src="javascript:void(0)" frameborder="0"
  76. name="MSearchResults" id="MSearchResults">
  77. </iframe>
  78. </div>
  79. <div class="header">
  80. <div class="headertitle">
  81. <div class="title">sniffer.h</div> </div>
  82. </div><!--header-->
  83. <div class="contents">
  84. <div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="preprocessor">#ifndef SNIFFER_H</span></div>
  85. <div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="preprocessor">#define SNIFFER_H</span></div>
  86. <div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;</div>
  87. <div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="preprocessor">#include &lt;QObject&gt;</span></div>
  88. <div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="preprocessor">#include &lt;QString&gt;</span></div>
  89. <div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="preprocessor">#include &lt;QDebug&gt;</span></div>
  90. <div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="preprocessor">#include &quot;ip_packet.h&quot;</span></div>
  91. <div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="preprocessor">#include &lt;QWaitCondition&gt;</span></div>
  92. <div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;<span class="preprocessor">#include &lt;QMutex&gt;</span></div>
  93. <div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160;</div>
  94. <div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="preprocessor">#include &lt;pcap.h&gt;</span></div>
  95. <div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
  96. <div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;<span class="preprocessor">#include &lt;string.h&gt;</span></div>
  97. <div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
  98. <div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<span class="preprocessor">#include &lt;ctype.h&gt;</span></div>
  99. <div class="line"><a name="l00016"></a><span class="lineno"> 16</span>&#160;<span class="preprocessor">#include &lt;cstring&gt;</span></div>
  100. <div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;<span class="preprocessor">#include &lt;errno.h&gt;</span></div>
  101. <div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="preprocessor">#include &lt;sys/types.h&gt;</span></div>
  102. <div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="preprocessor">#include &lt;sys/socket.h&gt;</span></div>
  103. <div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="preprocessor">#include &lt;netinet/in.h&gt;</span></div>
  104. <div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="preprocessor">#include &lt;arpa/inet.h&gt;</span></div>
  105. <div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;<span class="preprocessor">#include &quot;ethernet_hdr.h&quot;</span></div>
  106. <div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;<span class="preprocessor">#include &quot;ip_hdr.h&quot;</span></div>
  107. <div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="preprocessor">#include &quot;tcp_hdr.h&quot;</span></div>
  108. <div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;<span class="preprocessor">#include &quot;udp_hdr.h&quot;</span></div>
  109. <div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;</div>
  110. <div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160;<span class="comment">/* default snap length (maximum bytes per packet to capture) */</span></div>
  111. <div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160;<span class="preprocessor">#define SNAP_LEN 1518</span></div>
  112. <div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160;</div>
  113. <div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160;<span class="comment">/* ethernet headers are always exactly 14 bytes [1] */</span></div>
  114. <div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160;<span class="preprocessor">#define SIZE_ETHERNET 14</span></div>
  115. <div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160;</div>
  116. <div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160;<span class="preprocessor">#define IPV4 8</span></div>
  117. <div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;<span class="keyword">class </span><a class="code" href="class_sniffer.html">Sniffer</a> : <span class="keyword">public</span> QObject</div>
  118. <div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;{</div>
  119. <div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160; Q_OBJECT</div>
  120. <div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;</div>
  121. <div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160;<span class="keyword">public</span>:</div>
  122. <div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160;</div>
  123. <div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; <a class="code" href="class_sniffer.html#a8039cbd5f487a357321d57337a664d3d">Sniffer</a>() ;</div>
  124. <div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160;</div>
  125. <div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160; <a class="code" href="class_sniffer.html#a8039cbd5f487a357321d57337a664d3d">Sniffer</a>(QWaitCondition *pw, QMutex *mx, <span class="keywordtype">int</span> *ps) ;</div>
  126. <div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160;</div>
  127. <div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160; <a class="code" href="class_sniffer.html#a8ad3b97292e2cc274f31d87701f92be2">~Sniffer</a>() ;</div>
  128. <div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160;</div>
  129. <div class="line"><a name="l00084"></a><span class="lineno"> 84</span>&#160; vector&lt;ip_packet&gt; * <a class="code" href="class_sniffer.html#a791027d276cfcc5e6849132ecf8e80b6">getPacketList</a>() ;</div>
  130. <div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160;</div>
  131. <div class="line"><a name="l00098"></a><span class="lineno"> 98</span>&#160; <span class="keywordtype">string</span> <a class="code" href="class_sniffer.html#a3dd95c60c5b8554e1bedc22b36ae488c">format_payload</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *payload, <span class="keywordtype">int</span> len);</div>
  132. <div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160;</div>
  133. <div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160; <span class="keywordtype">string</span> <a class="code" href="class_sniffer.html#a02101b56a75804d1ed39a1c04ba36ab2">format_hex_ascii_line</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *payload, <span class="keywordtype">int</span> len, <span class="keywordtype">int</span> offset);</div>
  134. <div class="line"><a name="l00115"></a><span class="lineno"> 115</span>&#160;</div>
  135. <div class="line"><a name="l00124"></a><span class="lineno"> 124</span>&#160; <span class="keywordtype">void</span> <a class="code" href="class_sniffer.html#a94d7cd87d0f181c3cf2e5ec851e370b6">find_devices</a>(vector&lt;string&gt; &amp;) ;</div>
  136. <div class="line"><a name="l00125"></a><span class="lineno"> 125</span>&#160;</div>
  137. <div class="line"><a name="l00133"></a><span class="lineno"> 133</span>&#160; <span class="keywordtype">void</span> <a class="code" href="class_sniffer.html#ab706811aa2b285e4c0f55491703c105a">setDevice</a>(<span class="keywordtype">string</span>) ;</div>
  138. <div class="line"><a name="l00134"></a><span class="lineno"> 134</span>&#160;</div>
  139. <div class="line"><a name="l00135"></a><span class="lineno"> 135</span>&#160;<span class="keyword">public</span> slots:</div>
  140. <div class="line"><a name="l00136"></a><span class="lineno"> 136</span>&#160; <span class="keywordtype">void</span> <a class="code" href="class_sniffer.html#a6fc78b66d2f4dce0cc3662dacf171514">process</a>() ;</div>
  141. <div class="line"><a name="l00137"></a><span class="lineno"> 137</span>&#160;</div>
  142. <div class="line"><a name="l00138"></a><span class="lineno"> 138</span>&#160;signals:</div>
  143. <div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160; <span class="keywordtype">void</span> resultReady(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> index);</div>
  144. <div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160;</div>
  145. <div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160;<span class="keyword">private</span>:</div>
  146. <div class="line"><a name="l00142"></a><span class="lineno"> 142</span>&#160;</div>
  147. <div class="line"><a name="l00143"></a><span class="lineno"> 143</span>&#160; vector&lt;ip_packet&gt; packet_list ;</div>
  148. <div class="line"><a name="l00144"></a><span class="lineno"> 144</span>&#160; QWaitCondition *wait_pause ;</div>
  149. <div class="line"><a name="l00145"></a><span class="lineno"> 145</span>&#160; QMutex * mutex ;</div>
  150. <div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; <span class="keywordtype">string</span> device ;</div>
  151. <div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; <span class="keywordtype">string</span> filter ;</div>
  152. <div class="line"><a name="l00148"></a><span class="lineno"> 148</span>&#160; <span class="keywordtype">int</span> *pause ;</div>
  153. <div class="line"><a name="l00149"></a><span class="lineno"> 149</span>&#160;</div>
  154. <div class="line"><a name="l00159"></a><span class="lineno"> 159</span>&#160; <span class="keywordtype">void</span> <a class="code" href="class_sniffer.html#ac05f935a6ec2830d6bf42b607f071910">print_payload</a>(<span class="keyword">const</span> u_char *payload, <span class="keywordtype">int</span> len);</div>
  155. <div class="line"><a name="l00160"></a><span class="lineno"> 160</span>&#160;</div>
  156. <div class="line"><a name="l00172"></a><span class="lineno"> 172</span>&#160; <span class="keywordtype">void</span> <a class="code" href="class_sniffer.html#a70598d5001a30cc8e801f1262770cdf6">print_hex_ascii_line</a>(<span class="keyword">const</span> u_char *payload, <span class="keywordtype">int</span> len, <span class="keywordtype">int</span> offset);</div>
  157. <div class="line"><a name="l00173"></a><span class="lineno"> 173</span>&#160;</div>
  158. <div class="line"><a name="l00183"></a><span class="lineno"> 183</span>&#160; <span class="keywordtype">void</span></div>
  159. <div class="line"><a name="l00184"></a><span class="lineno"> 184</span>&#160; <a class="code" href="class_sniffer.html#a0179e32fee6a0f7c2a13f37d64a7fae0">got_packet</a>(<span class="keyword">const</span> <span class="keyword">struct</span> pcap_pkthdr *header, <span class="keyword">const</span> u_char *packet);</div>
  160. <div class="line"><a name="l00185"></a><span class="lineno"> 185</span>&#160;</div>
  161. <div class="line"><a name="l00186"></a><span class="lineno"> 186</span>&#160;};</div>
  162. <div class="line"><a name="l00187"></a><span class="lineno"> 187</span>&#160;</div>
  163. <div class="line"><a name="l00188"></a><span class="lineno"> 188</span>&#160;<span class="preprocessor">#endif // SNIFFER_H</span></div>
  164. <div class="ttc" id="class_sniffer_html_a0179e32fee6a0f7c2a13f37d64a7fae0"><div class="ttname"><a href="class_sniffer.html#a0179e32fee6a0f7c2a13f37d64a7fae0">Sniffer::got_packet</a></div><div class="ttdeci">void got_packet(const struct pcap_pkthdr *header, const u_char *packet)</div><div class="ttdoc">Disects the received packet. Takes out the info needed. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:394</div></div>
  165. <div class="ttc" id="class_sniffer_html_a3dd95c60c5b8554e1bedc22b36ae488c"><div class="ttname"><a href="class_sniffer.html#a3dd95c60c5b8554e1bedc22b36ae488c">Sniffer::format_payload</a></div><div class="ttdeci">string format_payload(const char *payload, int len)</div><div class="ttdoc">Formats the payload from a byte stream into a string of ascci. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:342</div></div>
  166. <div class="ttc" id="class_sniffer_html_a8ad3b97292e2cc274f31d87701f92be2"><div class="ttname"><a href="class_sniffer.html#a8ad3b97292e2cc274f31d87701f92be2">Sniffer::~Sniffer</a></div><div class="ttdeci">~Sniffer()</div><div class="ttdoc">Destructor, does nothing. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:35</div></div>
  167. <div class="ttc" id="class_sniffer_html_a6fc78b66d2f4dce0cc3662dacf171514"><div class="ttname"><a href="class_sniffer.html#a6fc78b66d2f4dce0cc3662dacf171514">Sniffer::process</a></div><div class="ttdeci">void process()</div><div class="ttdoc">The sniffer is run as a separate thread and the function process is the main function of the thread...</div><div class="ttdef"><b>Definition:</b> sniffer.cpp:45</div></div>
  168. <div class="ttc" id="class_sniffer_html_a70598d5001a30cc8e801f1262770cdf6"><div class="ttname"><a href="class_sniffer.html#a70598d5001a30cc8e801f1262770cdf6">Sniffer::print_hex_ascii_line</a></div><div class="ttdeci">void print_hex_ascii_line(const u_char *payload, int len, int offset)</div><div class="ttdoc">Prints to std output the a payload in ascii. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:157</div></div>
  169. <div class="ttc" id="class_sniffer_html_ac05f935a6ec2830d6bf42b607f071910"><div class="ttname"><a href="class_sniffer.html#ac05f935a6ec2830d6bf42b607f071910">Sniffer::print_payload</a></div><div class="ttdeci">void print_payload(const u_char *payload, int len)</div><div class="ttdoc">Prints the payload in ascii. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:278</div></div>
  170. <div class="ttc" id="class_sniffer_html_ab706811aa2b285e4c0f55491703c105a"><div class="ttname"><a href="class_sniffer.html#ab706811aa2b285e4c0f55491703c105a">Sniffer::setDevice</a></div><div class="ttdeci">void setDevice(string)</div><div class="ttdoc">Sets the device to capture packets to dev. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:561</div></div>
  171. <div class="ttc" id="class_sniffer_html_a791027d276cfcc5e6849132ecf8e80b6"><div class="ttname"><a href="class_sniffer.html#a791027d276cfcc5e6849132ecf8e80b6">Sniffer::getPacketList</a></div><div class="ttdeci">vector&lt; ip_packet &gt; * getPacketList()</div><div class="ttdoc">Returns the packet list that contains the packets that are Ethernet -> IP -> (TCP|UDP) ...</div><div class="ttdef"><b>Definition:</b> sniffer.cpp:520</div></div>
  172. <div class="ttc" id="class_sniffer_html_a94d7cd87d0f181c3cf2e5ec851e370b6"><div class="ttname"><a href="class_sniffer.html#a94d7cd87d0f181c3cf2e5ec851e370b6">Sniffer::find_devices</a></div><div class="ttdeci">void find_devices(vector&lt; string &gt; &amp;)</div><div class="ttdoc">Find the network devices in the computer, and store them in vector devs. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:533</div></div>
  173. <div class="ttc" id="class_sniffer_html_a8039cbd5f487a357321d57337a664d3d"><div class="ttname"><a href="class_sniffer.html#a8039cbd5f487a357321d57337a664d3d">Sniffer::Sniffer</a></div><div class="ttdeci">Sniffer()</div><div class="ttdoc">Constructor, does nothing. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:8</div></div>
  174. <div class="ttc" id="class_sniffer_html_a02101b56a75804d1ed39a1c04ba36ab2"><div class="ttname"><a href="class_sniffer.html#a02101b56a75804d1ed39a1c04ba36ab2">Sniffer::format_hex_ascii_line</a></div><div class="ttdeci">string format_hex_ascii_line(const char *payload, int len, int offset)</div><div class="ttdoc">Return string with the bytes of a payload line in ascii. </div><div class="ttdef"><b>Definition:</b> sniffer.cpp:219</div></div>
  175. <div class="ttc" id="class_sniffer_html"><div class="ttname"><a href="class_sniffer.html">Sniffer</a></div><div class="ttdoc">The Sniffer class is the one that use the pcap library to extract the packet information. It discards any packet that is not Ethernet->IP->(TCP|UDP), and pass up to the GUI the packets that are Ethernet->IP->(TCP|UDP). </div><div class="ttdef"><b>Definition:</b> sniffer.h:40</div></div>
  176. </div><!-- fragment --></div><!-- contents -->
  177. <!-- start footer part -->
  178. <hr class="footer"/><address class="footer"><small>
  179. Generated on Wed Jun 24 2015 15:25:12 for My Project by &#160;<a href="http://www.doxygen.org/index.html">
  180. <img class="footer" src="doxygen.png" alt="doxygen"/>
  181. </a> 1.8.9.1
  182. </small></address>
  183. </body>
  184. </html>