PacketProtoEncoder.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @file PacketProtoEncoder.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. * Object which encodes packets according to PacketProto.
  25. */
  26. #ifndef BADVPN_FLOW_PACKETPROTOENCODER_H
  27. #define BADVPN_FLOW_PACKETPROTOENCODER_H
  28. #include <stdint.h>
  29. #include <misc/dead.h>
  30. #include <system/DebugObject.h>
  31. #include <flow/PacketRecvInterface.h>
  32. /**
  33. * Object which encodes packets according to PacketProto.
  34. *
  35. * Input is with {@link PacketRecvInterface}.
  36. * Output is with {@link PacketRecvInterface}.
  37. */
  38. typedef struct {
  39. DebugObject d_obj;
  40. dead_t dead;
  41. PacketRecvInterface *input;
  42. PacketRecvInterface output;
  43. uint8_t *output_packet;
  44. } PacketProtoEncoder;
  45. /**
  46. * Initializes the object.
  47. *
  48. * @param enc the object
  49. * @param input input interface. Its MTU must be <=PACKETPROTO_MAXPAYLOAD.
  50. */
  51. void PacketProtoEncoder_Init (PacketProtoEncoder *enc, PacketRecvInterface *input);
  52. /**
  53. * Frees the object.
  54. *
  55. * @param enc the object
  56. */
  57. void PacketProtoEncoder_Free (PacketProtoEncoder *enc);
  58. /**
  59. * Returns the output interface.
  60. * The MTU of the output interface is PACKETPROTO_ENCLEN(MTU of input interface).
  61. *
  62. * @param enc the object
  63. * @return output interface
  64. */
  65. PacketRecvInterface * PacketProtoEncoder_GetOutput (PacketProtoEncoder *enc);
  66. #endif