1
0

tcpreplay.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* $Id: tcpreplay.h 767 2004-10-06 12:48:49Z aturner $ */
  2. /*
  3. * Copyright (c) 2001-2004 Aaron Turner, Matt Bing.
  4. * All rights reserved.
  5. *
  6. * Copyright (c) 1999 Anzen Computing. All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by Anzen Computing, Inc.
  20. * 4. Neither the names of the copyright owners nor the names of its
  21. * contributors may be used to endorse or promote products derived from
  22. * this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  25. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  26. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  27. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  28. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  30. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  32. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  33. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  34. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #ifndef _TCPREPLAY_H_
  37. #define _TCPREPLAY_H_
  38. #include "config.h"
  39. #include <libnet.h>
  40. #include <pcap.h>
  41. #include <sys/time.h>
  42. #include "timer.h"
  43. #include "cache.h"
  44. #include "dlt.h"
  45. /* Map libnet 1.1 structs to shorter names for internal use */
  46. typedef libnet_t LIBNET;
  47. #define LIBNET_IP_H LIBNET_IPV4_H
  48. #define LIBNET_ICMP_H LIBNET_ICMPV4_H
  49. /* The release version of libnet 1.1.1 changed DNS */
  50. #ifdef LIBNET_DNSV4_H
  51. #define LIBNET_DNS_H LIBNET_DNSV4_H
  52. #else
  53. #define LIBNET_DNS_H LIBNET_UDP_DNSV4_H
  54. #endif
  55. /* standardize all common header typedefs */
  56. typedef struct libnet_ipv4_hdr ip_hdr_t;
  57. typedef struct libnet_dnsv4_hdr dns_hdr_t;
  58. typedef struct libnet_icmpv4_hdr icmp_hdr_t;
  59. typedef struct libnet_arp_hdr arp_hdr_t;
  60. typedef struct libnet_tcp_hdr tcp_hdr_t;
  61. typedef struct libnet_udp_hdr udp_hdr_t;
  62. typedef struct libnet_ethernet_hdr eth_hdr_t;
  63. #define DEFAULT_MTU 1500 /* Max Transmission Unit of standard ethernet
  64. * don't forget *frames* are MTU + L2 header! */
  65. #define MAXPACKET 16436 /* MTU of Linux loopback */
  66. #define MAX_SNAPLEN 65535 /* tell libpcap to capture the entire packet */
  67. /* run-time options */
  68. struct options {
  69. LIBNET *intf1;
  70. LIBNET *intf2;
  71. pcap_t *listen1;
  72. pcap_t *listen2;
  73. pcap_t *savepcap;
  74. pcap_t *savepcap2;
  75. pcap_dumper_t *savedumper;
  76. pcap_dumper_t *savedumper2;
  77. char intf1_mac[ETHER_ADDR_LEN];
  78. char intf2_mac[ETHER_ADDR_LEN];
  79. char intf1_smac[ETHER_ADDR_LEN];
  80. char intf2_smac[ETHER_ADDR_LEN];
  81. int datadump_mode;
  82. int datadumpfile;
  83. int datadumpfile2;
  84. int break_percent;
  85. float rate;
  86. float mult;
  87. float packetrate;
  88. int one_at_a_time;
  89. int n_iter;
  90. int cache_packets;
  91. int no_martians;
  92. int topspeed;
  93. int fixchecksums;
  94. int cidr;
  95. int trunc;
  96. long int seed;
  97. int rewriteip;
  98. int rewriteports;
  99. int mtu;
  100. int truncate;
  101. char **files;
  102. char *cache_files;
  103. u_int64_t offset;
  104. u_int64_t limit_send;
  105. char *bpf_filter;
  106. int bpf_optimize;
  107. int sniff_snaplen;
  108. int sniff_bridge;
  109. int promisc;
  110. int poll_timeout;
  111. int verbose;
  112. int one_output;
  113. char *tcpprep_comment;
  114. char break_type;
  115. };
  116. #define RESOLVE 0 /* disable dns lookups */
  117. #define BPF_OPTIMIZE 1 /* default is to optimize bpf program */
  118. #define PCAP_TIMEOUT 100 /* 100ms pcap_open_live timeout */
  119. #define TRUE 1
  120. #define FALSE 0
  121. #define EBUF_SIZE 256 /* size of our error buffers */
  122. #define MAC_SIZE 7 /* size of the mac[] buffer */
  123. #define CIDR_MODE 1 /* single pass, CIDR netblock */
  124. #define REGEX_MODE 2 /* single pass, Regex */
  125. #define AUTO_MODE 4 /* first pass through in auto mode */
  126. #define PORT_MODE 8 /* single pass, use src/dst ports to split */
  127. #define ROUTER_MODE 16 /* second pass through in router/auto mode */
  128. #define BRIDGE_MODE 32 /* second pass through in bridge/auto mode */
  129. #define SERVER_MODE 64 /* second pass through in client/auto mode */
  130. #define CLIENT_MODE 128 /* second pass through in server/auto mode */
  131. #define L2DATALEN 255 /* Max size of the L2 data file */
  132. #define DNS_QUERY_FLAG 0x8000
  133. #define SERVER 1
  134. #define CLIENT 0
  135. #define UNKNOWN -1
  136. #define ANY 2
  137. #define DEBUG_INFO 1 /* informational only, lessthan 1 line per packet */
  138. #define DEBUG_BASIC 2 /* limited debugging, one line per packet */
  139. #define DEBUG_DETAILED 3 /* more detailed, a few lines per packet */
  140. #define DEBUG_CODE 4 /* examines code & values, many lines per packet */
  141. #define PAD_PACKET 1 /* values for the 'uflag' in tcpreplay */
  142. #define TRUNC_PACKET 2
  143. #ifndef SWAPLONG
  144. #define SWAPLONG(y) \
  145. ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
  146. #endif
  147. #ifndef SWAPSHORT
  148. #define SWAPSHORT(y) \
  149. ( (((y)&0xff)<<8) | ((u_short)((y)&0xff00)>>8) )
  150. #endif
  151. #define NULL_MAC "\0\0\0\0\0\0"
  152. #define BROADCAST_MAC "\FF\FF\FF\FF\FF\FF"
  153. /* MAC macros for printf */
  154. #define MAC_FORMAT "%02X:%02X:%02X:%02X:%02X:%02X"
  155. #define MAC_STR(x) x[0], x[1], x[2], x[3], x[4], x[5]
  156. /* converts a 64bit int to network byte order */
  157. #ifndef ntohll
  158. #ifdef WORDS_BIGENDIAN
  159. #define ntohll(x) (x)
  160. #define htonll(x) (x)
  161. #else
  162. /* stolen from http://www.codeproject.com/cpp/endianness.asp */
  163. #define ntohll(x) (((u_int64_t)(ntohl((int)((x << 32) >> 32))) << 32) | \
  164. (unsigned int)ntohl(((int)(x >> 32))))
  165. #define htonll(x) ntohll(x)
  166. #endif /* WORDS_BIGENDIAN */
  167. #endif /* ntholl */
  168. #endif