defines.h.in 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #ifndef __DEFINES_H__
  2. #define __DEFINES_H__
  3. #include "config.h"
  4. /* should packet counters be 32 or 64 bit? --enable-64bit */
  5. #ifdef ENABLE_64BITS
  6. #define COUNTER unsigned long long
  7. #define COUNTER_SPEC "%llu"
  8. #else
  9. #define COUNTER unsigned long
  10. #define COUNTER_SPEC "%lu"
  11. #endif
  12. #include "lib/strlcpy.h"
  13. #include "common/list.h"
  14. #include "common/cidr.h"
  15. #include "@LNETINC@"
  16. #ifdef INCLUDE_PCAP_BPF_H_FILE
  17. #include "@PCAP_BPF_H_FILE@"
  18. #define PCAP_DONT_INCLUDE_PCAP_BPF_H /* don't re-include it in pcap.h */
  19. #endif
  20. #include "@LPCAPINC@"
  21. #ifdef HAVE_LIBNIDS
  22. #include "@LNIDSINC@"
  23. #endif
  24. /* Map libnet 1.1 structs to shorter names for internal use */
  25. #define LIBNET_IP_H LIBNET_IPV4_H
  26. #define LIBNET_ICMP_H LIBNET_ICMPV4_H
  27. /* The release version of libnet 1.1.1 changed DNS */
  28. #ifdef LIBNET_DNSV4_H
  29. #define LIBNET_DNS_H LIBNET_DNSV4_H
  30. #else
  31. #define LIBNET_DNS_H LIBNET_UDP_DNSV4_H
  32. #endif
  33. /* standardize all common header typedefs */
  34. typedef struct libnet_ipv4_hdr ip_hdr_t;
  35. typedef struct libnet_dnsv4_hdr dns_hdr_t;
  36. typedef struct libnet_icmpv4_hdr icmp_hdr_t;
  37. typedef struct libnet_arp_hdr arp_hdr_t;
  38. typedef struct libnet_tcp_hdr tcp_hdr_t;
  39. typedef struct libnet_udp_hdr udp_hdr_t;
  40. typedef struct libnet_ethernet_hdr eth_hdr_t;
  41. typedef struct libnet_802_1q_hdr vlan_hdr_t;
  42. typedef struct sll_header sll_hdr_t;
  43. /* our custom typdefs/structs */
  44. typedef u_char tcpr_macaddr_t[LIBNET_ETH_H];
  45. struct tcpr_bpf_s {
  46. char *filter;
  47. int optimize;
  48. struct bpf_program program;
  49. };
  50. typedef struct tcpr_bpf_s tcpr_bpf_t;
  51. struct tcpr_xX_s {
  52. #define xX_MODE_INCLUDE 'x'
  53. #define xX_MODE_EXCLUDE 'X'
  54. int mode;
  55. tcpr_list_t *list;
  56. tcpr_cidr_t *cidr;
  57. #define xX_TYPE_LIST 1
  58. #define xX_TYPE_CIDR 2
  59. int type;
  60. };
  61. typedef struct tcpr_xX_s tcpr_xX_t;
  62. /* number of ports 0-65535 */
  63. #define NUM_PORTS 65536
  64. struct tcpr_services_s {
  65. char tcp[NUM_PORTS];
  66. char udp[NUM_PORTS];
  67. };
  68. typedef struct tcpr_services_s tcpr_services_t;
  69. struct tcpr_speed_s {
  70. /* speed modifiers */
  71. int mode;
  72. #define SPEED_MULTIPLIER 1
  73. #define SPEED_MBPSRATE 2
  74. #define SPEED_PACKETRATE 3
  75. #define SPEED_TOPSPEED 4
  76. #define SPEED_ONEATATIME 5
  77. float speed;
  78. };
  79. typedef struct tcpr_speed_s tcpr_speed_t;
  80. #define MAX_FILES 1024 /* Max number of files we can pass to tcpreplay */
  81. #define DEFAULT_MTU 1500 /* Max Transmission Unit of standard ethernet
  82. * don't forget *frames* are MTU + L2 header! */
  83. #define MAXPACKET 65535 /* was 16436 linux loopback, but maybe something is bigger then
  84. linux loopback */
  85. #define MAX_SNAPLEN 65535 /* tell libpcap to capture the entire packet */
  86. #define RESOLVE 0 /* disable dns lookups */
  87. #define BPF_OPTIMIZE 1 /* default is to optimize bpf program */
  88. #define PCAP_TIMEOUT 100 /* 100ms pcap_open_live timeout */
  89. #define TRUE 1
  90. #define FALSE 0
  91. #define EBUF_SIZE 1024 /* size of our error buffers */
  92. #define MAC_SIZE 7 /* size of the mac[] buffer */
  93. #define PAD_PACKET 1 /* values for the 'uflag' in tcpreplay */
  94. #define TRUNC_PACKET 2
  95. #define DNS_QUERY_FLAG 0x8000
  96. #define SERVER 1
  97. #define CLIENT 0
  98. #define UNKNOWN -1
  99. #define ANY 2
  100. enum tcpprep_mode {
  101. ERROR_MODE, /* Some kind of error has occurred */
  102. CIDR_MODE, /* single pass, CIDR netblock */
  103. REGEX_MODE, /* single pass, regex */
  104. PORT_MODE, /* single pass, use src/dst ports to split */
  105. MAC_MODE, /* single pass, use src mac to split */
  106. AUTO_MODE, /* first pass through in auto mode */
  107. ROUTER_MODE, /* second pass through in router mode */
  108. BRIDGE_MODE, /* second pass through in bridge mode */
  109. SERVER_MODE, /* second pass through in server (router) mode */
  110. CLIENT_MODE /* second pass through in client (router) mode */
  111. };
  112. #define BROADCAST_MAC "\FF\FF\FF\FF\FF\FF"
  113. /* MAC macros for printf */
  114. #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
  115. #define MAC_STR(x) x[0], x[1], x[2], x[3], x[4], x[5]
  116. /* struct timeval print structs */
  117. #define TIMEVAL_FORMAT "%lu.%08lu"
  118. /* force a word or half-word swap on both Big and Little endian systems */
  119. #ifndef SWAPLONG
  120. #define SWAPLONG(y) \
  121. ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
  122. #endif
  123. #ifndef SWAPSHORT
  124. #define SWAPSHORT(y) \
  125. ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
  126. #endif
  127. /* converts a 64bit int to network byte order */
  128. #ifndef HAVE_NTOHLL
  129. #ifdef WORDS_BIGENDIAN
  130. #define ntohll(x) (x)
  131. #define htonll(x) (x)
  132. #else
  133. /* stolen from http://www.codeproject.com/cpp/endianness.asp */
  134. #define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
  135. (unsigned int)ntohl(((int)(x >> 32))))
  136. #define htonll(x) ntohll(x)
  137. #endif /* WORDS_BIGENDIAN */
  138. #endif
  139. #define DEBUG_INFO 1 /* informational only, lessthan 1 line per packet */
  140. #define DEBUG_BASIC 2 /* limited debugging, one line per packet */
  141. #define DEBUG_DETAIL 3 /* more detailed, a few lines per packet */
  142. #define DEBUG_MORE 4 /* even more detail */
  143. #define DEBUG_CODE 5 /* examines code & values, many lines per packet */
  144. #endif /* DEFINES */
  145. /*
  146. Local Variables:
  147. mode:c
  148. indent-tabs-mode:nil
  149. c-basic-offset:4
  150. End:
  151. */