tcpprep_api.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2018 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  5. *
  6. * The Tcpreplay Suite of tools is free software: you can redistribute it
  7. * and/or modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or with the authors permission any later version.
  10. *
  11. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _TCPPREP_API_H_
  20. #define _TCPPREP_API_H_
  21. #include "config.h"
  22. #include "defines.h"
  23. #include "tcpreplay_api.h"
  24. #include <regex.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* default ports used for servers */
  29. #define DEFAULT_LOW_SERVER_PORT 0
  30. #define DEFAULT_HIGH_SERVER_PORT 1023
  31. #define MYARGS_LEN 1024
  32. typedef struct tcpprep_opt_s {
  33. pcap_t *pcap;
  34. #ifdef ENABLE_VERBOSE
  35. bool verbose;
  36. char *tcpdump_args;
  37. #endif
  38. tcpr_cache_t *cachedata;
  39. tcpr_cidr_t *cidrdata;
  40. char *maclist;
  41. tcpr_xX_t xX;
  42. tcpr_bpf_t bpf;
  43. tcpr_services_t services;
  44. char *comment; /* cache file comment */
  45. bool nocomment; /* don't include the cli in the comment */
  46. tcpprep_mode_t mode; /* our overall mode */
  47. tcpprep_mode_t automode; /* our auto mode */
  48. int min_mask;
  49. int max_mask;
  50. double ratio;
  51. regex_t preg;
  52. bool nonip;
  53. } tcpprep_opt_t;
  54. typedef struct tcpprep_s {
  55. tcpprep_opt_t *options;
  56. char *outfile;
  57. char *pcapfile;
  58. char errstr[TCPREPLAY_ERRSTR_LEN];
  59. char warnstr[TCPREPLAY_ERRSTR_LEN];
  60. #ifdef ENABLE_VERBOSE
  61. tcpdump_t tcpdump;
  62. #endif
  63. } tcpprep_t;
  64. char *tcpprep_geterr(tcpprep_t *);
  65. char *tcpprep_getwarn(tcpprep_t *);
  66. tcpprep_t *tcpprep_init();
  67. void tcpprep_close(tcpprep_t *);
  68. int tcpprep_post_args(tcpprep_t *, int, char *[]);
  69. /* all these functions return 0 on success and < 0 on error. */
  70. int tcpprep_set_pcap_file(tcpprep_t *, char *);
  71. int tcpprep_set_output_file(tcpprep_t *, char *);
  72. int tcpprep_set_comment(tcpprep_t *, char *);
  73. int tcpprep_set_nocomment(tcpprep_t *, bool);
  74. int tcpprep_set_mode(tcpprep_t *, tcpprep_mode_t);
  75. int tcpprep_set_min_mask(tcpprep_t *, int);
  76. int tcpprep_set_max_mask(tcpprep_t *, int);
  77. int tcpprep_set_ratio(tcpprep_t *, double);
  78. int tcpprep_set_regex(tcpprep_t *, char *);
  79. int tcpprep_set_nonip_is_secondary(tcpprep_t *, bool);
  80. #ifdef ENABLE_VERBOSE
  81. int tcpprep_set_verbose(tcpprep_t *, bool);
  82. int tcpprep_set_tcpdump_args(tcpprep_t *, char *);
  83. int tcpprep_set_tcpdump(tcpprep_t *, tcpdump_t *);
  84. #endif
  85. /**
  86. * These functions are seen by the outside world, but nobody should ever use them
  87. * outside of internal tcpprep API functions
  88. */
  89. #define tcpprep_seterr(x, y, ...) __tcpprep_seterr(x, __FUNCTION__, __LINE__, __FILE__, y, __VA_ARGS__)
  90. void __tcpprep_seterr(tcpprep_t *ctx, const char *func, const int line, const char *file, const char *fmt, ...);
  91. void tcpprep_setwarn(tcpprep_t *ctx, const char *fmt, ...);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif //_TCPREPLAY_API_H_