closechannel.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed closechannel (struct channel const * channel);
  11. *
  12. * channel.h
  13. *
  14. * close ethernet raw packet channel;
  15. *
  16. * Contributor(s):
  17. * Charles Maier <cmaier@qca.qualcomm.com>
  18. * Nathaniel Houghton <nhoughto@qca.qualcomm.com>
  19. *
  20. *--------------------------------------------------------------------*/
  21. #ifndef CLOSECHANNEL_SOURCE
  22. #define CLOSECHANNEL_SOURCE
  23. #include <unistd.h>
  24. #include <stdlib.h>
  25. #include "../ether/channel.h"
  26. signed closechannel (struct channel const * channel)
  27. {
  28. #if defined (__linux__)
  29. return (close (channel->fd));
  30. #elif defined (__APPLE__) || (__OpenBSD__)
  31. free (channel->bpf->bpf_buffer);
  32. free (channel->bpf);
  33. return (close (channel->fd));
  34. #elif defined (WINPCAP) || defined (LIBPCAP)
  35. pcap_close (channel->socket);
  36. return (0);
  37. #else
  38. #error "Unknown Environment"
  39. #endif
  40. }
  41. #endif