Sniffer.h 1.4 KB

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