1
0

tcpliveplay.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Main Author & Publisher: Yazan Siam (tcpliveplay@gmail.com)
  3. * File: tcpliveplay.h
  4. * Started as a Senior Design project @ North Carolina State University
  5. * Last Updated Date: September 5, 2012
  6. * Past Contributors (Last contributed May 4, 2012): Andrew Leonard & Beau Luck
  7. */
  8. #pragma once
  9. #include "defines.h"
  10. #include "config.h"
  11. #define SIZE_ETHERNET 14
  12. #define LOCAL_IP_MATCH 1
  13. #define REMOTE_IP_MATCH 2
  14. #define NO_MATCH 0
  15. #define PCAP_OPEN_ERROR (-1)
  16. #define TIMEOUT_ms 10000
  17. #define PROMISC_OFF 0
  18. #define BUFSIZ_PLUS BUFSIZ
  19. #define ALARM_TIMEOUT 10
  20. #define SUCCESS 1
  21. #define ERROR (-1)
  22. /***********From tcpedit.h*****/
  23. #define TCPEDIT_SOFT_ERROR (-2)
  24. #define TCPEDIT_ERROR (-1)
  25. #define TCPEDIT_OK 0
  26. #define TCPEDIT_WARN 1
  27. /************From checksum.h******/
  28. #define CHECKSUM_CARRY(x) (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
  29. #include <stdbool.h>
  30. // 6 byte MAC Address
  31. struct mac_addr {
  32. unsigned char byte1;
  33. unsigned char byte2;
  34. unsigned char byte3;
  35. unsigned char byte4;
  36. unsigned char byte5;
  37. unsigned char byte6;
  38. };
  39. typedef struct ip_addr input_addr;
  40. // 4 bytes IP address
  41. struct ip_addr {
  42. unsigned char byte1;
  43. unsigned char byte2;
  44. unsigned char byte3;
  45. unsigned char byte4;
  46. };
  47. typedef struct ether_hdr ether_hdr;
  48. /* Ethernet header */
  49. struct ether_hdr {
  50. u_char ether_dhost[ETHER_ADDR_LEN]; /* Destination host address */
  51. u_char ether_shost[ETHER_ADDR_LEN]; /* Source host address */
  52. u_short ether_type; /* IP? ARP? RARP? etc */
  53. };
  54. typedef struct ipv4_hdr ipv4_hdr;
  55. struct ipv4_hdr {
  56. #if defined(WORDS_BIGENDIAN)
  57. u_int8_t ip_v:4;
  58. u_int8_t ip_hl:4;
  59. #else
  60. u_int8_t ip_hl:4;
  61. u_int8_t ip_v:4;
  62. #endif
  63. u_int8_t ip_tos;
  64. u_int16_t ip_len;
  65. u_int16_t ip_id;
  66. u_int16_t ip_off;
  67. u_int8_t ip_ttl;
  68. u_int8_t ip_p;
  69. u_int16_t ip_sum;
  70. input_addr ip_src, ip_dst;
  71. };
  72. typedef struct tcpheader tcp_hdr;
  73. /* for easy reference ************ */
  74. struct tcpheader {
  75. u_int16_t th_sport; // source port
  76. u_int16_t th_dport;
  77. u_int32_t th_seq;
  78. u_int32_t th_ack;
  79. #if defined(WORDS_BIGENDIAN)
  80. u_int8_t th_off:4;
  81. u_int8_t th_x2:4;
  82. #else
  83. u_int8_t th_x2:4;
  84. u_int8_t th_off:4;
  85. #endif
  86. u_int8_t th_flags;
  87. u_int16_t th_win;
  88. u_int16_t th_sum;
  89. u_int16_t th_urp;
  90. };
  91. #define TH_FIN 0x01
  92. #define TH_SYN 0x02
  93. #define TH_RST 0x04
  94. #define TH_PUSH 0x08
  95. #define TH_ACK 0x10
  96. #define TH_URG 0x20
  97. #define TH_ECE 0x40
  98. #define TH_CWR 0x80
  99. struct tcp_sched {
  100. u_int32_t exp_rseq; /* Expected Remote SEQ */
  101. u_int32_t exp_rack; /* Expected Remote ACK */
  102. u_int32_t calc_curr_rseq; /* Calculated Current Remote SEQ (not used at the moment) */
  103. u_int32_t calc_curr_rack; /* Calculated Current Remote ACK (not used at the moment) */
  104. u_int32_t calc_curr_lseq; /* Calculated Current Local SEQ (not used at the moment) */
  105. u_int32_t calc_curr_lack; /* Calculated Current Local ACK (not used at the moment) */
  106. u_int32_t curr_lseq; /* Current Local SEQ */
  107. u_int32_t curr_lack; /* Current Local ACK */
  108. unsigned int length_curr_ldata; /* Data Length of Currently seen local data */
  109. unsigned int length_last_ldata; /* Data Length of last locally seen data */
  110. unsigned int length_curr_rdata; /* Length of currently seen remote data */
  111. unsigned int length_last_rdata; /* Length of last remote seen data*/
  112. u_char *packet_ptr; /* The entire packet data to be sent */
  113. struct pcap_pkthdr pkthdr; /* Packet header */
  114. ether_hdr *etherhdr; /* Ethernet Header */
  115. tcp_hdr *tcphdr; /* TCP Header */
  116. ipv4_hdr *iphdr; /* IP Header */
  117. unsigned int size_ip; /* Keep track of each packet's IP Size */
  118. unsigned int size_tcp; /* Keep track of each packet's TCP Size */
  119. unsigned int size_payload; /* Keep tack of each packet's Payload size, if any */
  120. unsigned int sent_counter; /* Keep track of each packet's sent attempts*/
  121. bool remote; /* Flag to signify this is a remote packet */
  122. bool local; /* Flag to signify this is a local packet */
  123. };