diff options
Diffstat (limited to 'src/Net.cpp')
-rw-r--r-- | src/Net.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Net.cpp b/src/Net.cpp index b993bc194..5c9c5a2f3 100644 --- a/src/Net.cpp +++ b/src/Net.cpp @@ -128,6 +128,19 @@ QByteArray HostAddress::toByteArray() const { return QByteArray(reinterpret_cast<const char *>(qip6.c), 16); } +void HostAddress::toSockaddr(sockaddr_storage *dst) const { + memset(dst, 0, sizeof(*dst)); + if(isV6()) { + struct sockaddr_in6 *in6 = reinterpret_cast<struct sockaddr_in6 *>(dst); + dst->ss_family = AF_INET6; + memcpy(in6->sin6_addr.s6_addr, qip6.c, 16); + } else { + struct sockaddr_in *in = reinterpret_cast<struct sockaddr_in *>(dst); + dst->ss_family = AF_INET; + in->sin_addr.s_addr = hash[3]; + } +} + quint32 qHash(const HostAddress &ha) { return (ha.hash[0] ^ ha.hash[1] ^ ha.hash[2] ^ ha.hash[3]); } |