KomodiaDNS::CDNSAnswer Class Reference#include <DNSAnswer.h>
Inheritance diagram for KomodiaDNS::CDNSAnswer:
![]()
Collaboration diagram for KomodiaDNS::CDNSAnswer:
![]()
Detailed DescriptionDefinition at line 90 of file DNSAnswer.h. Member Typedef Documentation
Member Enumeration Documentation
Definition at line 94 of file DNSAnswer.h. 00095 { 00096 dhQuestion, 00097 dhAnswer, 00098 dhAuthoritive, 00099 dhAdditional, 00100 dhNone 00101 } DnsHeaderType;
Definition at line 53 of file ErrorHandler.h. 00054 { 00055 lpDebug, 00056 lpMessage, 00057 lpCritical, 00058 lpError 00059 } LogPriority;
Constructor & Destructor Documentation
Definition at line 57 of file DNSAnswer.cpp. 00057 : CErrorHandler(), 00058 m_aAnswerType(dhNone), 00059 m_usMXPriority(0), 00060 m_pSOA(NULL) 00061 { 00062 try 00063 { 00064 //Set our name 00065 SetName(CDNSAnswer_Class); 00066 } 00067 ERROR_HANDLER("CDNSAnswer") 00068 }
Definition at line 70 of file DNSAnswer.cpp. 00070 : CErrorHandler(rAnswer), 00071 m_aAnswerType(rAnswer.m_aAnswerType), 00072 m_usMXPriority(rAnswer.m_usMXPriority), 00073 m_pSOA(NULL), 00074 m_aAnswer(rAnswer.m_aAnswer) 00075 { 00076 try 00077 { 00078 //Set our name 00079 SetName(CDNSAnswer_Class); 00080 00081 //Do we have SOA record? 00082 if (rAnswer.m_pSOA) 00083 //Copy it 00084 m_pSOA=new DNSSOARecord(*rAnswer.m_pSOA); 00085 } 00086 ERROR_HANDLER("CDNSAnswer") 00087 }
Definition at line 89 of file DNSAnswer.cpp. 00090 { 00091 try 00092 { 00093 //Delete the data 00094 DeleteBuffer(); 00095 } 00096 ERROR_HANDLER("~CDNSAnswer") 00097 }
Member Function Documentation
Definition at line 122 of file ErrorHandler.cpp. 00123 { 00124 try 00125 { 00126 //Get the error string 00127 LPVOID lpMsgBuf; 00128 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 00129 FORMAT_MESSAGE_FROM_SYSTEM | 00130 FORMAT_MESSAGE_IGNORE_INSERTS, 00131 NULL, 00132 dwErrorCode, 00133 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 00134 (LPTSTR) &lpMsgBuf, 00135 0, 00136 NULL); 00137 00138 //Save it 00139 std::string sMessage; 00140 sMessage+=(char*)lpMsgBuf; 00141 00142 //Release the buffer 00143 LocalFree(lpMsgBuf); 00144 00145 //Done 00146 return sMessage; 00147 } 00148 catch (...) 00149 { 00150 return "Unknown"; 00151 } 00152 }
Definition at line 425 of file DNSAnswer.cpp. 00427 { 00428 try 00429 { 00430 //Line terminator 00431 //End of line 00432 char aEndOfLine[3]; 00433 00434 //Which is it 00435 if (bWindowsLines) 00436 { 00437 aEndOfLine[0]=13; 00438 aEndOfLine[1]=10; 00439 aEndOfLine[2]=0; 00440 } 00441 else 00442 { 00443 aEndOfLine[0]='\n'; 00444 aEndOfLine[1]=0; 00445 } 00446 00447 //Our answer 00448 std::string sAnswer; 00449 00450 //The answer 00451 //What are we 00452 if (m_aAnswer.usType==CDNSQuery::SOA) 00453 { 00454 //Our name 00455 sAnswer+=m_aAnswer.sName; 00456 sAnswer+=aEndOfLine; 00457 00458 //Dump the soa data 00459 sAnswer+=GetSOARecord(std::string(" "), 00460 aEndOfLine); 00461 } 00462 if (m_aAnswer.usType==CDNSQuery::A) 00463 { 00464 //Regular address 00465 //Is it an address 00466 if (m_aAnswerType==dhAnswer) 00467 { 00468 //Our name 00469 sAnswer+="Name: "; 00470 sAnswer+=m_aAnswer.sName; 00471 sAnswer+=aEndOfLine; 00472 00473 //Address 00474 sAnswer+="Address: "; 00475 } 00476 else if (m_aAnswerType==dhAdditional) 00477 { 00478 //Our name 00479 sAnswer+=m_aAnswer.sName; 00480 sAnswer+=' '; 00481 00482 //Address prefix 00483 sAnswer+="internet address = "; 00484 } 00485 00486 //The address 00487 sAnswer+=CSpoofBase::LongToStdString(atol(m_aAnswer.sData.c_str())); 00488 } 00489 else if (m_aAnswer.usType==CDNSQuery::MX) 00490 { 00491 //Our name 00492 sAnswer+=m_aAnswer.sName; 00493 sAnswer+=' '; 00494 00495 //Convert the prefrence 00496 char aTmp[11]; 00497 itoa(m_usMXPriority,aTmp,10); 00498 00499 //MX prefrence 00500 sAnswer+="MX preference = "; 00501 sAnswer+=aTmp; 00502 sAnswer+=std::string(", "); 00503 00504 //MX address 00505 sAnswer+="mail exchanger = "; 00506 sAnswer+=m_aAnswer.sData; 00507 } 00508 else if (m_aAnswer.usType==CDNSQuery::NS) 00509 { 00510 //Our name 00511 sAnswer+=m_aAnswer.sName; 00512 sAnswer+=' '; 00513 00514 //The address 00515 sAnswer+="nameserver = "; 00516 sAnswer+=m_aAnswer.sData; 00517 } 00518 else if (m_aAnswer.usType==CDNSQuery::PTR) 00519 { 00520 //Our name 00521 sAnswer+=m_aAnswer.sName; 00522 sAnswer+=' '; 00523 00524 //The address 00525 sAnswer+="name = "; 00526 sAnswer+=m_aAnswer.sData; 00527 } 00528 00529 //Done 00530 return sAnswer; 00531 } 00532 ERROR_HANDLER_RETURN("GetAnswerParsed","") 00533 }
Definition at line 521 of file ErrorHandler.cpp. 00522 { 00523 try 00524 { 00525 //Our string 00526 std::string sDate; 00527 00528 //Our tmp buf 00529 char cTmp[128]; 00530 00531 //Get date 00532 _strdate(cTmp); 00533 sDate=cTmp; 00534 sDate+=' '; 00535 00536 //Get time 00537 _strtime(cTmp); 00538 sDate+=cTmp; 00539 00540 //Done 00541 return sDate; 00542 } 00543 ERROR_HANDLER_STATIC_RETURN(CErrorHandler_Class,"GetCurrentDateTime","") 00544 }
Definition at line 327 of file DNSAnswer.cpp. 00328 { 00329 return (CDNSQuery::DNSQueryTypes)m_aAnswer.usType; 00330 }
Definition at line 99 of file DNSAnswer.cpp. 00100 { 00101 //Check if we are the same? 00102 if (this==&rAnswer) 00103 return *this; 00104 00105 //Start to copy the data 00106 m_aAnswerType=rAnswer.m_aAnswerType; 00107 m_aAnswer=rAnswer.m_aAnswer; 00108 m_usMXPriority=rAnswer.m_usMXPriority; 00109 m_aAnswer=rAnswer.m_aAnswer; 00110 00111 //Delete the SOA 00112 delete m_pSOA; 00113 00114 //Do we need to copy it 00115 if (rAnswer.m_pSOA) 00116 m_pSOA=new DNSSOARecord(*rAnswer.m_pSOA); 00117 else 00118 m_pSOA=NULL; 00119 00120 //Done 00121 return *this; 00122 }
Definition at line 129 of file DNSAnswer.cpp. 00131 { 00132 try 00133 { 00134 //Parse the buffer returns number of byte proccesed 00135 //Copy buffer 00136 const char* pBackupBuffer=pBuffer; 00137 00138 //Parse the name 00139 unsigned short usLength; 00140 m_aAnswer.sName=CDNSParser::ParseName(pBuffer, 00141 pOriginalBuffer, 00142 usLength); 00143 00144 if (!usLength) 00145 { 00146 //Report it 00147 ReportError("ParseBuffer","Received zero length!"); 00148 00149 //Exit 00150 return 0; 00151 } 00152 00153 //Increase the buffer 00154 pBackupBuffer+=usLength; 00155 00156 //More fields 00157 memcpy(&m_aAnswer.usType, 00158 pBackupBuffer, 00159 sizeof(m_aAnswer.usType)); 00160 m_aAnswer.usType=htons(m_aAnswer.usType); 00161 pBackupBuffer+=sizeof(m_aAnswer.usType); 00162 00163 //More fields 00164 memcpy(&m_aAnswer.usClass, 00165 pBackupBuffer, 00166 sizeof(m_aAnswer.usClass)); 00167 m_aAnswer.usClass=htons(m_aAnswer.usClass); 00168 pBackupBuffer+=sizeof(m_aAnswer.usClass); 00169 00170 //More fields 00171 memcpy(&m_aAnswer.ulTTL, 00172 pBackupBuffer, 00173 sizeof(m_aAnswer.ulTTL)); 00174 m_aAnswer.ulTTL=htonl(m_aAnswer.ulTTL); 00175 pBackupBuffer+=sizeof(m_aAnswer.ulTTL); 00176 00177 //More fields 00178 memcpy(&m_aAnswer.usRdlLength, 00179 pBackupBuffer, 00180 sizeof(m_aAnswer.usRdlLength)); 00181 m_aAnswer.usRdlLength=htons(m_aAnswer.usRdlLength); 00182 pBackupBuffer+=sizeof(m_aAnswer.usRdlLength); 00183 00184 //Error indicator 00185 BOOL bError; 00186 bError=FALSE; 00187 00188 //Our parsed name 00189 std::string sParsedName; 00190 00191 //Parse the last name 00192 if (m_aAnswer.usType==CDNSQuery::CNAME || 00193 m_aAnswer.usType==CDNSQuery::NS || 00194 m_aAnswer.usType==CDNSQuery::PTR) 00195 { 00196 //Canonical name 00197 sParsedName=CDNSParser::ParseName(pBackupBuffer, 00198 pOriginalBuffer, 00199 usLength); 00200 00201 //Did we have an error 00202 if (!usLength) 00203 { 00204 //Report it 00205 ReportError("ParseBuffer","Failed to parsed canonical name!"); 00206 00207 //Set the error 00208 bError=TRUE; 00209 } 00210 00211 //Set the length 00212 usLength=m_aAnswer.usRdlLength; 00213 } 00214 else if (m_aAnswer.usType==CDNSQuery::A) 00215 { 00216 //Set the length 00217 usLength=m_aAnswer.usRdlLength; 00218 00219 //Is it more then long 00220 if (m_aAnswer.usRdlLength>4) 00221 { 00222 //Report it 00223 ReportError("ParseBuffer","Unexpected A length!",m_aAnswer.usRdlLength); 00224 00225 //Set the error 00226 bError=TRUE; 00227 } 00228 else 00229 { 00230 //Take the long 00231 long lIP; 00232 lIP=*((long*)pBackupBuffer); 00233 00234 //Convert it to string 00235 char aTmp[11]; 00236 sprintf(aTmp,"%lu",lIP); 00237 00238 //Put in the string 00239 sParsedName=aTmp; 00240 } 00241 } 00242 else if (m_aAnswer.usType==CDNSQuery::MX) 00243 { 00244 //Read the first 2 bytes 00245 memcpy(&m_usMXPriority, 00246 pBackupBuffer, 00247 sizeof(m_usMXPriority)); 00248 00249 //Invert it 00250 m_usMXPriority=htons(m_usMXPriority); 00251 00252 //Read on 00253 //Canonical name 00254 sParsedName=CDNSParser::ParseName(pBackupBuffer+sizeof(m_usMXPriority), 00255 pOriginalBuffer, 00256 usLength); 00257 00258 //Did we have an error 00259 if (!usLength) 00260 { 00261 //Report it 00262 ReportError("ParseBuffer","Failed to parsed MX name!"); 00263 00264 //Set the error 00265 bError=TRUE; 00266 } 00267 00268 //Set the length 00269 usLength=m_aAnswer.usRdlLength; 00270 } 00271 else if (m_aAnswer.usType==CDNSQuery::SOA) 00272 { 00273 //Parse it 00274 m_pSOA=ParseSOA(m_aAnswer.usRdlLength, 00275 pBackupBuffer, 00276 pOriginalBuffer); 00277 00278 //Set the length 00279 usLength=m_aAnswer.usRdlLength; 00280 } 00281 else 00282 { 00283 //Report it 00284 ReportError("ParseBuffer","Not supported address type!"); 00285 00286 //Done 00287 return 0; 00288 } 00289 00290 //Did we have an error 00291 if (bError) 00292 ReportError("ParseBuffer","Received zero length, trying to recover!"); 00293 00294 //Incease our position 00295 pBackupBuffer+=usLength; 00296 00297 //Copy the data 00298 m_aAnswer.sData=sParsedName; 00299 00300 //Number of bytes used 00301 return pBackupBuffer-pBuffer; 00302 } 00303 ERROR_HANDLER_RETURN("ParseBuffer",0) 00304 }
Definition at line 154 of file ErrorHandler.cpp. 00157 { 00158 if (!GetLog()) 00159 return; 00160 00161 try 00162 { 00163 //Get the log 00164 CErrorLog* pLog; 00165 pLog=GetLog(); 00166 00167 //Convert the error code 00168 char aTmp[11]; 00169 sprintf(aTmp,"%d",iErrorCode); 00170 00171 //Get the string for it 00172 std::string sError; 00173 sError=rMessage; 00174 sError+=", and Socket error: "; 00175 sError+=aTmp; 00176 sError+=", "; 00177 sError+=ErrorCodeToString(iErrorCode); 00178 00179 //Report to the log 00180 pLog->ReportError(m_sClassName, 00181 rMethod, 00182 sError); 00183 } 00184 ERROR_UNKNOWN("ReportError") 00185 }
Definition at line 187 of file ErrorHandler.cpp. 00189 { 00190 if (!GetLog()) 00191 return; 00192 00193 try 00194 { 00195 //Get the log 00196 CErrorLog* pLog; 00197 pLog=GetLog(); 00198 00199 //Convert the error code 00200 char aTmp[11]; 00201 sprintf(aTmp,"%d",iErrorCode); 00202 00203 //Get the string for it 00204 std::string sError; 00205 sError="Socket error: "; 00206 sError+=aTmp; 00207 sError+=", "; 00208 sError+=ErrorCodeToString(iErrorCode); 00209 00210 //Report to the log 00211 pLog->ReportError(m_sClassName, 00212 rMethod, 00213 sError); 00214 } 00215 ERROR_UNKNOWN("ReportError") 00216 }
Definition at line 275 of file ErrorHandler.cpp. 00278 { 00279 if (!GetLog()) 00280 return; 00281 00282 try 00283 { 00284 //Get the log 00285 CErrorLog* pLog; 00286 pLog=GetLog(); 00287 00288 //Convert the number 00289 char aTmp[11]; 00290 ltoa(dwAdditionalData,aTmp,10); 00291 00292 //Create the new message 00293 std::string sNewMessage(rMessage); 00294 sNewMessage+="Additional data: "; 00295 sNewMessage+=aTmp; 00296 00297 //Report to the log 00298 pLog->ReportError(m_sClassName, 00299 rMethod, 00300 sNewMessage); 00301 } 00302 ERROR_UNKNOWN("ReportError") 00303 }
Definition at line 218 of file ErrorHandler.cpp. 00220 { 00221 if (!GetLog()) 00222 return; 00223 00224 try 00225 { 00226 CErrorLog* pLog; 00227 pLog=GetLog(); 00228 00229 //Report to the log 00230 pLog->ReportError(m_sClassName, 00231 rMethod, 00232 rMessage); 00233 } 00234 ERROR_UNKNOWN("ReportError") 00235 }
Definition at line 311 of file ErrorHandler.cpp. 00312 { 00313 if (!GetLog()) 00314 return; 00315 00316 try 00317 { 00318 #ifdef WIN32 00319 //Get the last error 00320 DWORD dwLastError; 00321 dwLastError=GetLastError(); 00322 00323 //Report the error 00324 GetLog()->ReportError(m_sClassName, 00325 rMethod, 00326 ErrorCodeToString(dwLastError)); 00327 00328 #else 00329 GetLog()->ReportCatchError(m_sClassName, 00330 rMethod, 00331 "Unknown error!"); 00332 #endif 00333 } 00334 ERROR_UNKNOWN("ReportError") 00335 }
Definition at line 237 of file ErrorHandler.cpp. 00239 { 00240 if (!GetLog()) 00241 return; 00242 00243 try 00244 { 00245 //Get the last error 00246 DWORD dwLastError; 00247 dwLastError=GetLastError(); 00248 00249 //Format the message 00250 std::string sMessage; 00251 sMessage=rMessage; 00252 sMessage+=", with error code: "; 00253 00254 //Convert the error code 00255 char aTmp[11]; 00256 itoa(dwLastError,aTmp,10); 00257 00258 //Add it again 00259 sMessage+=aTmp; 00260 sMessage+=" "; 00261 sMessage+=ErrorCodeToString(dwLastError); 00262 00263 //Get the log 00264 CErrorLog* pLog; 00265 pLog=GetLog(); 00266 00267 //Report to the log 00268 pLog->ReportError(m_sClassName, 00269 rMethod, 00270 sMessage); 00271 } 00272 ERROR_UNKNOWN("ReportErrorOS") 00273 }
Definition at line 489 of file ErrorHandler.cpp. 00493 { 00494 if (!m_pLog) 00495 return; 00496 00497 try 00498 { 00499 //Convert the number 00500 char aTmp[11]; 00501 ltoa(dwAdditionalData,aTmp,10); 00502 00503 //Create the new message 00504 std::string sNewMessage(rMessage); 00505 sNewMessage+="Additional data: "; 00506 sNewMessage+=aTmp; 00507 00508 //Report to the log 00509 m_pLog->ReportError(rClass, 00510 rMethod, 00511 sNewMessage); 00512 } 00513 ERROR_UNKNOWN("ReportStaticError") 00514 }
Definition at line 472 of file ErrorHandler.cpp. 00475 { 00476 if (!m_pLog) 00477 return; 00478 00479 try 00480 { 00481 //Report to the log 00482 m_pLog->ReportError(rClass, 00483 rMethod, 00484 rMessage); 00485 } 00486 ERROR_UNKNOWN("ReportStaticError") 00487 }
Definition at line 446 of file ErrorHandler.cpp. 00448 { 00449 if (!m_pLog) 00450 return; 00451 00452 try 00453 { 00454 #ifdef WIN32 00455 //Get the last error 00456 DWORD dwLastError; 00457 dwLastError=GetLastError(); 00458 00459 //Report the error 00460 m_pLog->ReportError(rClass, 00461 rMethod, 00462 ErrorCodeToString(dwLastError)); 00463 #else 00464 m_pLog->ReportError(rClass, 00465 rMethod, 00466 "Unknown error!"); 00467 #endif 00468 } 00469 ERROR_UNKNOWN("ReportStaticError") 00470 }
Definition at line 355 of file ErrorHandler.cpp. 00359 { 00360 if (!GetLog()) 00361 return; 00362 00363 try 00364 { 00365 //Convert the number 00366 char aTmp[11]; 00367 ltoa(dwAdditionalData,aTmp,10); 00368 00369 //Create the new message 00370 std::string sNewMessage(rMessage); 00371 sNewMessage+="Additional data: "; 00372 sNewMessage+=aTmp; 00373 00374 //Delegate the call 00375 GetLog()->WriteMessage(m_sClassName, 00376 rMethod, 00377 sNewMessage, 00378 aPriority); 00379 } 00380 ERROR_UNKNOWN("WriteMessage") 00381 }
Definition at line 337 of file ErrorHandler.cpp. 00340 { 00341 if (!GetLog()) 00342 return; 00343 00344 try 00345 { 00346 //Delegate the call 00347 GetLog()->WriteMessage(m_sClassName, 00348 rMethod, 00349 rMessage, 00350 aPriority); 00351 } 00352 ERROR_UNKNOWN("WriteMessage") 00353 }
Definition at line 403 of file ErrorHandler.cpp. 00408 { 00409 if (!m_pLog) 00410 return; 00411 00412 try 00413 { 00414 //Convert the number 00415 char aTmp[11]; 00416 ltoa(dwAdditionalData,aTmp,10); 00417 00418 //Create the new message 00419 std::string sNewMessage(rMessage); 00420 sNewMessage+="Additional data: "; 00421 sNewMessage+=aTmp; 00422 00423 //Delegate the call 00424 m_pLog->WriteMessage(rClass, 00425 rMethod, 00426 sNewMessage, 00427 aPriority); 00428 } 00429 ERROR_UNKNOWN("WriteStaticMessage") 00430 }
Definition at line 383 of file ErrorHandler.cpp. 00388 { 00389 if (!m_pLog) 00390 return; 00391 00392 try 00393 { 00394 //Delegate the call 00395 m_pLog->WriteMessage(rClass, 00396 rMethod, 00397 rMessage, 00398 aPriority); 00399 } 00400 ERROR_UNKNOWN("WriteStaticMessage") 00401 }
The documentation for this class was generated from the following files: |