slitheen.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef _SLITHEEN_H_
  2. #define _SLITHEEN_H_
  3. #include <stdlib.h>
  4. #include <netinet/in.h>
  5. #include <pcap.h>
  6. #define macaddr "08:00:27:0e:89:ea"
  7. /* Ethernet addresses are 6 bytes */
  8. #define ETHER_ADDR_LEN 6
  9. #define ETHER_HEADER_LEN 2*ETHER_ADDR_LEN + 2
  10. /* Definitions for parsing packet data */
  11. struct ip_header {
  12. u_char versionihl; /* Version >> 4 | IHL & 0x0f */
  13. u_char dscpecn; /* DSCP >> 2 | ECN & 0x03 */
  14. u_short len; /* Total Length */
  15. u_short id; /* Identification */
  16. u_short flagsoff; /* Flags >> 13 | Fragment Offset & 0x1fff */
  17. #define RF 0x8000 /* Reserved; must be zero */
  18. #define DF 0x4000 /* Dont Fragment */
  19. #define MF 0x2000 /* More Fragments */
  20. u_char ttl; /* Time To Live */
  21. u_char proto; /* Protocol */
  22. u_short chksum; /* Header Checksum */
  23. struct in_addr src, dst; /* Source and Destination addresses */
  24. };
  25. #define IP_HEADER_LEN(ip) (((ip)->versionihl) & 0x0f)*4
  26. struct tcp_header {
  27. u_short src_port; /* source port */
  28. u_short dst_port; /* destination port */
  29. u_int sequence_num; /* sequence number */
  30. u_int ack_num; /* acknowledgement number */
  31. u_char offset_res_ns; /*Data offset >> 4 | res >> 1 | NS 0x01 */
  32. u_char flags; /* Flags */
  33. #define FIN 0x01
  34. #define RST 0x04
  35. u_short win_size; /* Window size*/
  36. u_short chksum; /* Checksum */
  37. u_short urg; /* Urgent pointer */
  38. };
  39. #define TCP_HEADER_LEN(tcp) (((tcp)->offset_res_ns) >> 4)*4
  40. struct tls_header {
  41. u_char type; /* Content Type */
  42. #define CCS 0x14
  43. #define ALERT 0x15
  44. #define HS 0x16
  45. #define APP 0x17
  46. #define HB 0x18
  47. u_short version; /* Version */
  48. u_short len; /* Length */
  49. u_char msg; /* Message Type */
  50. #define CLIENT_HELLO 0x01
  51. #define FINISHED 0x14
  52. };
  53. #define RECORD_HEADER_LEN 5
  54. #define CLIENT_HELLO_HEADER_LEN 6
  55. struct packet_info {
  56. const struct ip_header *ip_hdr;
  57. struct tcp_header *tcp_hdr;
  58. const struct tls_header *record_hdr;
  59. uint32_t size_tcp_hdr;
  60. uint32_t size_ip_hdr;
  61. uint8_t *app_data;
  62. uint32_t app_data_len;
  63. };
  64. struct slitheen_header {
  65. u_char marker; /* 0x01 means censored data, 0x02 means dummy data */
  66. u_char version; /* For now 0x01 */
  67. u_short len;
  68. };
  69. #define SLITHEEN_HEADER_LEN 4
  70. struct __attribute__((__packed__)) record_header {
  71. u_char type;
  72. #define HS 0x16
  73. u_short version;
  74. u_short len;
  75. };
  76. #define RECORD_LEN(rec) (htons(rec->len))
  77. struct __attribute__((__packed__)) handshake_header {
  78. u_char type; /*Handshake message type */
  79. u_char len1;
  80. u_char len2;
  81. u_char len3;
  82. };
  83. #define HANDSHAKE_MESSAGE_LEN(hs) (((hs)->len1) << 16)+(((hs)->len2) << 8)+ ((hs)->len3)
  84. #define HANDSHAKE_HEADER_LEN 4
  85. struct sniff_args {
  86. char *readdev;
  87. char *writedev;
  88. char *filter;
  89. };
  90. void got_packet(uint8_t *args, const struct pcap_pkthdr *header, const uint8_t *packet);
  91. void *sniff_packets(void *);
  92. void process_packet(struct packet_info *info);
  93. void extract_packet_headers(uint8_t *packet, struct packet_info *info);
  94. #endif /* _SLITHEEN_H_ */