defines.h.in 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 "@PCAP_BPF_H_FILE@"
  19. #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 /* don't re-include it in pcap.h */
  20. #endif
  21. #include "@LPCAPINC@"
  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 "@LNETINC@"
  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. enum bool_t {
  96. FALSE = 0,
  97. TRUE
  98. };
  99. #define EBUF_SIZE 1024 /* size of our error buffers */
  100. #define MAC_SIZE 7 /* size of the mac[] buffer */
  101. enum pad_t {
  102. PAD_PACKET,
  103. TRUNC_PACKET
  104. };
  105. #define DNS_QUERY_FLAG 0x8000
  106. enum direction_t {
  107. UNKNOWN = -1,
  108. CLIENT = 0,
  109. SERVER = 1,
  110. ANY = 2
  111. };
  112. enum tcpprep_mode {
  113. ERROR_MODE, /* Some kind of error has occurred */
  114. CIDR_MODE, /* single pass, CIDR netblock */
  115. REGEX_MODE, /* single pass, regex */
  116. PORT_MODE, /* single pass, use src/dst ports to split */
  117. MAC_MODE, /* single pass, use src mac to split */
  118. AUTO_MODE, /* first pass through in auto mode */
  119. ROUTER_MODE, /* second pass through in router mode */
  120. BRIDGE_MODE, /* second pass through in bridge mode */
  121. SERVER_MODE, /* second pass through in server (router) mode */
  122. CLIENT_MODE /* second pass through in client (router) mode */
  123. };
  124. #define BROADCAST_MAC "\FF\FF\FF\FF\FF\FF"
  125. /* MAC macros for printf */
  126. #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
  127. #define MAC_STR(x) x[0], x[1], x[2], x[3], x[4], x[5]
  128. /* struct timeval print structs */
  129. #define TIMEVAL_FORMAT "%lu.%08lu"
  130. /* force a word or half-word swap on both Big and Little endian systems */
  131. #ifndef SWAPLONG
  132. #define SWAPLONG(y) \
  133. ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
  134. #endif
  135. #ifndef SWAPSHORT
  136. #define SWAPSHORT(y) \
  137. ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
  138. #endif
  139. /* converts a 64bit int to network byte order */
  140. #ifndef HAVE_NTOHLL
  141. #ifdef WORDS_BIGENDIAN
  142. #define ntohll(x) (x)
  143. #define htonll(x) (x)
  144. #else
  145. /* stolen from http://www.codeproject.com/cpp/endianness.asp */
  146. #define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
  147. (unsigned int)ntohl(((int)(x >> 32))))
  148. #define htonll(x) ntohll(x)
  149. #endif /* WORDS_BIGENDIAN */
  150. #endif
  151. #define DEBUG_INFO 1 /* informational only, lessthan 1 line per packet */
  152. #define DEBUG_BASIC 2 /* limited debugging, one line per packet */
  153. #define DEBUG_DETAIL 3 /* more detailed, a few lines per packet */
  154. #define DEBUG_MORE 4 /* even more detail */
  155. #define DEBUG_CODE 5 /* examines code & values, many lines per packet */
  156. #endif /* DEFINES */