SeqPacketSocketSink.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @file SeqPacketSocketSink.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} sink which sends packets to a seqpacket socket.
  25. */
  26. #ifndef BADVPN_FLOW_SEQPACKETSOCKETSINK_H
  27. #define BADVPN_FLOW_SEQPACKETSOCKETSINK_H
  28. #include <stdint.h>
  29. #include <misc/dead.h>
  30. #include <system/DebugObject.h>
  31. #include <system/BSocket.h>
  32. #include <flow/PacketPassInterface.h>
  33. #include <flow/error.h>
  34. #define SEQPACKETSOCKETSINK_ERROR_BSOCKET 1
  35. #define SEQPACKETSOCKETSINK_ERROR_WRONGSIZE 2
  36. /**
  37. * A {@link PacketPassInterface} sink which sends packets to a seqpacket socket.
  38. */
  39. typedef struct {
  40. DebugObject d_obj;
  41. dead_t dead;
  42. FlowErrorReporter rep;
  43. BSocket *bsock;
  44. PacketPassInterface input;
  45. int in_len;
  46. uint8_t *in;
  47. #ifndef NDEBUG
  48. int in_error;
  49. #endif
  50. } SeqPacketSocketSink;
  51. /**
  52. * Initializes the sink.
  53. *
  54. * @param s the object
  55. * @param rep error reporting data. Error code is an int. Possible error codes:
  56. * - SEQPACKETSOCKETSINK_ERROR_BSOCKET: {@link BSocket_Send} failed
  57. * with an unhandled error code
  58. * - SEQPACKETSOCKETSINK_ERROR_WRONGSIZE: {@link BSocket_Send} succeeded,
  59. * but did not send all of the packet
  60. * The object must be freed from the error handler.
  61. * @param bsock socket to write packets to. Registers a BSOCKET_WRITE handler which
  62. * must not be registered.
  63. * @param mtu maximum packet size. Must be >=0.
  64. */
  65. void SeqPacketSocketSink_Init (SeqPacketSocketSink *s, FlowErrorReporter rep, BSocket *bsock, int mtu);
  66. /**
  67. * Frees the sink.
  68. *
  69. * @param s the object
  70. */
  71. void SeqPacketSocketSink_Free (SeqPacketSocketSink *s);
  72. /**
  73. * Returns the input interface.
  74. * The MTU of the interface will be as in {@link SeqPacketSocketSink_Init}.
  75. *
  76. * @param s the object
  77. * @return input interface
  78. */
  79. PacketPassInterface * SeqPacketSocketSink_GetInput (SeqPacketSocketSink *s);
  80. #endif