Няма описание

class_sniffer.tex 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. \hypertarget{class_sniffer}{}\section{Sniffer Class Reference}
  2. \label{class_sniffer}\index{Sniffer@{Sniffer}}
  3. The \hyperlink{class_sniffer}{Sniffer} class is the one that use the pcap library to extract the packet information. It discards any packet that is not Ethernet-\/$>$I\+P-\/$>$(T\+C\+P$\vert$\+U\+D\+P), and pass up to the G\+U\+I the packets that are Ethernet-\/$>$I\+P-\/$>$(T\+C\+P$\vert$\+U\+D\+P).
  4. {\ttfamily \#include $<$sniffer.\+h$>$}
  5. Inheritance diagram for Sniffer\+:\begin{figure}[H]
  6. \begin{center}
  7. \leavevmode
  8. \includegraphics[height=2.000000cm]{class_sniffer}
  9. \end{center}
  10. \end{figure}
  11. \subsection*{Public Slots}
  12. \begin{DoxyCompactItemize}
  13. \item
  14. \hypertarget{class_sniffer_a6fc78b66d2f4dce0cc3662dacf171514}{}void \hyperlink{class_sniffer_a6fc78b66d2f4dce0cc3662dacf171514}{process} ()\label{class_sniffer_a6fc78b66d2f4dce0cc3662dacf171514}
  15. \begin{DoxyCompactList}\small\item\em The sniffer is run as a separate thread and the function process is the main function of the thread. It is the sniffer. \end{DoxyCompactList}\end{DoxyCompactItemize}
  16. \subsection*{Signals}
  17. \begin{DoxyCompactItemize}
  18. \item
  19. \hypertarget{class_sniffer_a7d0fd40379b7e5f49aff18ac20cb1c45}{}void {\bfseries result\+Ready} (unsigned long index)\label{class_sniffer_a7d0fd40379b7e5f49aff18ac20cb1c45}
  20. \end{DoxyCompactItemize}
  21. \subsection*{Public Member Functions}
  22. \begin{DoxyCompactItemize}
  23. \item
  24. \hypertarget{class_sniffer_a8039cbd5f487a357321d57337a664d3d}{}\hyperlink{class_sniffer_a8039cbd5f487a357321d57337a664d3d}{Sniffer} ()\label{class_sniffer_a8039cbd5f487a357321d57337a664d3d}
  25. \begin{DoxyCompactList}\small\item\em Constructor, does nothing. \end{DoxyCompactList}\item
  26. \hyperlink{class_sniffer_a8e5f1474f756be527b4c39a3e9a83893}{Sniffer} (Q\+Wait\+Condition $\ast$pw, Q\+Mutex $\ast$mx, int $\ast$ps)
  27. \begin{DoxyCompactList}\small\item\em Sets the mutexes for the inter communication between the sniffer and the G\+U\+I. \end{DoxyCompactList}\item
  28. \hypertarget{class_sniffer_a8ad3b97292e2cc274f31d87701f92be2}{}\hyperlink{class_sniffer_a8ad3b97292e2cc274f31d87701f92be2}{$\sim$\+Sniffer} ()\label{class_sniffer_a8ad3b97292e2cc274f31d87701f92be2}
  29. \begin{DoxyCompactList}\small\item\em Destructor, does nothing. \end{DoxyCompactList}\item
  30. vector$<$ \hyperlink{classip__packet}{ip\+\_\+packet} $>$ $\ast$ \hyperlink{class_sniffer_a791027d276cfcc5e6849132ecf8e80b6}{get\+Packet\+List} ()
  31. \begin{DoxyCompactList}\small\item\em Returns the packet list that contains the packets that are Ethernet -\/$>$ I\+P -\/$>$ (T\+C\+P$\vert$\+U\+D\+P) \end{DoxyCompactList}\item
  32. string \hyperlink{class_sniffer_a3dd95c60c5b8554e1bedc22b36ae488c}{format\+\_\+payload} (const char $\ast$payload, int len)
  33. \begin{DoxyCompactList}\small\item\em Formats the payload from a byte stream into a string of ascci. \end{DoxyCompactList}\item
  34. string \hyperlink{class_sniffer_a02101b56a75804d1ed39a1c04ba36ab2}{format\+\_\+hex\+\_\+ascii\+\_\+line} (const char $\ast$payload, int len, int offset)
  35. \begin{DoxyCompactList}\small\item\em Return string with the bytes of a payload line in ascii. \end{DoxyCompactList}\item
  36. void \hyperlink{class_sniffer_a94d7cd87d0f181c3cf2e5ec851e370b6}{find\+\_\+devices} (vector$<$ string $>$ \&)
  37. \begin{DoxyCompactList}\small\item\em Find the network devices in the computer, and store them in vector devs. \end{DoxyCompactList}\item
  38. void \hyperlink{class_sniffer_ab706811aa2b285e4c0f55491703c105a}{set\+Device} (string)
  39. \begin{DoxyCompactList}\small\item\em Sets the device to capture packets to dev. \end{DoxyCompactList}\end{DoxyCompactItemize}
  40. \subsection*{Private Member Functions}
  41. \begin{DoxyCompactItemize}
  42. \item
  43. void \hyperlink{class_sniffer_ac05f935a6ec2830d6bf42b607f071910}{print\+\_\+payload} (const u\+\_\+char $\ast$payload, int len)
  44. \begin{DoxyCompactList}\small\item\em Prints the payload in ascii. \end{DoxyCompactList}\item
  45. void \hyperlink{class_sniffer_a70598d5001a30cc8e801f1262770cdf6}{print\+\_\+hex\+\_\+ascii\+\_\+line} (const u\+\_\+char $\ast$payload, int len, int offset)
  46. \begin{DoxyCompactList}\small\item\em Prints to std output the a payload in ascii. \end{DoxyCompactList}\item
  47. void \hyperlink{class_sniffer_a0179e32fee6a0f7c2a13f37d64a7fae0}{got\+\_\+packet} (const struct pcap\+\_\+pkthdr $\ast$header, const u\+\_\+char $\ast$packet)
  48. \begin{DoxyCompactList}\small\item\em Disects the received packet. Takes out the info needed. \end{DoxyCompactList}\end{DoxyCompactItemize}
  49. \subsection*{Private Attributes}
  50. \begin{DoxyCompactItemize}
  51. \item
  52. \hypertarget{class_sniffer_ad3ad83091913a50effd7468d8d7ca590}{}vector$<$ \hyperlink{classip__packet}{ip\+\_\+packet} $>$ {\bfseries packet\+\_\+list}\label{class_sniffer_ad3ad83091913a50effd7468d8d7ca590}
  53. \item
  54. \hypertarget{class_sniffer_a36e1964fbc960b60a09b425a7cd1c0f6}{}Q\+Wait\+Condition $\ast$ {\bfseries wait\+\_\+pause}\label{class_sniffer_a36e1964fbc960b60a09b425a7cd1c0f6}
  55. \item
  56. \hypertarget{class_sniffer_ae0d6a92d2224a8c927afe861d45ab182}{}Q\+Mutex $\ast$ {\bfseries mutex}\label{class_sniffer_ae0d6a92d2224a8c927afe861d45ab182}
  57. \item
  58. \hypertarget{class_sniffer_ac35f2e04e7f7668243a75bd9b9b44028}{}string {\bfseries device}\label{class_sniffer_ac35f2e04e7f7668243a75bd9b9b44028}
  59. \item
  60. \hypertarget{class_sniffer_abb7dd6858499a14bcf002ba86e2d3f7f}{}string {\bfseries filter}\label{class_sniffer_abb7dd6858499a14bcf002ba86e2d3f7f}
  61. \item
  62. \hypertarget{class_sniffer_a2fde6ba65f629b1c74b1fcd1b8d2c022}{}int $\ast$ {\bfseries pause}\label{class_sniffer_a2fde6ba65f629b1c74b1fcd1b8d2c022}
  63. \end{DoxyCompactItemize}
  64. \subsection{Detailed Description}
  65. The \hyperlink{class_sniffer}{Sniffer} class is the one that use the pcap library to extract the packet information. It discards any packet that is not Ethernet-\/$>$I\+P-\/$>$(T\+C\+P$\vert$\+U\+D\+P), and pass up to the G\+U\+I the packets that are Ethernet-\/$>$I\+P-\/$>$(T\+C\+P$\vert$\+U\+D\+P).
  66. \subsection{Constructor \& Destructor Documentation}
  67. \hypertarget{class_sniffer_a8e5f1474f756be527b4c39a3e9a83893}{}\index{Sniffer@{Sniffer}!Sniffer@{Sniffer}}
  68. \index{Sniffer@{Sniffer}!Sniffer@{Sniffer}}
  69. \subsubsection[{Sniffer}]{\setlength{\rightskip}{0pt plus 5cm}Sniffer\+::\+Sniffer (
  70. \begin{DoxyParamCaption}
  71. \item[{Q\+Wait\+Condition $\ast$}]{pw, }
  72. \item[{Q\+Mutex $\ast$}]{mx, }
  73. \item[{int $\ast$}]{ps}
  74. \end{DoxyParamCaption}
  75. )}\label{class_sniffer_a8e5f1474f756be527b4c39a3e9a83893}
  76. Sets the mutexes for the inter communication between the sniffer and the G\+U\+I.
  77. \begin{DoxyParams}{Parameters}
  78. {\em pw} & used to pause the capture of packets \\
  79. \hline
  80. {\em mx} & used to protect critical region \\
  81. \hline
  82. {\em ps} & flag to pause the packet capture \\
  83. \hline
  84. \end{DoxyParams}
  85. \subsection{Member Function Documentation}
  86. \hypertarget{class_sniffer_a94d7cd87d0f181c3cf2e5ec851e370b6}{}\index{Sniffer@{Sniffer}!find\+\_\+devices@{find\+\_\+devices}}
  87. \index{find\+\_\+devices@{find\+\_\+devices}!Sniffer@{Sniffer}}
  88. \subsubsection[{find\+\_\+devices}]{\setlength{\rightskip}{0pt plus 5cm}void Sniffer\+::find\+\_\+devices (
  89. \begin{DoxyParamCaption}
  90. \item[{vector$<$ string $>$ \&}]{devs}
  91. \end{DoxyParamCaption}
  92. )}\label{class_sniffer_a94d7cd87d0f181c3cf2e5ec851e370b6}
  93. Find the network devices in the computer, and store them in vector devs.
  94. \begin{DoxyParams}{Parameters}
  95. {\em devs} & vector of string for device names \\
  96. \hline
  97. \end{DoxyParams}
  98. \hypertarget{class_sniffer_a02101b56a75804d1ed39a1c04ba36ab2}{}\index{Sniffer@{Sniffer}!format\+\_\+hex\+\_\+ascii\+\_\+line@{format\+\_\+hex\+\_\+ascii\+\_\+line}}
  99. \index{format\+\_\+hex\+\_\+ascii\+\_\+line@{format\+\_\+hex\+\_\+ascii\+\_\+line}!Sniffer@{Sniffer}}
  100. \subsubsection[{format\+\_\+hex\+\_\+ascii\+\_\+line}]{\setlength{\rightskip}{0pt plus 5cm}string Sniffer\+::format\+\_\+hex\+\_\+ascii\+\_\+line (
  101. \begin{DoxyParamCaption}
  102. \item[{const char $\ast$}]{payload, }
  103. \item[{int}]{len, }
  104. \item[{int}]{offset}
  105. \end{DoxyParamCaption}
  106. )}\label{class_sniffer_a02101b56a75804d1ed39a1c04ba36ab2}
  107. Return string with the bytes of a payload line in ascii.
  108. \begin{DoxyParams}{Parameters}
  109. {\em payload} & payload of the packet \\
  110. \hline
  111. {\em len} & length of the packet \\
  112. \hline
  113. {\em offset} & offset of packet \\
  114. \hline
  115. \end{DoxyParams}
  116. \begin{DoxyReturn}{Returns}
  117. a string with the bytes of a payload line in ascii
  118. \end{DoxyReturn}
  119. \hypertarget{class_sniffer_a3dd95c60c5b8554e1bedc22b36ae488c}{}\index{Sniffer@{Sniffer}!format\+\_\+payload@{format\+\_\+payload}}
  120. \index{format\+\_\+payload@{format\+\_\+payload}!Sniffer@{Sniffer}}
  121. \subsubsection[{format\+\_\+payload}]{\setlength{\rightskip}{0pt plus 5cm}string Sniffer\+::format\+\_\+payload (
  122. \begin{DoxyParamCaption}
  123. \item[{const char $\ast$}]{payload, }
  124. \item[{int}]{len}
  125. \end{DoxyParamCaption}
  126. )}\label{class_sniffer_a3dd95c60c5b8554e1bedc22b36ae488c}
  127. Formats the payload from a byte stream into a string of ascci.
  128. \begin{DoxyParams}{Parameters}
  129. {\em payload} & payload of the packet \\
  130. \hline
  131. {\em len} & length of the packet \\
  132. \hline
  133. \end{DoxyParams}
  134. \begin{DoxyReturn}{Returns}
  135. the payload in a string of ascii
  136. \end{DoxyReturn}
  137. \hypertarget{class_sniffer_a791027d276cfcc5e6849132ecf8e80b6}{}\index{Sniffer@{Sniffer}!get\+Packet\+List@{get\+Packet\+List}}
  138. \index{get\+Packet\+List@{get\+Packet\+List}!Sniffer@{Sniffer}}
  139. \subsubsection[{get\+Packet\+List}]{\setlength{\rightskip}{0pt plus 5cm}vector$<$ {\bf ip\+\_\+packet} $>$ $\ast$ Sniffer\+::get\+Packet\+List (
  140. \begin{DoxyParamCaption}
  141. {}
  142. \end{DoxyParamCaption}
  143. )}\label{class_sniffer_a791027d276cfcc5e6849132ecf8e80b6}
  144. Returns the packet list that contains the packets that are Ethernet -\/$>$ I\+P -\/$>$ (T\+C\+P$\vert$\+U\+D\+P)
  145. \begin{DoxyReturn}{Returns}
  146. vector of packets
  147. \end{DoxyReturn}
  148. \hypertarget{class_sniffer_a0179e32fee6a0f7c2a13f37d64a7fae0}{}\index{Sniffer@{Sniffer}!got\+\_\+packet@{got\+\_\+packet}}
  149. \index{got\+\_\+packet@{got\+\_\+packet}!Sniffer@{Sniffer}}
  150. \subsubsection[{got\+\_\+packet}]{\setlength{\rightskip}{0pt plus 5cm}void Sniffer\+::got\+\_\+packet (
  151. \begin{DoxyParamCaption}
  152. \item[{const struct pcap\+\_\+pkthdr $\ast$}]{header, }
  153. \item[{const u\+\_\+char $\ast$}]{packet}
  154. \end{DoxyParamCaption}
  155. )\hspace{0.3cm}{\ttfamily [private]}}\label{class_sniffer_a0179e32fee6a0f7c2a13f37d64a7fae0}
  156. Disects the received packet. Takes out the info needed.
  157. \begin{DoxyParams}{Parameters}
  158. {\em pcap\+\_\+pkthdr} & header of the pcap packet \\
  159. \hline
  160. {\em packet} & recieved packet \\
  161. \hline
  162. \end{DoxyParams}
  163. \hypertarget{class_sniffer_a70598d5001a30cc8e801f1262770cdf6}{}\index{Sniffer@{Sniffer}!print\+\_\+hex\+\_\+ascii\+\_\+line@{print\+\_\+hex\+\_\+ascii\+\_\+line}}
  164. \index{print\+\_\+hex\+\_\+ascii\+\_\+line@{print\+\_\+hex\+\_\+ascii\+\_\+line}!Sniffer@{Sniffer}}
  165. \subsubsection[{print\+\_\+hex\+\_\+ascii\+\_\+line}]{\setlength{\rightskip}{0pt plus 5cm}void Sniffer\+::print\+\_\+hex\+\_\+ascii\+\_\+line (
  166. \begin{DoxyParamCaption}
  167. \item[{const u\+\_\+char $\ast$}]{payload, }
  168. \item[{int}]{len, }
  169. \item[{int}]{offset}
  170. \end{DoxyParamCaption}
  171. )\hspace{0.3cm}{\ttfamily [private]}}\label{class_sniffer_a70598d5001a30cc8e801f1262770cdf6}
  172. Prints to std output the a payload in ascii.
  173. \begin{DoxyParams}{Parameters}
  174. {\em payload} & payload of the packet \\
  175. \hline
  176. {\em len} & length of the packet \\
  177. \hline
  178. {\em offset} & offset \\
  179. \hline
  180. \end{DoxyParams}
  181. \hypertarget{class_sniffer_ac05f935a6ec2830d6bf42b607f071910}{}\index{Sniffer@{Sniffer}!print\+\_\+payload@{print\+\_\+payload}}
  182. \index{print\+\_\+payload@{print\+\_\+payload}!Sniffer@{Sniffer}}
  183. \subsubsection[{print\+\_\+payload}]{\setlength{\rightskip}{0pt plus 5cm}void Sniffer\+::print\+\_\+payload (
  184. \begin{DoxyParamCaption}
  185. \item[{const u\+\_\+char $\ast$}]{payload, }
  186. \item[{int}]{len}
  187. \end{DoxyParamCaption}
  188. )\hspace{0.3cm}{\ttfamily [private]}}\label{class_sniffer_ac05f935a6ec2830d6bf42b607f071910}
  189. Prints the payload in ascii.
  190. \begin{DoxyParams}{Parameters}
  191. {\em payload} & payload of the packet \\
  192. \hline
  193. {\em len} & payload length \\
  194. \hline
  195. \end{DoxyParams}
  196. \hypertarget{class_sniffer_ab706811aa2b285e4c0f55491703c105a}{}\index{Sniffer@{Sniffer}!set\+Device@{set\+Device}}
  197. \index{set\+Device@{set\+Device}!Sniffer@{Sniffer}}
  198. \subsubsection[{set\+Device}]{\setlength{\rightskip}{0pt plus 5cm}void Sniffer\+::set\+Device (
  199. \begin{DoxyParamCaption}
  200. \item[{string}]{dev}
  201. \end{DoxyParamCaption}
  202. )}\label{class_sniffer_ab706811aa2b285e4c0f55491703c105a}
  203. Sets the device to capture packets to dev.
  204. \begin{DoxyParams}{Parameters}
  205. {\em dev} & name of the device \\
  206. \hline
  207. \end{DoxyParams}
  208. The documentation for this class was generated from the following files\+:\begin{DoxyCompactItemize}
  209. \item
  210. sniffer.\+h\item
  211. sniffer.\+cpp\end{DoxyCompactItemize}