tcpliveplay.h 4.6 KB

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