Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::net::dns::DnsPackage Class Reference

DNS Package Object. More...

#include <DnsPackage.h>

Classes

struct  Answer
 DNS Answer. More...
 
struct  DnsHeader
 
struct  Flags
 DNS Flags Utility. More...
 
class  Index
 DNS Package Compression Index. More...
 
struct  Question
 DNS Question. More...
 

Public Types

using Authority = Answer
 DNS Authority Answer.
 
using Additional = Answer
 DNS Additional Answer.
 
using Ptr = std::shared_ptr<DnsPackage>
 

Public Member Functions

Index buildIndex ()
 
bool encode (void *buffer, size_t &length, Index &index) const
 
std::vector< Question > & getQuestions ()
 
std::vector< Answer > & getAnswers ()
 
std::vector< Authority > & getAuthorities ()
 
std::vector< Additional > & getAdditionals ()
 
auto getId () const
 
auto getFlags () const
 
void setId (uint16_t id)
 
void setFlags (uint16_t flags)
 

Static Public Member Functions

static Ptr new_ ()
 
static Ptr decode (const uint8_t *buffer, size_t length)
 

Private Member Functions

 DnsPackage ()=default
 

Static Private Member Functions

static std::string decodeWords (const uint8_t *buffer, size_t length, size_t &offset)
 
static bool decodeAnswers (std::vector< Answer > &answers, size_t expect_size, const uint8_t *buffer, size_t length, size_t &pos)
 
static std::string encodeWords (const std::string &fullname)
 
static bool encodeQuestions (const std::vector< Question > &questions, void *buffer, size_t &length, Index &index, size_t offset)
 
static bool encodeAnswers (const std::vector< Answer > &answers, void *buffer, size_t &length, Index &index, size_t offset)
 

Private Attributes

struct sese::net::dns::DnsPackage::DnsHeader header
 
std::vector< Questionquestions
 
std::vector< Answeranswers
 
std::vector< Authorityauthorities
 
std::vector< Additionaladditionals
 

Detailed Description

DNS Package Object.

Member Typedef Documentation

◆ Additional

◆ Authority

◆ Ptr

using sese::net::dns::DnsPackage::Ptr = std::shared_ptr<DnsPackage>

Constructor & Destructor Documentation

◆ DnsPackage()

sese::net::dns::DnsPackage::DnsPackage ( )
privatedefault

Referenced by new_().

Member Function Documentation

◆ buildIndex()

DnsPackage::Index DnsPackage::buildIndex ( )

Get DNS Package Compression Index

Returns
Index

References additionals, answers, authorities, and questions.

◆ decode()

DnsPackage::Ptr DnsPackage::decode ( const uint8_t * buffer,
size_t length )
static

Parse DNS raw package

Parameters
bufferDNS package buffer
lengthBuffer size
Returns
Returns object on success, otherwise returns nullptr

References sese::net::dns::DnsPackage::Question::class_, DECODE_HEADER, decodeAnswers(), decodeWords(), FromBigEndian16(), sese::net::dns::DnsPackage::Question::name, new_(), and sese::net::dns::DnsPackage::Question::type.

Referenced by sese::internal::net::service::dns::DnsService::handle().

◆ decodeAnswers()

◆ decodeWords()

std::string DnsPackage::decodeWords ( const uint8_t * buffer,
size_t length,
size_t & offset )
staticprivate

Decode DNS name

Warning
This function performs recursive decoding of multi-level pointers
Parameters
bufferComplete buffer
lengthSize of buffer
offsetOffset to be decoded, ends at 00 position after decoding
Returns
Decoded string

References sese::text::AbstractStringBuffer::append(), decodeWords(), FromBigEndian16(), and sese::text::AbstractStringBuffer::toString().

Referenced by decode(), decodeAnswers(), and decodeWords().

◆ encode()

bool DnsPackage::encode ( void * buffer,
size_t & length,
Index & index ) const

Encode DNS package to buffer

Parameters
bufferOutput buffer
lengthOutput buffer size, returns actual size used on success; if input is 0, calculates required buffer size without actual packaging
indexDNS Package Compression Index
Returns
Whether encoding was successful

References additionals, answers, authorities, sese::net::dns::DnsPackage::Index::clearPos(), encodeAnswers(), encodeQuestions(), sese::net::dns::DnsPackage::DnsHeader::flags, header, sese::net::dns::DnsPackage::DnsHeader::id, questions, and ToBigEndian16().

◆ encodeAnswers()

bool DnsPackage::encodeAnswers ( const std::vector< Answer > & answers,
void * buffer,
size_t & length,
Index & index,
size_t offset )
staticprivate

◆ encodeQuestions()

bool DnsPackage::encodeQuestions ( const std::vector< Question > & questions,
void * buffer,
size_t & length,
Index & index,
size_t offset )
staticprivate

◆ encodeWords()

std::string DnsPackage::encodeWords ( const std::string & fullname)
staticprivate

◆ getAdditionals()

std::vector< Additional > & sese::net::dns::DnsPackage::getAdditionals ( )
inlinenodiscard

References additionals.

◆ getAnswers()

std::vector< Answer > & sese::net::dns::DnsPackage::getAnswers ( )
inlinenodiscard

References answers.

◆ getAuthorities()

std::vector< Authority > & sese::net::dns::DnsPackage::getAuthorities ( )
inlinenodiscard

References authorities.

◆ getFlags()

auto sese::net::dns::DnsPackage::getFlags ( ) const
inlinenodiscard

◆ getId()

auto sese::net::dns::DnsPackage::getId ( ) const
inlinenodiscard

◆ getQuestions()

std::vector< Question > & sese::net::dns::DnsPackage::getQuestions ( )
inlinenodiscard

References questions.

◆ new_()

DnsPackage::Ptr DnsPackage::new_ ( )
static

◆ setFlags()

void sese::net::dns::DnsPackage::setFlags ( uint16_t flags)
inline

◆ setId()

void sese::net::dns::DnsPackage::setId ( uint16_t id)
inline

Member Data Documentation

◆ additionals

std::vector<Additional> sese::net::dns::DnsPackage::additionals
private

Referenced by buildIndex(), encode(), and getAdditionals().

◆ answers

std::vector<Answer> sese::net::dns::DnsPackage::answers
private

◆ authorities

std::vector<Authority> sese::net::dns::DnsPackage::authorities
private

Referenced by buildIndex(), encode(), and getAuthorities().

◆ header

struct sese::net::dns::DnsPackage::DnsHeader sese::net::dns::DnsPackage::header
private

Referenced by encode(), getFlags(), getId(), setFlags(), and setId().

◆ questions

std::vector<Question> sese::net::dns::DnsPackage::questions
private

The documentation for this class was generated from the following files: