Implemented udp sender for ipv6
This commit is contained in:
@ -82,4 +82,17 @@ tl::expected<void, std::string> UdpSender::send(const struct sockaddr_in &recipi
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tl::expected<void, std::string> UdpSender::send(const struct sockaddr_in6 &recipient, std::string_view buf)
|
||||||
|
{
|
||||||
|
if (!ready())
|
||||||
|
return tl::make_unexpected("initializing failed, not ready to send");
|
||||||
|
|
||||||
|
if (const ssize_t sent = sendto(m_udp_server, buf.data(), buf.size(), 0, (const struct sockaddr*)&recipient, sizeof(recipient)); sent < 0)
|
||||||
|
return tl::make_unexpected(fmt::format("send failed with {} (errno={})", sent, errno));
|
||||||
|
else if (sent != buf.size())
|
||||||
|
return tl::make_unexpected(fmt::format("sent bytes does not match, expected={}, sent={}", buf.size(), sent));
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace wifi_stack
|
} // namespace wifi_stack
|
||||||
|
@ -27,6 +27,7 @@ public:
|
|||||||
tl::expected<void, std::string> send(esp_netif_t *interf, uint16_t port, std::string_view buf);
|
tl::expected<void, std::string> send(esp_netif_t *interf, uint16_t port, std::string_view buf);
|
||||||
tl::expected<void, std::string> send(const esp_netif_ip_info_t &ip, uint16_t port, std::string_view buf);
|
tl::expected<void, std::string> send(const esp_netif_ip_info_t &ip, uint16_t port, std::string_view buf);
|
||||||
tl::expected<void, std::string> send(const struct sockaddr_in &recipient, std::string_view buf);
|
tl::expected<void, std::string> send(const struct sockaddr_in &recipient, std::string_view buf);
|
||||||
|
tl::expected<void, std::string> send(const struct sockaddr_in6 &recipient, std::string_view buf);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int m_udp_server;
|
const int m_udp_server;
|
||||||
|
Reference in New Issue
Block a user