defines.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #ifndef __DEFINES_H__
  2. #define __DEFINES_H__
  3. #include "config.h"
  4. #include "tcpr.h"
  5. /* should packet counters be 32 or 64 bit? --enable-64bit */
  6. #ifdef ENABLE_64BITS
  7. #define COUNTER unsigned long long
  8. #define COUNTER_SPEC "%llu"
  9. #else
  10. #define COUNTER unsigned long
  11. #define COUNTER_SPEC "%lu"
  12. #endif
  13. #ifdef HAVE_BPF
  14. #include <net/bpf.h>
  15. #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1
  16. #endif
  17. #if defined INCLUDE_PCAP_BPF_H_FILE && !defined PCAP_DONT_INCLUDE_PCAP_BPF_H
  18. #include "/usr/local/include/pcap-bpf.h"
  19. #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 /* don't re-include it in pcap.h */
  20. #endif
  21. #include "/usr/local/include/pcap.h"
  22. #include "lib/strlcpy.h"
  23. #include "common/list.h"
  24. #include "common/cidr.h"
  25. /*
  26. * net/bpf.h doesn't include DLT types, but pcap-bpf.h does.
  27. * Unfortunately, pcap-bpf.h also includes things in net/bpf.h
  28. * while also missing some key things (wow, that sucks)
  29. * The result is that I stole the DLT types from pcap-bpf.h and
  30. * put them in here.
  31. */
  32. #include "common/dlt_names.h"
  33. #ifdef HAVE_LIBNET
  34. #include ""
  35. #endif
  36. typedef struct tcpr_ipv4_hdr ipv4_hdr_t;
  37. typedef struct tcpr_ipv6_hdr ipv6_hdr_t;
  38. typedef struct tcpr_tcp_hdr tcp_hdr_t;
  39. typedef struct tcpr_udp_hdr udp_hdr_t;
  40. typedef struct tcpr_icmpv4_hdr icmpv4_hdr_t;
  41. typedef struct tcpr_icmpv6_hdr icmpv6_hdr_t;
  42. typedef struct tcpr_ethernet_hdr eth_hdr_t;
  43. typedef struct tcpr_802_1q_hdr vlan_hdr_t;
  44. typedef struct sll_header sll_hdr_t;
  45. typedef struct tcpr_arp_hdr arp_hdr_t;
  46. typedef struct tcpr_dnsv4_hdr dnsv4_hdr_t;
  47. /* our custom typdefs/structs */
  48. typedef u_char tcpr_macaddr_t[TCPR_ETH_H];
  49. struct tcpr_bpf_s {
  50. char *filter;
  51. int optimize;
  52. struct bpf_program program;
  53. };
  54. typedef struct tcpr_bpf_s tcpr_bpf_t;
  55. struct tcpr_xX_s {
  56. #define xX_MODE_INCLUDE 'x'
  57. #define xX_MODE_EXCLUDE 'X'
  58. int mode;
  59. tcpr_list_t *list;
  60. tcpr_cidr_t *cidr;
  61. #define xX_TYPE_LIST 1
  62. #define xX_TYPE_CIDR 2
  63. int type;
  64. };
  65. typedef struct tcpr_xX_s tcpr_xX_t;
  66. /* number of ports 0-65535 */
  67. #define NUM_PORTS 65536
  68. struct tcpr_services_s {
  69. char tcp[NUM_PORTS];
  70. char udp[NUM_PORTS];
  71. };
  72. typedef struct tcpr_services_s tcpr_services_t;
  73. struct tcpr_speed_s {
  74. /* speed modifiers */
  75. int mode;
  76. #define SPEED_MULTIPLIER 1
  77. #define SPEED_MBPSRATE 2
  78. #define SPEED_PACKETRATE 3
  79. #define SPEED_TOPSPEED 4
  80. #define SPEED_ONEATATIME 5
  81. float speed;
  82. };
  83. typedef struct tcpr_speed_s tcpr_speed_t;
  84. #define MAX_FILES 1024 /* Max number of files we can pass to tcpreplay */
  85. #define DEFAULT_MTU 1500 /* Max Transmission Unit of standard ethernet
  86. * don't forget *frames* are MTU + L2 header! */
  87. #define MAXPACKET 65535 /* was 16436 linux loopback, but maybe something is bigger then
  88. linux loopback */
  89. #define MAX_SNAPLEN 65535 /* tell libpcap to capture the entire packet */
  90. #define DNS_RESOLVE 1
  91. #define DNS_DONT_RESOLVE 0
  92. #define RESOLVE 0 /* disable dns lookups */
  93. #define BPF_OPTIMIZE 1 /* default is to optimize bpf program */
  94. #define PCAP_TIMEOUT 100 /* 100ms pcap_open_live timeout */
  95. /* HP-UX already defines TRUE/FALSE */
  96. #ifndef TRUE
  97. enum bool_t {
  98. FALSE = 0,
  99. TRUE
  100. };
  101. #endif
  102. #define EBUF_SIZE 1024 /* size of our error buffers */
  103. #define MAC_SIZE 7 /* size of the mac[] buffer */
  104. enum pad_t {
  105. PAD_PACKET,
  106. TRUNC_PACKET
  107. };
  108. #define DNS_QUERY_FLAG 0x8000
  109. enum direction_t {
  110. DIR_UNKNOWN = -1,
  111. DIR_CLIENT = 0,
  112. DIR_SERVER = 1,
  113. DIR_ANY = 2
  114. };
  115. enum tcpprep_mode {
  116. ERROR_MODE, /* Some kind of error has occurred */
  117. CIDR_MODE, /* single pass, CIDR netblock */
  118. REGEX_MODE, /* single pass, regex */
  119. PORT_MODE, /* single pass, use src/dst ports to split */
  120. MAC_MODE, /* single pass, use src mac to split */
  121. AUTO_MODE, /* first pass through in auto mode */
  122. ROUTER_MODE, /* second pass through in router mode */
  123. BRIDGE_MODE, /* second pass through in bridge mode */
  124. SERVER_MODE, /* second pass through in server (router) mode */
  125. CLIENT_MODE /* second pass through in client (router) mode */
  126. };
  127. #define BROADCAST_MAC "\xFF\xFF\xFF\xFF\xFF\xFF"
  128. /* MAC macros for printf */
  129. #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
  130. #define MAC_STR(x) x[0], x[1], x[2], x[3], x[4], x[5]
  131. /* struct timeval print structs */
  132. #define TIMEVAL_FORMAT "%lu.%06lu"
  133. /* force a word or half-word swap on both Big and Little endian systems */
  134. #ifndef SWAPLONG
  135. #define SWAPLONG(y) \
  136. ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
  137. #endif
  138. #ifndef SWAPSHORT
  139. #define SWAPSHORT(y) \
  140. ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
  141. #endif
  142. /* converts a 64bit int to network byte order */
  143. #ifndef HAVE_NTOHLL
  144. #ifdef WORDS_BIGENDIAN
  145. #define ntohll(x) (x)
  146. #define htonll(x) (x)
  147. #else
  148. /* stolen from http://www.codeproject.com/cpp/endianness.asp */
  149. #define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
  150. (unsigned int)ntohl(((int)(x >> 32))))
  151. #define htonll(x) ntohll(x)
  152. #endif /* WORDS_BIGENDIAN */
  153. #endif
  154. #define DEBUG_INFO 1 /* informational only, lessthan 1 line per packet */
  155. #define DEBUG_BASIC 2 /* limited debugging, one line per packet */
  156. #define DEBUG_DETAIL 3 /* more detailed, a few lines per packet */
  157. #define DEBUG_MORE 4 /* even more detail */
  158. #define DEBUG_CODE 5 /* examines code & values, many lines per packet */
  159. /* Win32 doesn't know about PF_INET6 */
  160. #ifndef PF_INET6
  161. #ifdef AF_INET6
  162. #define PF_INET6 AF_INET6
  163. #else
  164. #define PF_INET6 30 /* stolen from OS/X */
  165. #endif
  166. #endif
  167. #endif /* DEFINES */