Class KomodiaDNS::CDNSManager::
QueryDNS()
Base ClassesData ItemsConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: ParseMultithreadedNext page: Receive    Show member index
Public Function Declared in:
DNSManager.h

'Declaration' icon -- Shortcut to top of page. Declaration

unsigned short QueryDNS(
    const CDNSQuery& rQuery,
    unsigned short usID=0,
    LPVOID lpLocalIDData=NULL);

'Description' icon -- Shortcut to top of page. Description

Send a query (Returns the Query ID)

'Function Body' icon -- Shortcut to top of page. Function Body

try
{
    //Are we initialized
    if (!m_bInitialized)
    {
        //Report it
        ReportError("QueryDNS","Not initialized!");

        //Exit
        return 0;
    }

    //Get the query size
    unsigned short usTotalSize;
    usTotalSize=rQuery.GetSerializationSize();

    //Is it bad?
    if (!usTotalSize)
    {
        //Report it
        ReportError("QueryDNS","Bad query size!");

        //Exit
        return 0;
    }

    //Add the dns header
    usTotalSize+=DnsHeaderHeaderLength;

    //Is it TCP
    if (m_bTCP)
        usTotalSize+=2;

    //Allocate the buffer
    char* pBuffer;
    pBuffer=new char[usTotalSize];

    //Protect it
    CArray_ptr<char> pProtection(pBuffer);

    //Keep track of position
    char* pBackupBuffer=pBuffer;

    if (m_bTCP)
        //Advance pointer
        pBuffer+=2;

    //Get the ID
    if (!usID)
    {
        //Get a running static ID
        static long lID=0;
        InterlockedIncrement(&lID);
        usID=lID;
    }

    //Get the DNS header
    LPDnsHeaderHeader lpHead;
    lpHead=GetDNSHeaderHeader(usID,
                              DNS_RECURSION,
                              rQuery.GetQuestionCount());

    //Copy it
    memcpy(pBuffer,
           lpHead,
           DnsHeaderHeaderLength);
    pBuffer+=DnsHeaderHeaderLength;

    //Done with it
    delete lpHead;

    //Serialize the query
    if (!rQuery.SerializeQuery(pBuffer))
    {
        //Report it
        ReportError("QueryDNS","Failed to serialize query!");

        //Exit
        return 0;
    }

    //Fix the tcp header
    if (m_bTCP)
        *((unsigned short*)pBackupBuffer)=htons(usTotalSize-2);

    //Add the record
    AddRecord(usID,
              lpLocalIDData,
              m_dwTimeout,
              rQuery);

    //Send the data
    BOOL bResult;
    bResult=m_pSocket->Send(pBackupBuffer,
                            usTotalSize,
                            lpLocalIDData);

    //If error remove the data
    if (!bResult)
        RemoveRecord(usID);

    //Check if all is OK
    if (bResult)
        return usID;
    else
        return 0;
}
ERROR_HANDLER_RETURN("QueryDNS",0)

'See Also' icon -- Shortcut to top of page. See Also

Class Overview Class Overview  |  Public base class CErrorHandler  |  Hierarchy Chart Hierarchy Chart


Get Surveyor!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.