DataProtoKeepaliveSource.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @file DataProtoKeepaliveSource.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/dataproto.h>
  23. #include <misc/byteorder.h>
  24. #include "DataProtoKeepaliveSource.h"
  25. static void output_handler_recv (DataProtoKeepaliveSource *o, uint8_t *data)
  26. {
  27. DebugObject_Access(&o->d_obj);
  28. struct dataproto_header *header = (struct dataproto_header *)data;
  29. header->flags = htol8(0);
  30. header->from_id = htol16(0);
  31. header->num_peer_ids = htol16(0);
  32. // finish packet
  33. PacketRecvInterface_Done(&o->output, sizeof(struct dataproto_header));
  34. }
  35. void DataProtoKeepaliveSource_Init (DataProtoKeepaliveSource *o, BPendingGroup *pg)
  36. {
  37. // init output
  38. PacketRecvInterface_Init(&o->output, sizeof(struct dataproto_header), (PacketRecvInterface_handler_recv)output_handler_recv, o, pg);
  39. DebugObject_Init(&o->d_obj);
  40. }
  41. void DataProtoKeepaliveSource_Free (DataProtoKeepaliveSource *o)
  42. {
  43. DebugObject_Free(&o->d_obj);
  44. // free output
  45. PacketRecvInterface_Free(&o->output);
  46. }
  47. PacketRecvInterface * DataProtoKeepaliveSource_GetOutput (DataProtoKeepaliveSource *o)
  48. {
  49. DebugObject_Access(&o->d_obj);
  50. return &o->output;
  51. }