mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-07-05 20:41:44 -07:00
Turns out you do have to unpack and compare sockaddr structures due to sin_len / sin6_len not present on all platforms and other junk.
This commit is contained in:
parent
1cfa67bbdd
commit
6f4b30add8
2 changed files with 83 additions and 72 deletions
|
@ -61,16 +61,6 @@ struct InetAddress : public sockaddr_storage
|
|||
*/
|
||||
static const InetAddress LO6;
|
||||
|
||||
/**
|
||||
* 0.0.0.0/0
|
||||
*/
|
||||
static const InetAddress DEFAULT4;
|
||||
|
||||
/**
|
||||
* ::/0
|
||||
*/
|
||||
static const InetAddress DEFAULT6;
|
||||
|
||||
/**
|
||||
* IP address scope
|
||||
*
|
||||
|
@ -91,6 +81,7 @@ struct InetAddress : public sockaddr_storage
|
|||
|
||||
InetAddress() throw() { memset(this,0,sizeof(InetAddress)); }
|
||||
InetAddress(const InetAddress &a) throw() { memcpy(this,&a,sizeof(InetAddress)); }
|
||||
InetAddress(const InetAddress *a) throw() { memcpy(this,a,sizeof(InetAddress)); }
|
||||
InetAddress(const struct sockaddr_storage &ss) throw() { *this = ss; }
|
||||
InetAddress(const struct sockaddr_storage *ss) throw() { *this = ss; }
|
||||
InetAddress(const struct sockaddr &sa) throw() { *this = sa; }
|
||||
|
@ -112,6 +103,13 @@ struct InetAddress : public sockaddr_storage
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline InetAddress &operator=(const InetAddress *a)
|
||||
throw()
|
||||
{
|
||||
memcpy(this,a,sizeof(InetAddress));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline InetAddress &operator=(const struct sockaddr_storage &ss)
|
||||
throw()
|
||||
{
|
||||
|
@ -294,39 +292,6 @@ struct InetAddress : public sockaddr_storage
|
|||
*/
|
||||
inline bool isV6() const throw() { return (ss_family == AF_INET6); }
|
||||
|
||||
/**
|
||||
* Force type to IPv4
|
||||
*/
|
||||
inline void setV4() throw() { ss_family = AF_INET; }
|
||||
|
||||
/**
|
||||
* Force type to IPv6
|
||||
*/
|
||||
inline void setV6() throw() { ss_family = AF_INET6; }
|
||||
|
||||
/**
|
||||
* @return Length of sockaddr_in if IPv4, sockaddr_in6 if IPv6
|
||||
*/
|
||||
inline unsigned int saddrLen() const
|
||||
throw()
|
||||
{
|
||||
switch(ss_family) {
|
||||
case AF_INET: return sizeof(struct sockaddr_in);
|
||||
case AF_INET6: return sizeof(struct sockaddr_in6);
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Raw sockaddr_in structure (valid if IPv4)
|
||||
*/
|
||||
inline const struct sockaddr_in *saddr4() const throw() { return reinterpret_cast<const struct sockaddr_in *>(this); }
|
||||
|
||||
/**
|
||||
* @return Raw sockaddr_in6 structure (valid if IPv6)
|
||||
*/
|
||||
inline const struct sockaddr_in6 *saddr6() const throw() { return reinterpret_cast<const struct sockaddr_in6 *>(this); }
|
||||
|
||||
/**
|
||||
* @return pointer to raw IP address bytes
|
||||
*/
|
||||
|
@ -376,9 +341,9 @@ struct InetAddress : public sockaddr_storage
|
|||
*/
|
||||
inline operator bool() const throw() { return (ss_family != 0); }
|
||||
|
||||
inline bool operator==(const InetAddress &a) const throw() { return (memcmp(this,&a,sizeof(InetAddress)) == 0); }
|
||||
bool operator==(const InetAddress &a) const throw();
|
||||
bool operator<(const InetAddress &a) const throw();
|
||||
inline bool operator!=(const InetAddress &a) const throw() { return !(*this == a); }
|
||||
inline bool operator<(const InetAddress &a) const throw() { return (memcmp(this,&a,sizeof(InetAddress)) < 0); }
|
||||
inline bool operator>(const InetAddress &a) const throw() { return (a < *this); }
|
||||
inline bool operator<=(const InetAddress &a) const throw() { return !(a < *this); }
|
||||
inline bool operator>=(const InetAddress &a) const throw() { return !(*this < a); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue