fakepcapnav.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2024 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. /* This file implements a fake, non-functioning version of the libpcapnav
  20. * API based on libpcap. It's solely here for people who don't have
  21. * libpcapnav installed on their system, and to keep the code maintainable.
  22. */
  23. #include "defines.h"
  24. #include "config.h"
  25. #include "common.h"
  26. #include "utils.h"
  27. #include <stdlib.h>
  28. #ifndef HAVE_PCAPNAV
  29. /**
  30. * pcapnav_init does nothing!
  31. */
  32. void
  33. pcapnav_init(void)
  34. {}
  35. /**
  36. * pcapnav_open_offline opens a pcap file,
  37. * and creates the struct for our use
  38. */
  39. pcapnav_t *
  40. pcapnav_open_offline(const char *filename)
  41. {
  42. pcapnav_t *pcapnav;
  43. char errbuf[PCAP_ERRBUF_SIZE];
  44. pcapnav = (pcapnav_t *)malloc(sizeof(pcapnav_t));
  45. if (pcapnav == NULL) {
  46. err(-1, "malloc() error: unable to malloc pcapnav_t");
  47. }
  48. pcapnav->pcap = tcpr_pcap_open(filename, errbuf);
  49. if (pcapnav->pcap == NULL) {
  50. errx(-1, "Error opening pcap file %s: %s", filename, errbuf);
  51. }
  52. return (pcapnav);
  53. }
  54. /**
  55. * closes our pcap file and free's the pcapnav
  56. */
  57. void
  58. pcapnav_close(pcapnav_t *pcapnav)
  59. {
  60. pcap_close(pcapnav->pcap);
  61. safe_free(pcapnav);
  62. }
  63. /**
  64. * returns the pcap_t data struct
  65. */
  66. pcap_t *
  67. pcapnav_pcap(pcapnav_t *pcapnav)
  68. {
  69. return (pcapnav->pcap);
  70. }
  71. #endif