From ab30405c163c2e5c17f971bb05d9fe901533b599 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Mon, 18 Apr 2011 09:32:46 +0200 Subject: [PATCH] Fixed the type punning from boost::net::dns::message class --- lib/boost-net-dns/boost/net/dns.hpp | 100 ++++++++++++++++++----------------- 1 files changed, 52 insertions(+), 48 deletions(-) diff --git a/lib/boost-net-dns/boost/net/dns.hpp b/lib/boost-net-dns/boost/net/dns.hpp index 510f61e..9859100 100755 --- a/lib/boost-net-dns/boost/net/dns.hpp +++ b/lib/boost-net-dns/boost/net/dns.hpp @@ -2077,7 +2077,7 @@ public: private: /// Header bytes of the message - uint8_t header[sizeof(opaque_header)]; + opaque_header header; /// Question list questions_t question_section; @@ -2091,7 +2091,8 @@ private: public: /// Default constructor message() - : question_section(), + : header(), + question_section(), answer_section(), authority_section(), additional_section() @@ -2105,7 +2106,8 @@ public: \param q question to ask */ message( const dns::question& q) - : question_section(), + : header(), + question_section(), answer_section(), authority_section(), additional_section() @@ -2125,7 +2127,8 @@ public: \param t Resource type to query */ message(const string & d, const type_t t) - : question_section(), + : header(), + question_section(), answer_section(), authority_section(), additional_section() @@ -2144,7 +2147,8 @@ public: \param p message to copy from */ message(const message& p) - : question_section(), + : header(), + question_section(), answer_section(), authority_section(), additional_section() @@ -2190,8 +2194,8 @@ public: */ uint16_t id(const uint16_t d) { - ((opaque_header*)header)->Id = d; - return ((opaque_header*)header)->Id; + header.Id = d; + return header.Id; } /*! @@ -2201,7 +2205,7 @@ public: */ uint16_t id() const { - return ((opaque_header*)header)->Id; + return header.Id; } /*! @@ -2213,10 +2217,10 @@ public: action_t action(const action_t e) { (e == query) ? - ((opaque_header*)header)->bit_fields &= static_cast(~0x8000) : - ((opaque_header*)header)->bit_fields |= static_cast(0x8000); + header.bit_fields &= static_cast(~0x8000) : + header.bit_fields |= static_cast(0x8000); - return (action_t)(((opaque_header*)header)->bit_fields & 0x8000); + return (action_t)(header.bit_fields & 0x8000); } /*! @@ -2226,7 +2230,7 @@ public: */ action_t action() const { - return (action_t)(((opaque_header*)header)->bit_fields & 0x8000); + return (action_t)(header.bit_fields & 0x8000); } @@ -2241,21 +2245,21 @@ public: switch( oc ) { case squery: - ((opaque_header*)header)->bit_fields &= static_cast(~0x3000); + header.bit_fields &= static_cast(~0x3000); return squery; case iquery: - ((opaque_header*)header)->bit_fields |= 0x1000; + header.bit_fields |= 0x1000; return iquery; case status: - ((opaque_header*)header)->bit_fields |= 0x2000; + header.bit_fields |= 0x2000; return status; case no_opcode: break; } - if( ((opaque_header*)header)->bit_fields & 0x1000 ) + if( header.bit_fields & 0x1000 ) return iquery; - if( ((opaque_header*)header)->bit_fields & 0x2000 ) + if( header.bit_fields & 0x2000 ) return status; return squery; @@ -2268,9 +2272,9 @@ public: */ opcode_t opcode() const { - if( ((opaque_header*)header)->bit_fields & 0x1000 ) + if( header.bit_fields & 0x1000 ) return iquery; - if( ((opaque_header*)header)->bit_fields & 0x2000 ) + if( header.bit_fields & 0x2000 ) return status; return squery; @@ -2285,8 +2289,8 @@ public: */ void authority(const bool _authority) { - (_authority) ? ((opaque_header*)header)->bit_fields |= static_cast(0x400) : - ((opaque_header*)header)->bit_fields &= static_cast(~0x400); + (_authority) ? header.bit_fields |= static_cast(0x400) : + header.bit_fields &= static_cast(~0x400); } /*! @@ -2296,7 +2300,7 @@ public: */ bool is_authority() const { - return( ((opaque_header*)header)->bit_fields & 0x400 ); + return( header.bit_fields & 0x400 ); } /*! @@ -2309,8 +2313,8 @@ public: */ void truncated(const bool _truncated) { - (_truncated) ? ((opaque_header*)header)->bit_fields |= static_cast(0x200) : - ((opaque_header*)header)->bit_fields &= static_cast(~0x200); + (_truncated) ? header.bit_fields |= static_cast(0x200) : + header.bit_fields &= static_cast(~0x200); } /*! @@ -2318,7 +2322,7 @@ public: \return True if the server is truncating the message */ - bool is_truncated() const { return( ((opaque_header*)header)->bit_fields & 0x200 ); } + bool is_truncated() const { return( header.bit_fields & 0x200 ); } /*! Sets the 'recursive' field. @@ -2331,8 +2335,8 @@ public: */ void recursive(const bool _recursive) { - (_recursive) ? ((opaque_header*)header)->bit_fields |= static_cast(0x100) : - ((opaque_header*)header)->bit_fields &= static_cast(~0x100); + (_recursive) ? header.bit_fields |= static_cast(0x100) : + header.bit_fields &= static_cast(~0x100); } /*! @@ -2340,7 +2344,7 @@ public: \return True if the server can recursively seek an answer. */ - bool is_recursive() const { return( ((opaque_header*)header)->bit_fields & 0x100 ); } + bool is_recursive() const { return( header.bit_fields & 0x100 ); } /*! Sets the 'recursion availability' field. @@ -2353,8 +2357,8 @@ public: */ void recursion_avail(const bool _recursion_avail) { - (_recursion_avail) ? ((opaque_header*)header)->bit_fields |= static_cast(0x80) : - ((opaque_header*)header)->bit_fields &= static_cast(~0x80); + (_recursion_avail) ? header.bit_fields |= static_cast(0x80) : + header.bit_fields &= static_cast(~0x80); } /*! @@ -2364,7 +2368,7 @@ public: */ bool is_recursion_avail() const { - return( ((opaque_header*)header)->bit_fields & 0x80 ); + return( header.bit_fields & 0x80 ); } /*! @@ -2378,30 +2382,30 @@ public: switch( r ) { case noerror: - ((opaque_header*)header)->bit_fields &= static_cast(~0x07); + header.bit_fields &= static_cast(~0x07); break; default: - ((opaque_header*)header)->bit_fields |= static_cast(r); + header.bit_fields |= static_cast(r); break; } - if( ((opaque_header*)header)->bit_fields & 0x01 ) + if( header.bit_fields & 0x01 ) return format_error; - if( ((opaque_header*)header)->bit_fields & 0x02 ) + if( header.bit_fields & 0x02 ) return server_error; - if( ((opaque_header*)header)->bit_fields & 0x03 ) + if( header.bit_fields & 0x03 ) return name_error; - if( ((opaque_header*)header)->bit_fields & 0x04 ) + if( header.bit_fields & 0x04 ) return not_implemented; - if( ((opaque_header*)header)->bit_fields & 0x05 ) + if( header.bit_fields & 0x05 ) return refused; - if( ((opaque_header*)header)->bit_fields & 0x06 ) + if( header.bit_fields & 0x06 ) return no_result; return noerror; @@ -2414,22 +2418,22 @@ public: */ result_t result() const { - if( ((opaque_header*)header)->bit_fields & 0x01 ) + if( header.bit_fields & 0x01 ) return format_error; - if( ((opaque_header*)header)->bit_fields & 0x02 ) + if( header.bit_fields & 0x02 ) return server_error; - if( ((opaque_header*)header)->bit_fields & 0x03 ) + if( header.bit_fields & 0x03 ) return name_error; - if( ((opaque_header*)header)->bit_fields & 0x04 ) + if( header.bit_fields & 0x04 ) return not_implemented; - if( ((opaque_header*)header)->bit_fields & 0x05 ) + if( header.bit_fields & 0x05 ) return refused; - if( ((opaque_header*)header)->bit_fields & 0x06 ) + if( header.bit_fields & 0x06 ) return no_result; return noerror; @@ -2455,8 +2459,8 @@ public: rfc1035_414_t offset_map; - buffer.put( ((opaque_header*)header)->Id ); - buffer.put( ((opaque_header*)header)->bit_fields ); + buffer.put( header.Id ); + buffer.put( header.bit_fields ); buffer.put( (uint16_t)question_section.size() ); buffer.put( (uint16_t)answer_section.size() ); buffer.put( (uint16_t)authority_section.size() ); @@ -2490,7 +2494,7 @@ public: // start at 0th buffer.position(0); - opaque_header* pHeader = (opaque_header*)header; + opaque_header* pHeader = &header; buffer.get( pHeader->Id ); buffer.get( pHeader->bit_fields ); -- 1.7.1