mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
Make it compile without IPv6
This commit is contained in:
parent
b3b106f9b3
commit
16529b490d
2 changed files with 13 additions and 2 deletions
|
@ -198,7 +198,12 @@ void UDPComponent::setup() {
|
|||
this->header_.push_back(0);
|
||||
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
||||
for (const auto &address : this->addresses_) {
|
||||
#if USE_NETWORK_IPV6
|
||||
struct sockaddr_in6 saddr {};
|
||||
#else
|
||||
struct sockaddr saddr {};
|
||||
#endif
|
||||
|
||||
auto err = socket::set_sockaddr(reinterpret_cast<sockaddr *>(&saddr), sizeof(saddr), address, this->port_);
|
||||
if (err == 0) {
|
||||
ESP_LOGV(TAG, "Couldn't set sockaddr %d", errno);
|
||||
|
@ -589,19 +594,23 @@ void UDPComponent::increment_code_() {
|
|||
void UDPComponent::send_packet_(void *data, size_t len) {
|
||||
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
||||
for (const auto &saddr : this->sockaddrs_) {
|
||||
#if USE_NETWORK_IPV6
|
||||
if (saddr.sin6_family == AF_INET) {
|
||||
auto result =
|
||||
this->broadcast_socket_->sendto(data, len, 0, reinterpret_cast<const sockaddr *>(&saddr), sizeof(saddr));
|
||||
if (result < 0)
|
||||
ESP_LOGW(TAG, "sendto() error %d", errno);
|
||||
}
|
||||
#if USE_NETWORK_IPV6
|
||||
if (saddr.sin6_family == AF_INET6) {
|
||||
auto result =
|
||||
this->broadcast_socket6_->sendto(data, len, 0, reinterpret_cast<const sockaddr *>(&saddr), sizeof(saddr));
|
||||
if (result < 0)
|
||||
ESP_LOGW(TAG, "sendto() error %d", errno);
|
||||
}
|
||||
#else
|
||||
auto result = this->broadcast_socket_->sendto(data, len, 0, &saddr, sizeof(saddr));
|
||||
if (result < 0)
|
||||
ESP_LOGW(TAG, "sendto() error %d", errno);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -125,9 +125,11 @@ class UDPComponent : public PollingComponent {
|
|||
std::unique_ptr<socket::Socket> broadcast_socket_ = nullptr;
|
||||
#if USE_NETWORK_IPV6
|
||||
std::unique_ptr<socket::Socket> broadcast_socket6_ = nullptr;
|
||||
std::vector<struct sockaddr_in6> sockaddrs_{};
|
||||
#else
|
||||
std::vector<struct sockaddr> sockaddrs_{};
|
||||
#endif
|
||||
std::unique_ptr<socket::Socket> listen_socket_ = nullptr;
|
||||
std::vector<struct sockaddr_in6> sockaddrs_{};
|
||||
#else
|
||||
std::vector<IPAddress> ipaddrs_{};
|
||||
WiFiUDP udp_client_{};
|
||||
|
|
Loading…
Reference in a new issue