SinglePacketSource.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @file SinglePacketSource.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef BADVPN_SINGLEPACKETSOURCE_H
  23. #define BADVPN_SINGLEPACKETSOURCE_H
  24. #include <base/DebugObject.h>
  25. #include <flow/PacketRecvInterface.h>
  26. /**
  27. * An object which provides a single packet through {@link PacketRecvInterface}.
  28. */
  29. typedef struct {
  30. uint8_t *packet;
  31. int packet_len;
  32. int sent;
  33. PacketRecvInterface output;
  34. DebugObject d_obj;
  35. } SinglePacketSource;
  36. /**
  37. * Initializes the object.
  38. *
  39. * @param o the object
  40. * @param packet packet to provide to the output. Must stay available until the packet is provided.
  41. * @param packet_len length of packet. Must be >=0.
  42. * @param pg pending group we live in
  43. */
  44. void SinglePacketSource_Init (SinglePacketSource *o, uint8_t *packet, int packet_len, BPendingGroup *pg);
  45. /**
  46. * Frees the object.
  47. *
  48. * @param o the object
  49. */
  50. void SinglePacketSource_Free (SinglePacketSource *o);
  51. /**
  52. * Returns the output interface.
  53. * The MTU of the interface will be packet_len.
  54. *
  55. * @param o the object
  56. * @return output interface
  57. */
  58. PacketRecvInterface * SinglePacketSource_GetOutput (SinglePacketSource *o);
  59. #endif