Brenton/curly braces (#1971)
* fix formatting * properly adjust various lines breakup multiple statements onto multiple lines * insert {} around if, for, etc.
This commit is contained in:
parent
e6802690b8
commit
f73e51e94c
57 changed files with 2247 additions and 1082 deletions
|
@ -94,29 +94,33 @@ struct InetAddress : public sockaddr_storage
|
|||
|
||||
inline InetAddress &operator=(const InetAddress &a)
|
||||
{
|
||||
if (&a != this)
|
||||
if (&a != this) {
|
||||
memcpy(this,&a,sizeof(InetAddress));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline InetAddress &operator=(const InetAddress *a)
|
||||
{
|
||||
if (a != this)
|
||||
if (a != this) {
|
||||
memcpy(this,a,sizeof(InetAddress));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline InetAddress &operator=(const struct sockaddr_storage &ss)
|
||||
{
|
||||
if (reinterpret_cast<const InetAddress *>(&ss) != this)
|
||||
if (reinterpret_cast<const InetAddress *>(&ss) != this) {
|
||||
memcpy(this,&ss,sizeof(InetAddress));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline InetAddress &operator=(const struct sockaddr_storage *ss)
|
||||
{
|
||||
if (reinterpret_cast<const InetAddress *>(ss) != this)
|
||||
if (reinterpret_cast<const InetAddress *>(ss) != this) {
|
||||
memcpy(this,ss,sizeof(InetAddress));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -230,8 +234,9 @@ struct InetAddress : public sockaddr_storage
|
|||
case AF_INET6:
|
||||
const uint8_t *ipb = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
|
||||
for(int i=0;i<16;++i) {
|
||||
if (ipb[i])
|
||||
if (ipb[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return (reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port == 0);
|
||||
}
|
||||
|
@ -260,9 +265,12 @@ struct InetAddress : public sockaddr_storage
|
|||
inline unsigned int port() const
|
||||
{
|
||||
switch(ss_family) {
|
||||
case AF_INET: return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in *>(this)->sin_port));
|
||||
case AF_INET6: return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port));
|
||||
default: return 0;
|
||||
case AF_INET:
|
||||
return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in *>(this)->sin_port));
|
||||
case AF_INET6:
|
||||
return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,8 +292,10 @@ struct InetAddress : public sockaddr_storage
|
|||
{
|
||||
const unsigned int n = port();
|
||||
switch(ss_family) {
|
||||
case AF_INET: return (n <= 32);
|
||||
case AF_INET6: return (n <= 128);
|
||||
case AF_INET:
|
||||
return (n <= 32);
|
||||
case AF_INET6:
|
||||
return (n <= 128);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -356,9 +366,12 @@ struct InetAddress : public sockaddr_storage
|
|||
inline const void *rawIpData() const
|
||||
{
|
||||
switch(ss_family) {
|
||||
case AF_INET: return (const void *)&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr);
|
||||
case AF_INET6: return (const void *)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
|
||||
default: return 0;
|
||||
case AF_INET:
|
||||
return (const void *)&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr);
|
||||
case AF_INET6:
|
||||
return (const void *)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,10 +403,12 @@ struct InetAddress : public sockaddr_storage
|
|||
inline bool ipsEqual(const InetAddress &a) const
|
||||
{
|
||||
if (ss_family == a.ss_family) {
|
||||
if (ss_family == AF_INET)
|
||||
if (ss_family == AF_INET) {
|
||||
return (reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr == reinterpret_cast<const struct sockaddr_in *>(&a)->sin_addr.s_addr);
|
||||
if (ss_family == AF_INET6)
|
||||
}
|
||||
if (ss_family == AF_INET6) {
|
||||
return (memcmp(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr,16) == 0);
|
||||
}
|
||||
return (memcmp(this,&a,sizeof(InetAddress)) == 0);
|
||||
}
|
||||
return false;
|
||||
|
@ -410,10 +425,12 @@ struct InetAddress : public sockaddr_storage
|
|||
inline bool ipsEqual2(const InetAddress &a) const
|
||||
{
|
||||
if (ss_family == a.ss_family) {
|
||||
if (ss_family == AF_INET)
|
||||
if (ss_family == AF_INET) {
|
||||
return (reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr == reinterpret_cast<const struct sockaddr_in *>(&a)->sin_addr.s_addr);
|
||||
if (ss_family == AF_INET6)
|
||||
return (memcmp(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr,8) == 0);
|
||||
}
|
||||
if (ss_family == AF_INET6) {
|
||||
return (memcmp(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr, reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr, 8) == 0);
|
||||
}
|
||||
return (memcmp(this,&a,sizeof(InetAddress)) == 0);
|
||||
}
|
||||
return false;
|
||||
|
@ -426,14 +443,16 @@ struct InetAddress : public sockaddr_storage
|
|||
} else if (ss_family == AF_INET6) {
|
||||
unsigned long tmp = reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port;
|
||||
const uint8_t *a = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
|
||||
for(long i=0;i<16;++i)
|
||||
for(long i=0;i<16;++i) {
|
||||
reinterpret_cast<uint8_t *>(&tmp)[i % sizeof(tmp)] ^= a[i];
|
||||
}
|
||||
return tmp;
|
||||
} else {
|
||||
unsigned long tmp = reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port;
|
||||
const uint8_t *a = reinterpret_cast<const uint8_t *>(this);
|
||||
for(long i=0;i<(long)sizeof(InetAddress);++i)
|
||||
for(long i=0;i<(long)sizeof(InetAddress);++i) {
|
||||
reinterpret_cast<uint8_t *>(&tmp)[i % sizeof(tmp)] ^= a[i];
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
@ -470,8 +489,9 @@ struct InetAddress : public sockaddr_storage
|
|||
while ((ip0 >> 31) == (ip1 >> 31)) {
|
||||
ip0 <<= 1;
|
||||
ip1 <<= 1;
|
||||
if (++c == 32)
|
||||
if (++c == 32) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case AF_INET6: {
|
||||
|
@ -485,8 +505,9 @@ struct InetAddress : public sockaddr_storage
|
|||
uint8_t ip1b = ip1[i];
|
||||
uint8_t bit = 0x80;
|
||||
while (bit != 0) {
|
||||
if ((ip0b & bit) != (ip1b & bit))
|
||||
if ((ip0b & bit) != (ip1b & bit)) {
|
||||
break;
|
||||
}
|
||||
++c;
|
||||
bit >>= 1;
|
||||
}
|
||||
|
@ -512,11 +533,16 @@ struct InetAddress : public sockaddr_storage
|
|||
break;
|
||||
case AF_INET6: {
|
||||
const uint8_t *ip = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
|
||||
h = ((unsigned long)ip[0]); h <<= 1;
|
||||
h += ((unsigned long)ip[1]); h <<= 1;
|
||||
h += ((unsigned long)ip[2]); h <<= 1;
|
||||
h += ((unsigned long)ip[3]); h <<= 1;
|
||||
h += ((unsigned long)ip[4]); h <<= 1;
|
||||
h = ((unsigned long)ip[0]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[1]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[2]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[3]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[4]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[5]);
|
||||
} break;
|
||||
}
|
||||
|
@ -570,13 +596,17 @@ struct InetAddress : public sockaddr_storage
|
|||
return (unsigned int)(b.template at<uint16_t>(p) + 3); // other addresses begin with 16-bit non-inclusive length
|
||||
case 0x04:
|
||||
ss_family = AF_INET;
|
||||
memcpy(&(reinterpret_cast<struct sockaddr_in *>(this)->sin_addr.s_addr),b.field(p,4),4); p += 4;
|
||||
reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p)); p += 2;
|
||||
memcpy(&(reinterpret_cast<struct sockaddr_in *>(this)->sin_addr.s_addr),b.field(p,4),4);
|
||||
p += 4;
|
||||
reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p));
|
||||
p += 2;
|
||||
break;
|
||||
case 0x06:
|
||||
ss_family = AF_INET6;
|
||||
memcpy(reinterpret_cast<struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,b.field(p,16),16); p += 16;
|
||||
reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p)); p += 2;
|
||||
memcpy(reinterpret_cast<struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,b.field(p,16),16);
|
||||
p += 16;
|
||||
reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p));
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_BAD_ENCODING;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue