DataProtoKeepaliveSource.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <flow/DataProtoKeepaliveSource.h>
  25. static int output_handler_recv (DataProtoKeepaliveSource *o, uint8_t *data, int *data_len)
  26. {
  27. struct dataproto_header *header = (struct dataproto_header *)data;
  28. header->flags = 0;
  29. header->from_id = htol16(0);
  30. header->num_peer_ids = htol16(0);
  31. *data_len = sizeof(struct dataproto_header);
  32. return 1;
  33. }
  34. void DataProtoKeepaliveSource_Init (DataProtoKeepaliveSource *o)
  35. {
  36. // init output
  37. PacketRecvInterface_Init(&o->output, sizeof(struct dataproto_header), (PacketRecvInterface_handler_recv)output_handler_recv, o);
  38. // init debug object
  39. DebugObject_Init(&o->d_obj);
  40. }
  41. void DataProtoKeepaliveSource_Free (DataProtoKeepaliveSource *o)
  42. {
  43. // free debug object
  44. DebugObject_Free(&o->d_obj);
  45. // free output
  46. PacketRecvInterface_Free(&o->output);
  47. }
  48. PacketRecvInterface * DataProtoKeepaliveSource_GetOutput (DataProtoKeepaliveSource *o)
  49. {
  50. return &o->output;
  51. }