![]() |
ParseBuffer() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| Public Function |
Declared in: DNSAnswer.h |
Declaration
int ParseBuffer(
const char* pBuffer,
const char* pOriginalBuffer);
DescriptionParse the answer
Function Body
try
{
//Parse the buffer returns number of byte proccesed
//Copy buffer
const char* pBackupBuffer=pBuffer;
//Parse the name
unsigned short usLength;
m_aAnswer.sName=CDNSParser::ParseName(pBuffer,
pOriginalBuffer,
usLength);
if (!usLength)
{
//Report it
ReportError("ParseBuffer","Received zero length!");
//Exit
return 0;
}
//Increase the buffer
pBackupBuffer+=usLength;
//More fields
memcpy(&m_aAnswer.usType,
pBackupBuffer,
sizeof(m_aAnswer.usType));
m_aAnswer.usType=htons(m_aAnswer.usType);
pBackupBuffer+=sizeof(m_aAnswer.usType);
//More fields
memcpy(&m_aAnswer.usClass,
pBackupBuffer,
sizeof(m_aAnswer.usClass));
m_aAnswer.usClass=htons(m_aAnswer.usClass);
pBackupBuffer+=sizeof(m_aAnswer.usClass);
//More fields
memcpy(&m_aAnswer.ulTTL,
pBackupBuffer,
sizeof(m_aAnswer.ulTTL));
m_aAnswer.ulTTL=htonl(m_aAnswer.ulTTL);
pBackupBuffer+=sizeof(m_aAnswer.ulTTL);
//More fields
memcpy(&m_aAnswer.usRdlLength,
pBackupBuffer,
sizeof(m_aAnswer.usRdlLength));
m_aAnswer.usRdlLength=htons(m_aAnswer.usRdlLength);
pBackupBuffer+=sizeof(m_aAnswer.usRdlLength);
//Error indicator
BOOL bError;
bError=FALSE;
//Our parsed name
std::string sParsedName;
//Parse the last name
if (m_aAnswer.usType==CDNSQuery::CNAME ||
m_aAnswer.usType==CDNSQuery::NS ||
m_aAnswer.usType==CDNSQuery::PTR)
{
//Canonical name
sParsedName=CDNSParser::ParseName(pBackupBuffer,
pOriginalBuffer,
usLength);
//Did we have an error
if (!usLength)
{
//Report it
ReportError("ParseBuffer","Failed to parsed canonical name!");
//Set the error
bError=TRUE;
}
//Set the length
usLength=m_aAnswer.usRdlLength;
}
else if (m_aAnswer.usType==CDNSQuery::A)
{
//Set the length
usLength=m_aAnswer.usRdlLength;
//Is it more then long
if (m_aAnswer.usRdlLength>4)
{
//Report it
ReportError("ParseBuffer","Unexpected A length!",m_aAnswer.usRdlLength);
//Set the error
bError=TRUE;
}
else
{
//Take the long
long lIP;
lIP=*((long*)pBackupBuffer);
//Convert it to string
char aTmp[11];
sprintf(aTmp,"%lu",lIP);
//Put in the string
sParsedName=aTmp;
}
}
else if (m_aAnswer.usType==CDNSQuery::MX)
{
//Read the first 2 bytes
memcpy(&m_usMXPriority,
pBackupBuffer,
sizeof(m_usMXPriority));
//Invert it
m_usMXPriority=htons(m_usMXPriority);
//Read on
//Canonical name
sParsedName=CDNSParser::ParseName(pBackupBuffer+sizeof(m_usMXPriority),
pOriginalBuffer,
usLength);
//Did we have an error
if (!usLength)
{
//Report it
ReportError("ParseBuffer","Failed to parsed MX name!");
//Set the error
bError=TRUE;
}
//Set the length
usLength=m_aAnswer.usRdlLength;
}
else if (m_aAnswer.usType==CDNSQuery::SOA)
{
//Parse it
m_pSOA=ParseSOA(m_aAnswer.usRdlLength,
pBackupBuffer,
pOriginalBuffer);
//Set the length
usLength=m_aAnswer.usRdlLength;
}
else
{
//Report it
ReportError("ParseBuffer","Not supported address type!");
//Done
return 0;
}
//Did we have an error
if (bError)
ReportError("ParseBuffer","Received zero length, trying to recover!");
//Incease our position
pBackupBuffer+=usLength;
//Copy the data
m_aAnswer.sData=sParsedName;
//Number of bytes used
return pBackupBuffer-pBuffer;
}
ERROR_HANDLER_RETURN("ParseBuffer",0)
See Also
This web site was generated
using Surveyor V4.50.811.1. Click
here
for more information. |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |