fakepcapnav.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /* 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 "config.h"
  24. #include "defines.h"
  25. #include "common.h"
  26. #include <stdlib.h>
  27. #ifndef HAVE_PCAPNAV
  28. /**
  29. * pcapnav_init does nothing!
  30. */
  31. void
  32. pcapnav_init(void)
  33. {
  34. return;
  35. }
  36. /**
  37. * pcapnav_open_offline opens a pcap file,
  38. * and creates the struct for our use
  39. */
  40. pcapnav_t *
  41. pcapnav_open_offline(const char *filename)
  42. {
  43. pcapnav_t *pcapnav;
  44. char errbuf[PCAP_ERRBUF_SIZE];
  45. pcapnav = (pcapnav_t *) malloc(sizeof(pcapnav_t));
  46. if (pcapnav == NULL) {
  47. err(-1, "malloc() error: unable to malloc pcapnav_t");
  48. }
  49. pcapnav->pcap = pcap_open_offline(filename, errbuf);
  50. if (pcapnav->pcap == NULL) {
  51. errx(-1, "Error opening pcap file %s: %s", filename, errbuf);
  52. }
  53. return (pcapnav);
  54. }
  55. /**
  56. * closes our pcap file and free's the pcapnav
  57. */
  58. void
  59. pcapnav_close(pcapnav_t * pcapnav)
  60. {
  61. pcap_close(pcapnav->pcap);
  62. safe_free(pcapnav);
  63. }
  64. /**
  65. * returns the pcap_t data struct
  66. */
  67. pcap_t *
  68. pcapnav_pcap(pcapnav_t * pcapnav)
  69. {
  70. return (pcapnav->pcap);
  71. }
  72. #endif