diff --git a/src/client.cpp b/src/client.cpp index d404769..17fbe51 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -519,10 +519,8 @@ ContextImpl::ContextImpl(const Config& conf, const evbase& tcp_loop) log_err_printf(setup, "%s Ignoring %s\n", e.what(), addr.c_str()); continue; } - auto top = ntohl(saddr->in.sin_addr.s_addr)>>24u; - auto ismcast = top>224 && top<239; - bool isbcast = bcasts.find(saddr)!=bcasts.end(); - auto isucast = !isbcast && !ismcast; + // if !bcast and !mcast + auto isucast = bcasts.find(saddr)==bcasts.end() && !saddr.isMCast(); log_info_printf(io, "Searching to %s%s\n", saddr.tostring().c_str(), (isucast?" unicast":"")); searchDest.emplace_back(saddr, isucast); diff --git a/src/osiSockExt.h b/src/osiSockExt.h index 5fb34f7..b39b3d0 100644 --- a/src/osiSockExt.h +++ b/src/osiSockExt.h @@ -44,6 +44,8 @@ public: inline explicit SockAddr(int af, const std::string& address) :SockAddr(af, address.c_str()) {} size_t size() const; + inline + size_t capacity() const { return sizeof(store); } inline unsigned short family() const { return store.sa.sa_family; } unsigned short port() const; @@ -58,6 +60,7 @@ public: bool isAny() const; bool isLO() const; + bool isMCast() const; store_t* operator->() { return &store; } const store_t* operator->() const { return &store; } diff --git a/src/util.cpp b/src/util.cpp index 18ad8a3..48704da 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -350,6 +350,17 @@ bool SockAddr::isLO() const } } +bool SockAddr::isMCast() const +{ + switch(store.sa.sa_family) { + case AF_INET: return IN_MULTICAST(store.in.sin_addr.s_addr); +#ifdef AF_INET6 + case AF_INET6: return IN6_IS_ADDR_MULTICAST(&store.in6.sin6_addr); +#endif + default: return false; + } +} + std::string SockAddr::tostring() const { std::ostringstream strm;