slitheen.h 3.1 KB

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