SinglePacketSender.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @file SinglePacketSender.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. * @section DESCRIPTION
  23. *
  24. * A {@link PacketPassInterface} source which sends a single packet.
  25. */
  26. #ifndef BADVPN_FLOW_SINGLEPACKETSENDER_H
  27. #define BADVPN_FLOW_SINGLEPACKETSENDER_H
  28. #include <stdint.h>
  29. #include <misc/dead.h>
  30. #include <system/BPending.h>
  31. #include <system/DebugObject.h>
  32. #include <flow/PacketPassInterface.h>
  33. /**
  34. * Handler function called after the packet is sent.
  35. * The object must be freed from within this handler.
  36. *
  37. * @param user as in {@link SinglePacketSender_Init}.
  38. */
  39. typedef void (*SinglePacketSender_handler) (void *user);
  40. /**
  41. * A {@link PacketPassInterface} source which sends a single packet.
  42. */
  43. typedef struct {
  44. dead_t dead;
  45. uint8_t *packet;
  46. int packet_len;
  47. PacketPassInterface *output;
  48. SinglePacketSender_handler handler;
  49. void *user;
  50. BPending start_job;
  51. DebugObject d_obj;
  52. } SinglePacketSender;
  53. /**
  54. * Initializes the object.
  55. *
  56. * @param o the object
  57. * @param packet packet to be sent. Must be available as long as the object exists.
  58. * @param packet_len length of the packet. Must be >=0 and <=(MTU of output).
  59. * @param output output interface
  60. * @param handler handler to call when the packet is sent
  61. * @param user value to pass to handler
  62. * @param pg pending group
  63. */
  64. void SinglePacketSender_Init (SinglePacketSender *o, uint8_t *packet, int packet_len, PacketPassInterface *output, SinglePacketSender_handler handler, void *user, BPendingGroup *pg);
  65. /**
  66. * Frees the object.
  67. *
  68. * @param o the object
  69. */
  70. void SinglePacketSender_Free (SinglePacketSender *o);
  71. #endif