SinglePacketSender.h 2.2 KB

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