From: Stephan Bosch Date: Mon, 30 Sep 2019 08:30:24 +0000 (+0200) Subject: Reformat iputils.hh X-Git-Tag: auth-4.3.0-beta2~20^2~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=389fa92ec92ba9247dc5cd8f0eefb1329b777d8e;p=thirdparty%2Fpdns.git Reformat iputils.hh Mainly removed whitespace at end of line and fixed several indenting mishaps. --- diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 77b5667ee2..132b7bc3ce 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -111,12 +111,12 @@ union ComboAddress { { if(sin4.sin_family == 0) { return false; - } + } if(boost::tie(sin4.sin_family, sin4.sin_port) < boost::tie(rhs.sin4.sin_family, rhs.sin4.sin_port)) return true; if(boost::tie(sin4.sin_family, sin4.sin_port) > boost::tie(rhs.sin4.sin_family, rhs.sin4.sin_port)) return false; - + if(sin4.sin_family == AF_INET) return sin4.sin_addr.s_addr < rhs.sin4.sin_addr.s_addr; else @@ -130,8 +130,8 @@ union ComboAddress { struct addressOnlyHash { - uint32_t operator()(const ComboAddress& ca) const - { + uint32_t operator()(const ComboAddress& ca) const + { const unsigned char* start; int len; if(ca.sin4.sin_family == AF_INET) { @@ -182,8 +182,8 @@ union ComboAddress { else return sizeof(sin6); } - - ComboAddress() + + ComboAddress() { sin4.sin_family=AF_INET; sin4.sin_addr.s_addr=0; @@ -218,8 +218,8 @@ union ComboAddress { if(makeIPv4sockaddr(str, &sin4)) { sin6.sin6_family = AF_INET6; if(makeIPv6sockaddr(str, &sin6) < 0) - throw PDNSException("Unable to convert presentation address '"+ str +"'"); - + throw PDNSException("Unable to convert presentation address '"+ str +"'"); + } if(!sin4.sin_port) // 'str' overrides port! sin4.sin_port=htons(port); @@ -238,20 +238,20 @@ union ComboAddress { { if(sin4.sin_family!=AF_INET6) return false; - + int n=0; const unsigned char*ptr = (unsigned char*) &sin6.sin6_addr.s6_addr; for(n=0; n < 10; ++n) if(ptr[n]) return false; - + for(; n < 12; ++n) if(ptr[n]!=0xff) return false; - + return true; } - + ComboAddress mapToIPv4() const { if(!isMappedIPv4()) @@ -259,7 +259,7 @@ union ComboAddress { ComboAddress ret; ret.sin4.sin_family=AF_INET; ret.sin4.sin_port=sin4.sin_port; - + const unsigned char*ptr = (unsigned char*) &sin6.sin6_addr.s6_addr; ptr+=(sizeof(sin6.sin6_addr.s6_addr) - sizeof(ret.sin4.sin_addr.s_addr)); memcpy(&ret.sin4.sin_addr.s_addr, ptr, sizeof(ret.sin4.sin_addr.s_addr)); @@ -320,7 +320,7 @@ union ComboAddress { }; /** This exception is thrown by the Netmask class and by extension by the NetmaskGroup class */ -class NetmaskException: public PDNSException +class NetmaskException: public PDNSException { public: NetmaskException(const string &a) : PDNSException(a) {} @@ -333,7 +333,7 @@ inline ComboAddress makeComboAddress(const string& str) if(inet_pton(AF_INET, str.c_str(), &address.sin4.sin_addr) <= 0) { address.sin4.sin_family=AF_INET6; if(makeIPv6sockaddr(str, &address.sin6) < 0) - throw NetmaskException("Unable to convert '"+str+"' to a netmask"); + throw NetmaskException("Unable to convert '"+str+"' to a netmask"); } return address; } @@ -369,31 +369,31 @@ class Netmask public: Netmask() { - d_network.sin4.sin_family=0; // disable this doing anything useful - d_network.sin4.sin_port = 0; // this guarantees d_network compares identical - d_mask=0; - d_bits=0; + d_network.sin4.sin_family=0; // disable this doing anything useful + d_network.sin4.sin_port = 0; // this guarantees d_network compares identical + d_mask=0; + d_bits=0; } - + Netmask(const ComboAddress& network, uint8_t bits=0xff): d_network(network) { d_network.sin4.sin_port=0; if(bits > 128) bits = (network.sin4.sin_family == AF_INET) ? 32 : 128; - + d_bits = bits; if(d_bits<32) d_mask=~(0xFFFFFFFF>>d_bits); else d_mask=0xFFFFFFFF; // not actually used for IPv6 } - - //! Constructor supplies the mask, which cannot be changed - Netmask(const string &mask) + + //! Constructor supplies the mask, which cannot be changed + Netmask(const string &mask) { pair split=splitField(mask,'/'); d_network=makeComboAddress(split.first); - + if(!split.second.empty()) { d_bits = (uint8_t)pdns_stou(split.second); if(d_bits<32) @@ -429,7 +429,7 @@ public: uint8_t bytes=d_bits/8, n; const uint8_t *us=(const uint8_t*) &d_network.sin6.sin6_addr.s6_addr; const uint8_t *them=(const uint8_t*) &ip->sin6.sin6_addr.s6_addr; - + for(n=0; n < bytes; ++n) { if(us[n]!=them[n]) { return false; @@ -506,7 +506,7 @@ public: return d_network.sin4.sin_family == AF_INET; } - bool operator<(const Netmask& rhs) const + bool operator<(const Netmask& rhs) const { if (empty() && !rhs.empty()) return false; @@ -527,12 +527,12 @@ public: return rhs.operator<(*this); } - bool operator==(const Netmask& rhs) const + bool operator==(const Netmask& rhs) const { return tie(d_network, d_bits) == tie(rhs.d_network, rhs.d_bits); } - bool empty() const + bool empty() const { return d_network.sin4.sin_family==0; } @@ -576,35 +576,35 @@ private: */ class TreeNode : boost::noncopyable { public: - explicit TreeNode(int bits) noexcept : parent(NULL),d_bits(bits) { - } - - //(new TreeNode(d_bits+1)); - left->parent = this; - } - return left.get(); - } - - //(new TreeNode(d_bits+1)); - right->parent = this; - } - return right.get(); - } - - unique_ptr left; - unique_ptr right; - TreeNode* parent; - - unique_ptr node4; // node6; //(new TreeNode(d_bits+1)); + left->parent = this; + } + return left.get(); + } + + //(new TreeNode(d_bits+1)); + right->parent = this; + } + return right.get(); + } + + unique_ptr left; + unique_ptr right; + TreeNode* parent; + + unique_ptr node4; // node6; //parent; // delete this node if (pparent) { - if (pparent->left.get() == node) - pparent->left.reset(); - else - pparent->right.reset(); - // now recurse up to the parent - cleanup_tree(pparent); + if (pparent->left.get() == node) + pparent->left.reset(); + else + pparent->right.reset(); + // now recurse up to the parent + cleanup_tree(pparent); } } } @@ -1009,7 +1009,6 @@ private: NetmaskTree tree; }; - struct SComboAddress { SComboAddress(const ComboAddress& orig) : ca(orig) {} @@ -1049,7 +1048,7 @@ void setSocketIgnorePMTU(int sockfd); #if defined(IP_PKTINFO) #define GEN_IP_PKTINFO IP_PKTINFO #elif defined(IP_RECVDSTADDR) - #define GEN_IP_PKTINFO IP_RECVDSTADDR + #define GEN_IP_PKTINFO IP_RECVDSTADDR #endif bool IsAnyAddress(const ComboAddress& addr);