KomodiaDNS::CDNSAnswers Class Reference#include <DNSAnswers.h>
Inheritance diagram for KomodiaDNS::CDNSAnswers:
![]()
Collaboration diagram for KomodiaDNS::CDNSAnswers:
![]()
Detailed DescriptionDefinition at line 112 of file DNSAnswers.h. Member Typedef Documentation
Definition at line 119 of file DNSAnswers.h.
Definition at line 116 of file DNSAnswers.h.
Member Enumeration Documentation
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 DNSAnswers.cpp. 00057 : CErrorHandler(), 00058 m_pDNSQuery(NULL) 00059 { 00060 try 00061 { 00062 //Set our name 00063 SetName(CDNSAnswers_Class); 00064 } 00065 ERROR_HANDLER("CDNSAnswers") 00066 }
Definition at line 68 of file DNSAnswers.cpp. 00068 : CErrorHandler(), 00069 m_pDNSQuery(NULL), 00070 m_aAnswers(rAnswers.m_aAnswers) 00071 { 00072 try 00073 { 00074 //Set our name 00075 SetName(CDNSAnswers_Class); 00076 00077 //Do we have a query? 00078 if (rAnswers.m_pDNSQuery) 00079 //Copy it 00080 m_pDNSQuery=new CDNSQuery(*rAnswers.m_pDNSQuery); 00081 } 00082 ERROR_HANDLER("CDNSAnswers") 00083 }
Definition at line 85 of file DNSAnswers.cpp. 00086 { 00087 try 00088 { 00089 //Delete the query 00090 delete m_pDNSQuery; 00091 } 00092 ERROR_HANDLER("~CDNSAnswers") 00093 }
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 246 of file DNSAnswers.cpp. 00247 { 00248 try 00249 { 00250 if (!m_aDNSHeader.usARCount || 00251 !m_aDNSHeader.usANCount) 00252 { 00253 //Report it 00254 ReportError("GetAddress","No answers!"); 00255 00256 //Exit 00257 return 0; 00258 } 00259 00260 //Get to the actual answer 00261 unsigned short usPrior; 00262 usPrior=m_aDNSHeader.usANCount+ 00263 m_aDNSHeader.usNSCount; 00264 00265 for (unsigned short usCounter=usIndex; 00266 usCounter<m_aDNSHeader.usARCount-usIndex; 00267 ++usCounter) 00268 if (m_aAnswers[usPrior+usCounter].GetResourceType()==CDNSQuery::A) 00269 { 00270 //Get the data 00271 std::string sData; 00272 sData=m_aAnswers[usPrior+usCounter].GetData(); 00273 00274 //Convert it to long 00275 return atol(sData.c_str()); 00276 } 00277 00278 //Nothing 00279 return 0; 00280 } 00281 ERROR_HANDLER_RETURN("GetAddress",0) 00282 }
Definition at line 294 of file DNSAnswers.cpp. 00295 { 00296 try 00297 { 00298 //Do we have an answer ? 00299 if (!m_aDNSHeader.usANCount || 00300 m_aAnswers.empty()) 00301 return 0; 00302 00303 //Get the answer 00304 const CDNSAnswer& rAnswer=m_aAnswers[0]; 00305 00306 //Check what type is it ? 00307 if (rAnswer.GetResourceType()==CDNSQuery::A) 00308 { 00309 //Get the data 00310 std::string sData; 00311 sData=rAnswer.GetData(); 00312 00313 //Convert it to long 00314 return atol(sData.c_str()); 00315 } 00316 else if (rAnswer.GetResourceType()==CDNSQuery::MX && 00317 m_aDNSHeader.usARCount) 00318 { 00319 //Look for the additional resources 00320 int iPos; 00321 iPos=m_aDNSHeader.usANCount+ 00322 m_aDNSHeader.usNSCount; 00323 00324 //Our data 00325 std::string sData; 00326 sData=rAnswer.GetData(); 00327 00328 //Loop them 00329 for (int iCount=0; 00330 iCount<m_aDNSHeader.usARCount; 00331 iCount++) 00332 { 00333 //Get the answer 00334 const CDNSAnswer& rARAnswer=m_aAnswers[iCount+iPos]; 00335 00336 //Is it an A record? 00337 if (rARAnswer.GetResourceType()==CDNSQuery::A && 00338 rARAnswer.GetName()==sData) 00339 //This is us 00340 return atol(rARAnswer.GetData().c_str()); 00341 } 00342 00343 //Not found 00344 return 0; 00345 } 00346 else 00347 return 0; 00348 } 00349 ERROR_HANDLER_RETURN("GetAIPAnswer",0) 00350 }
Definition at line 352 of file DNSAnswers.cpp. 00353 { 00354 //Empty vector 00355 static IPAnswersVector aEmptyVector; 00356 00357 try 00358 { 00359 //Our vector 00360 IPAnswersVector aVector; 00361 00362 //Do we have an answer ? 00363 if (!m_aDNSHeader.usANCount || 00364 m_aAnswers.empty()) 00365 return aVector; 00366 00367 //Iterate the answers 00368 for (int iCount=0; 00369 iCount<m_aDNSHeader.usANCount; 00370 ++iCount) 00371 { 00372 //Get the answer 00373 const CDNSAnswer& rAnswer=m_aAnswers[iCount]; 00374 00375 //Check what type is it ? 00376 if (rAnswer.GetResourceType()==CDNSQuery::A) 00377 { 00378 //Get the data 00379 std::string sData; 00380 sData=rAnswer.GetData(); 00381 00382 //Convert it to long 00383 aVector.push_back(atol(sData.c_str())); 00384 } 00385 else if (rAnswer.GetResourceType()==CDNSQuery::MX && 00386 m_aDNSHeader.usARCount) 00387 { 00388 //Look for the additional resources 00389 int iPos; 00390 iPos=m_aDNSHeader.usANCount+ 00391 m_aDNSHeader.usNSCount; 00392 00393 //Our data 00394 std::string sData; 00395 sData=rAnswer.GetData(); 00396 00397 //Loop them 00398 for (int iCount=0; 00399 iCount<m_aDNSHeader.usARCount; 00400 iCount++) 00401 { 00402 //Get the answer 00403 const CDNSAnswer& rARAnswer=m_aAnswers[iCount+iPos]; 00404 00405 //Is it an A record? (may have more then one A record per type) 00406 if (rARAnswer.GetResourceType()==CDNSQuery::A && 00407 rARAnswer.GetName()==sData) 00408 //This is us 00409 aVector.push_back(atol(rARAnswer.GetData().c_str())); 00410 } 00411 } 00412 } 00413 00414 //Done 00415 return aVector; 00416 } 00417 ERROR_HANDLER_RETURN("GetAIPAnswers",aEmptyVector) 00418 }
Definition at line 420 of file DNSAnswers.cpp. 00421 { 00422 try 00423 { 00424 //Do we have an answer ? 00425 if (!m_aDNSHeader.usANCount || 00426 m_aAnswers.empty()) 00427 return ""; 00428 00429 //Get the answer 00430 const CDNSAnswer& rAnswer=m_aAnswers[0]; 00431 00432 //Check what type is it ? 00433 if (rAnswer.GetResourceType()==CDNSQuery::PTR || 00434 rAnswer.GetResourceType()==CDNSQuery::MX) 00435 { 00436 //Get the data 00437 std::string sData; 00438 sData=rAnswer.GetData(); 00439 00440 //Convert it to long 00441 return sData; 00442 } 00443 else if (rAnswer.GetResourceType()==CDNSQuery::A) 00444 { 00445 //Get the data 00446 std::string sData; 00447 sData=rAnswer.GetData(); 00448 00449 //Convert to DWORD 00450 DWORD dwIP; 00451 dwIP=atof(sData.c_str()); 00452 00453 //Convert to string 00454 return CSpoofBase::LongToStdString(dwIP); 00455 } 00456 else 00457 return ""; 00458 } 00459 ERROR_HANDLER_RETURN("GetAnswer","") 00460 }
Definition at line 523 of file DNSAnswers.cpp. 00526 { 00527 try 00528 { 00529 //Line terminator 00530 //End of line 00531 char aEndOfLine[3]; 00532 00533 //Which is it 00534 if (bWindowsLines) 00535 { 00536 aEndOfLine[0]=13; 00537 aEndOfLine[1]=10; 00538 aEndOfLine[2]=0; 00539 } 00540 else 00541 { 00542 aEndOfLine[0]='\n'; 00543 aEndOfLine[1]=0; 00544 } 00545 00546 //Our string 00547 std::string sAnswer; 00548 00549 //Iterate answers 00550 for (int iCount=0; 00551 iCount<m_aAnswers.size(); 00552 iCount++) 00553 { 00554 //What are we 00555 if (iCount<m_aDNSHeader.usANCount && 00556 !iCount) 00557 { 00558 //Answer 00559 sAnswer+="Non-authoritative answer:"; 00560 sAnswer+=aEndOfLine; 00561 } 00562 else if ((iCount<m_aDNSHeader.usANCount+ 00563 m_aDNSHeader.usNSCount) && 00564 iCount==m_aDNSHeader.usANCount) 00565 { 00566 //Authority servers 00567 sAnswer+=aEndOfLine; 00568 sAnswer+="Authoritive servers:"; 00569 sAnswer+=aEndOfLine; 00570 } 00571 else if (iCount==m_aDNSHeader.usANCount+ 00572 m_aDNSHeader.usNSCount) 00573 { 00574 //Additional records 00575 sAnswer+=aEndOfLine; 00576 sAnswer+="Additional records:"; 00577 sAnswer+=aEndOfLine; 00578 } 00579 00580 //Add the answer 00581 sAnswer+=m_aAnswers[iCount].GetAnswerParsed(bWindowsLines, 00582 bBrief); 00583 sAnswer+=aEndOfLine; 00584 } 00585 00586 //Do we need another line? 00587 if (bExtraLine) 00588 sAnswer+=aEndOfLine; 00589 00590 //Done 00591 return sAnswer; 00592 } 00593 ERROR_HANDLER_RETURN("GetAnswerParsed","") 00594 }
Definition at line 462 of file DNSAnswers.cpp. 00463 { 00464 //Empty vector 00465 static StringAnswersVector aEmptyVector; 00466 00467 try 00468 { 00469 //Our vector 00470 StringAnswersVector aVector; 00471 00472 //Do we have an answer ? 00473 if (!m_aDNSHeader.usANCount || 00474 m_aAnswers.empty()) 00475 return aEmptyVector; 00476 00477 //Iterate the answers 00478 for (int iCount=0; 00479 iCount<m_aDNSHeader.usANCount; 00480 ++iCount) 00481 { 00482 //Get the answer 00483 const CDNSAnswer& rAnswer=m_aAnswers[iCount]; 00484 00485 //Check what type is it ? 00486 if (rAnswer.GetResourceType()==CDNSQuery::PTR || 00487 rAnswer.GetResourceType()==CDNSQuery::MX) 00488 { 00489 //Get the data 00490 std::string sData; 00491 sData=rAnswer.GetData(); 00492 00493 //Add it 00494 aVector.push_back(sData); 00495 } 00496 else if (rAnswer.GetResourceType()==CDNSQuery::A) 00497 { 00498 //Get the data 00499 std::string sData; 00500 sData=rAnswer.GetData(); 00501 00502 //Convert to DWORD 00503 DWORD dwIP; 00504 dwIP=atof(sData.c_str()); 00505 00506 //Convert to string 00507 //Add it 00508 aVector.push_back(CSpoofBase::LongToStdString(dwIP)); 00509 } 00510 } 00511 00512 //Done 00513 return aVector; 00514 } 00515 ERROR_HANDLER_RETURN("GetAnswers",aEmptyVector) 00516 }
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 284 of file DNSAnswers.cpp. 00285 { 00286 return !(m_aDNSHeader.usOptions & DNS_SERVER_FAILURE); 00287 }
Definition at line 596 of file DNSAnswers.cpp. 00597 { 00598 return IsResolved() && 00599 m_pDNSQuery->GetFirstQueryType()==CDNSQuery::PTR; 00600 }
Definition at line 100 of file DNSAnswers.cpp. 00102 { 00103 try 00104 { 00105 //Delete previous data 00106 UnInitialize(); 00107 00108 if (iLength<=DnsHeaderHeaderLength) 00109 { 00110 //Report it 00111 ReportError("Parse","Buffer size too small!"); 00112 00113 //Exit 00114 return 0; 00115 } 00116 00117 //Start parsing the dude 00118 const char* pBackupBuffer=pBuffer; 00119 00120 //Let's start with the answer 00121 memcpy(&m_aDNSHeader, 00122 pBackupBuffer, 00123 DnsHeaderHeaderLength); 00124 00125 //Reverse the header 00126 ReverseHeader(); 00127 00128 //Increase the buffer 00129 pBackupBuffer+=DnsHeaderHeaderLength; 00130 00131 //OK now we can continue 00132 m_pDNSQuery=new CDNSQuery; 00133 00134 //Get the number of data the query parsed ! 00135 unsigned short usParseLength; 00136 00137 //Parse it 00138 usParseLength=m_pDNSQuery->Parse(pBackupBuffer, 00139 m_aDNSHeader.usQDCount); 00140 00141 //Check for errors 00142 if (!usParseLength) 00143 { 00144 //Report it 00145 ReportError("Parse","Received zero length!"); 00146 00147 //Exit 00148 return 0; 00149 } 00150 00151 //Increase the buffer 00152 pBackupBuffer+=usParseLength; 00153 00154 //Parse the rest of the headers 00155 return ParseAnswers(pBackupBuffer, 00156 pBuffer); 00157 } 00158 ERROR_HANDLER_RETURN("Parse",0) 00159 }
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: |