SCKeepaliveSource.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @file SCKeepaliveSource.c
  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. #include <protocol/scproto.h>
  23. #include <misc/byteorder.h>
  24. #include <flow/SCKeepaliveSource.h>
  25. static void output_handler_recv (SCKeepaliveSource *o, uint8_t *data)
  26. {
  27. DebugObject_Access(&o->d_obj);
  28. struct sc_header *header = (struct sc_header *)data;
  29. header->type = htol8(SCID_KEEPALIVE);
  30. PacketRecvInterface_Done(&o->output, sizeof(struct sc_header));
  31. }
  32. void SCKeepaliveSource_Init (SCKeepaliveSource *o, BPendingGroup *pg)
  33. {
  34. // init output
  35. PacketRecvInterface_Init(&o->output, sizeof(struct sc_header), (PacketRecvInterface_handler_recv)output_handler_recv, o, pg);
  36. DebugObject_Init(&o->d_obj);
  37. }
  38. void SCKeepaliveSource_Free (SCKeepaliveSource *o)
  39. {
  40. DebugObject_Free(&o->d_obj);
  41. // free output
  42. PacketRecvInterface_Free(&o->output);
  43. }
  44. PacketRecvInterface * SCKeepaliveSource_GetOutput (SCKeepaliveSource *o)
  45. {
  46. DebugObject_Access(&o->d_obj);
  47. return &o->output;
  48. }