Sniffer.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef SNIFFER_H
  2. #define SNIFFER_H
  3. #include <tins/tins.h>
  4. /**
  5. * @class Sniffer
  6. *
  7. * Sniffs the network.
  8. *
  9. * Sniffer class which will sniff on a network interface. It is supposed to
  10. * forward the packets to an analyzer or modifyer so we can hide data in the
  11. * traffic.
  12. */
  13. class Sniffer {
  14. public:
  15. /**
  16. * Creates a Sniffer.
  17. *
  18. * Creates a Sniffer and sets the network interface for sniffing.
  19. *
  20. * @param interface name of the interface for sniffing
  21. */
  22. Sniffer(std::string interfaceName);
  23. /**
  24. * Destroys the Sniffer.
  25. *
  26. * Destructor of the Sniffer.
  27. */
  28. ~Sniffer();
  29. /**
  30. * Start sniffing on the interface.
  31. *
  32. * Starts a sniffing loop which calls handle. The loop will only be stopped if
  33. * handle returns false.
  34. */
  35. void startSniffing();
  36. /**
  37. * Sets a filter for the sniffer.
  38. *
  39. * Sets the filter for a sniffer with a pcap filter string. E.g. "ip
  40. * dst 8.8.8.8".
  41. *
  42. * @param filterString pcap filter string
  43. */
  44. void setFilter(std::string filterString);
  45. private:
  46. /**
  47. * Handler for sniffed packets.
  48. *
  49. * Handles incoming connections and provides data for the package analyzer and
  50. * modifyer.
  51. *
  52. * @param pdu sniffed packet
  53. *
  54. * @return false = stop loop | true = continue loop
  55. */
  56. bool handle(Tins::PDU &pdu);
  57. /**
  58. * Tins sniffer object.
  59. */
  60. Tins::Sniffer sniffer;
  61. };
  62. #endif