UDPAddrIface.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "exception/Err.h"
  16. #include "rust/cjdns_sys/Rffi.h"
  17. #include "util/events/UDPAddrIface.h"
  18. #include "memory/Allocator.h"
  19. #include "util/platform/Sockaddr.h"
  20. #include "util/Identity.h"
  21. struct UDPAddrIface_pvt {
  22. struct UDPAddrIface pub;
  23. Rffi_UDPIface* internal;
  24. Identity
  25. };
  26. int UDPAddrIface_setDSCP(struct UDPAddrIface* iface, uint8_t dscp)
  27. {
  28. struct UDPAddrIface_pvt* ifp = Identity_check((struct UDPAddrIface_pvt*)iface);
  29. return Rffi_udpIfaceSetDscp(ifp->internal->pvt, dscp);
  30. }
  31. int UDPAddrIface_getFd(struct UDPAddrIface* iface)
  32. {
  33. struct UDPAddrIface_pvt* ifp = Identity_check((struct UDPAddrIface_pvt*)iface);
  34. return Rffi_udpIfaceGetFd(ifp->internal->pvt);
  35. }
  36. int UDPAddrIface_setBroadcast(struct UDPAddrIface* iface, bool enable)
  37. {
  38. struct UDPAddrIface_pvt* ifp = Identity_check((struct UDPAddrIface_pvt*)iface);
  39. return (int) Rffi_udpIfaceSetBroadcast(ifp->internal->pvt, enable);
  40. }
  41. Err_DEFUN UDPAddrIface_workerStates(
  42. Object_t** out,
  43. struct UDPAddrIface* iface,
  44. Allocator_t* alloc)
  45. {
  46. struct UDPAddrIface_pvt* ifp = Identity_check((struct UDPAddrIface_pvt*)iface);
  47. return Rffi_udpIface_worker_states(out, ifp->internal->pvt, alloc);
  48. }
  49. Err_DEFUN UDPAddrIface_new(
  50. struct UDPAddrIface** outP,
  51. struct Sockaddr* addr,
  52. struct Allocator* userAlloc)
  53. {
  54. Rffi_UDPIface* internal = NULL;
  55. Err(Rffi_udpIfaceNew(&internal, addr, userAlloc));
  56. struct UDPAddrIface_pvt* out =
  57. Allocator_calloc(userAlloc, sizeof(struct UDPAddrIface_pvt), 1);
  58. out->pub.generic.iface = internal->iface;
  59. out->pub.generic.addr = internal->local_addr;
  60. out->pub.generic.alloc = userAlloc;
  61. out->internal = internal;
  62. Identity_set(out);
  63. *outP = &out->pub;
  64. return NULL;
  65. }