The Poor Man's (or Woman's) Intrusion Detection System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
2.3 KiB

  1. //////////////////////////////////////////////////////////////////////
  2. // IP traffic analyzer - data objects
  3. // Written by Jonathan A. Foster <ChipMaster@YeOlPiShack.net>
  4. // Started April 23rd, 2021
  5. // Copyright JF Possibilities, Inc. All rights reserved.
  6. //
  7. // This is useful for breaking a text file line into fields.
  8. //
  9. // 2021-05-14 <ChipMaster@YeOlPiShack.net>
  10. // Restructure: broke out of monolithic iptraffic.cpp and made its
  11. // own module.
  12. //////////////////////////////////////////////////////////////////////
  13. #ifndef __JFP_IPTRAFFIC_DATA_H__
  14. #define __JFP_IPTRAFFIC_DATA_H__
  15. #include <string>
  16. #include <ostream>
  17. #include <vector>
  18. #include "strutil.h"
  19. //////////////////////////////////////////////////////////////////////
  20. // Network connection between "us" and "them"
  21. //////////////////////////////////////////////////////////////////////
  22. typedef unsigned short word;
  23. struct Conn {
  24. std::string us; // address on our side
  25. word us_port; // the port on our side
  26. std::string them; // address on their side
  27. word them_port; // the port on their side
  28. std::string name; // name of the address
  29. std::string protocol; // protocol used to communicate
  30. bool in; // whether this was an inward bound connection.
  31. Conn(): us_port(0), them_port(0), in(false) {}
  32. // clear data
  33. void clear();
  34. // swap polarity of record
  35. void swap();
  36. // scan & copy data from log record in
  37. Conn &operator=(const Splits &sp);
  38. // compare to another Conn
  39. int cmp(const Conn &gtr) const;
  40. inline bool operator<(const Conn &gtr) const { return cmp(gtr) <0; }
  41. inline bool operator<=(const Conn &gtr) const { return cmp(gtr)<=0; }
  42. inline bool operator>(const Conn &gtr) const { return cmp(gtr) >0; }
  43. inline bool operator>=(const Conn &gtr) const { return cmp(gtr)>=0; }
  44. inline bool operator==(const Conn &gtr) const { return cmp(gtr)==0; }
  45. inline bool operator!=(const Conn &gtr) const { return cmp(gtr)!=0; }
  46. };
  47. // A text output of Conn
  48. std::ostream &operator<<(std::ostream &out, const Conn &c);
  49. // Copy data from Splits into Conn
  50. const Splits &operator>>(const Splits &tsv, Conn &conn);
  51. //////////////////////////////////////////////////////////////////////
  52. // List of connections
  53. //////////////////////////////////////////////////////////////////////
  54. struct ConnList: public std::vector<Conn> {
  55. int find(Conn &needle);
  56. };
  57. #endif