private:
/// Header bytes of the message
- uint8_t header[sizeof(opaque_header)];
+ opaque_header header;
/// Question list
questions_t question_section;
public:
/// Default constructor
message()
- : question_section(),
+ : header(),
+ question_section(),
answer_section(),
authority_section(),
additional_section()
\param q question to ask
*/
message( const dns::question& q)
- : question_section(),
+ : header(),
+ question_section(),
answer_section(),
authority_section(),
additional_section()
\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()
\param p message to copy from
*/
message(const message& p)
- : question_section(),
+ : header(),
+ question_section(),
answer_section(),
authority_section(),
additional_section()
*/
uint16_t id(const uint16_t d)
{
- ((opaque_header*)header)->Id = d;
- return ((opaque_header*)header)->Id;
+ header.Id = d;
+ return header.Id;
}
/*!
*/
uint16_t id() const
{
- return ((opaque_header*)header)->Id;
+ return header.Id;
}
/*!
action_t action(const action_t e)
{
(e == query) ?
- ((opaque_header*)header)->bit_fields &= static_cast<uint16_t>(~0x8000) :
- ((opaque_header*)header)->bit_fields |= static_cast<uint16_t>(0x8000);
+ header.bit_fields &= static_cast<uint16_t>(~0x8000) :
+ header.bit_fields |= static_cast<uint16_t>(0x8000);
- return (action_t)(((opaque_header*)header)->bit_fields & 0x8000);
+ return (action_t)(header.bit_fields & 0x8000);
}
/*!
*/
action_t action() const
{
- return (action_t)(((opaque_header*)header)->bit_fields & 0x8000);
+ return (action_t)(header.bit_fields & 0x8000);
}
switch( oc )
{
case squery:
- ((opaque_header*)header)->bit_fields &= static_cast<uint16_t>(~0x3000);
+ header.bit_fields &= static_cast<uint16_t>(~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;
*/
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;
*/
void authority(const bool _authority)
{
- (_authority) ? ((opaque_header*)header)->bit_fields |= static_cast<uint16_t>(0x400) :
- ((opaque_header*)header)->bit_fields &= static_cast<uint16_t>(~0x400);
+ (_authority) ? header.bit_fields |= static_cast<uint16_t>(0x400) :
+ header.bit_fields &= static_cast<uint16_t>(~0x400);
}
/*!
*/
bool is_authority() const
{
- return( ((opaque_header*)header)->bit_fields & 0x400 );
+ return( header.bit_fields & 0x400 );
}
/*!
*/
void truncated(const bool _truncated)
{
- (_truncated) ? ((opaque_header*)header)->bit_fields |= static_cast<uint16_t>(0x200) :
- ((opaque_header*)header)->bit_fields &= static_cast<uint16_t>(~0x200);
+ (_truncated) ? header.bit_fields |= static_cast<uint16_t>(0x200) :
+ header.bit_fields &= static_cast<uint16_t>(~0x200);
}
/*!
\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.
*/
void recursive(const bool _recursive)
{
- (_recursive) ? ((opaque_header*)header)->bit_fields |= static_cast<uint16_t>(0x100) :
- ((opaque_header*)header)->bit_fields &= static_cast<uint16_t>(~0x100);
+ (_recursive) ? header.bit_fields |= static_cast<uint16_t>(0x100) :
+ header.bit_fields &= static_cast<uint16_t>(~0x100);
}
/*!
\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.
*/
void recursion_avail(const bool _recursion_avail)
{
- (_recursion_avail) ? ((opaque_header*)header)->bit_fields |= static_cast<uint16_t>(0x80) :
- ((opaque_header*)header)->bit_fields &= static_cast<uint16_t>(~0x80);
+ (_recursion_avail) ? header.bit_fields |= static_cast<uint16_t>(0x80) :
+ header.bit_fields &= static_cast<uint16_t>(~0x80);
}
/*!
*/
bool is_recursion_avail() const
{
- return( ((opaque_header*)header)->bit_fields & 0x80 );
+ return( header.bit_fields & 0x80 );
}
/*!
switch( r )
{
case noerror:
- ((opaque_header*)header)->bit_fields &= static_cast<uint16_t>(~0x07);
+ header.bit_fields &= static_cast<uint16_t>(~0x07);
break;
default:
- ((opaque_header*)header)->bit_fields |= static_cast<uint16_t>(r);
+ header.bit_fields |= static_cast<uint16_t>(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;
*/
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;
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() );
// 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 );