aes67_net.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * SPDX-FileCopyrightText: 2026 DatanoiseTV
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*
  7. * Network utilities for AES67.
  8. *
  9. * Multicast socket management, IGMP join/leave, IP address helpers.
  10. */
  11. #pragma once
  12. #include <stdint.h>
  13. #include <stdbool.h>
  14. #include "esp_err.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /**
  19. * Create a UDP socket bound to the given port with multicast support.
  20. *
  21. * @param port Local port to bind
  22. * @param reuse Allow address reuse
  23. * @return Socket fd on success, -1 on error
  24. */
  25. int aes67_net_create_udp_socket(uint16_t port, bool reuse);
  26. /**
  27. * Join a multicast group on the given socket.
  28. *
  29. * @param sock Socket fd
  30. * @param mcast_addr Multicast group address string (e.g. "239.69.0.1")
  31. * @param if_addr Local interface address string (NULL for default)
  32. * @return ESP_OK on success
  33. */
  34. esp_err_t aes67_net_join_multicast(int sock, const char *mcast_addr,
  35. const char *if_addr);
  36. /**
  37. * Leave a multicast group.
  38. */
  39. esp_err_t aes67_net_leave_multicast(int sock, const char *mcast_addr,
  40. const char *if_addr);
  41. /**
  42. * Set multicast TTL on a socket.
  43. */
  44. esp_err_t aes67_net_set_multicast_ttl(int sock, uint8_t ttl);
  45. /**
  46. * Set DSCP/TOS on a socket.
  47. */
  48. esp_err_t aes67_net_set_dscp(int sock, uint8_t dscp);
  49. /**
  50. * Set socket send/receive buffer sizes.
  51. */
  52. esp_err_t aes67_net_set_buffers(int sock, int send_size, int recv_size);
  53. /**
  54. * Parse an IPv4 address string to network byte order uint32_t.
  55. */
  56. uint32_t aes67_net_ip_to_u32(const char *ip_str);
  57. /**
  58. * Format a network byte order IPv4 address to string.
  59. */
  60. void aes67_net_u32_to_ip(uint32_t ip, char *buf, size_t len);
  61. /**
  62. * Check if an IP address is multicast (224.0.0.0/4).
  63. */
  64. bool aes67_net_is_multicast(uint32_t ip);
  65. /**
  66. * Get the local interface IP address for the default Ethernet interface.
  67. */
  68. esp_err_t aes67_net_get_local_ip(uint32_t *ip);
  69. /**
  70. * Get the local MAC address.
  71. */
  72. esp_err_t aes67_net_get_local_mac(uint8_t mac[6]);
  73. /**
  74. * Calculate multicast MAC address from multicast IP (IANA mapping).
  75. */
  76. void aes67_net_mcast_ip_to_mac(uint32_t mcast_ip, uint8_t mac[6]);
  77. #ifdef __cplusplus
  78. }
  79. #endif