DWORD
DNSStdReceiveStdResponse(
    HANDLE         hDNSHandle,
    PDNS_RESPONSE* ppDNSResponse
    )
{
    PDNS_RESPONSE pDNSResponse = NULL;
    DWORD dwError = 0;
    WORD wnIdentification,wIdentification = 0;
    WORD wnParameter, wParameter = 0;
    WORD wnQuestions, wQuestions = 0;
    WORD wnAnswers, wAnswers = 0;
    WORD wnAdditionals, wAdditionals = 0;
    WORD wnAuthoritys, wAuthoritys = 0;
    DWORD dwRead = 0;
    PDNS_RR_RECORD * ppDNSAnswerRecords = NULL;
    PDNS_RR_RECORD *  ppDNSAdditionalRecords = NULL;
    PDNS_RR_RECORD *  ppDNSAuthorityRecords = NULL;
    PDNS_QUESTION_RECORD * ppDNSQuestionRecords = NULL;
    HANDLE hRecvBuffer = (HANDLE)NULL;

    dwError = DNSCreateReceiveBuffer(&hRecvBuffer);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    dwError = DNSReceiveBufferContext(
                hDNSHandle,
                hRecvBuffer,
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);

    dwError = DNSDumpRecvBufferContext(hRecvBuffer);
    BAIL_ON_LWDNS_ERROR(dwError);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnIdentification,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    wIdentification = ntohs(wnIdentification);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnParameter,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    wParameter = ntohs(wnParameter);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnQuestions,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    wQuestions = ntohs(wnQuestions);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnAnswers,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    wAnswers = ntohs(wnAnswers);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnAuthoritys,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    wAuthoritys = ntohs(wnAuthoritys);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnAdditionals,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    wAdditionals = ntohs(wnAdditionals);

    if (wQuestions)
    {
        dwError = DNSStdUnmarshallQuestionSection(
                    hRecvBuffer, 
                    wQuestions, 
                    &ppDNSQuestionRecords);
        BAIL_ON_LWDNS_ERROR(dwError);
    }

    if (wAnswers)
    {
        dwError = DNSStdUnmarshallAnswerSection(
                    hRecvBuffer, 
                    wAnswers, 
                    &ppDNSAnswerRecords);
        BAIL_ON_LWDNS_ERROR(dwError);
    }

    if (wAuthoritys)
    {
        dwError = DNSStdUnmarshallAuthoritySection(
                    hRecvBuffer, 
                    wAuthoritys, 
                    &ppDNSAuthorityRecords);
        BAIL_ON_LWDNS_ERROR(dwError);
    }

    if (wAdditionals)
    {
        dwError = DNSStdUnmarshallAdditionalSection(
                    hRecvBuffer, 
                    wAdditionals, 
                    &ppDNSAdditionalRecords);
        BAIL_ON_LWDNS_ERROR(dwError);
    }

    dwError = DNSStdAllocateResponse(&pDNSResponse);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    pDNSResponse->wIdentification = wIdentification;
    pDNSResponse->wParameter = wParameter;
    pDNSResponse->wQuestions = wQuestions;
    pDNSResponse->wAnswers = wAnswers;
    pDNSResponse->wAuthoritys = wAuthoritys;
    pDNSResponse->wAdditionals = wAdditionals;

    pDNSResponse->ppQuestionRRSet = ppDNSQuestionRecords;
    pDNSResponse->ppAnswerRRSet = ppDNSAnswerRecords;
    pDNSResponse->ppAuthorityRRSet = ppDNSAuthorityRecords;
    pDNSResponse->ppAdditionalRRSet = ppDNSAdditionalRecords;
    
    *ppDNSResponse = pDNSResponse;
    
cleanup:

    if (hRecvBuffer != (HANDLE)NULL)
    {
        DNSFreeReceiveBufferContext(hRecvBuffer);
    }

    return dwError;

error:

    if (ppDNSAnswerRecords)
    {
        DNSFreeRecordList(
                ppDNSAnswerRecords,
                wAnswers);
    }
    
    if (ppDNSAdditionalRecords)
    {
        DNSFreeRecordList(
                ppDNSAdditionalRecords,
                wAdditionals);
    }
    
    if (ppDNSAuthorityRecords)
    {
        DNSFreeRecordList(
                ppDNSAuthorityRecords,
                wAuthoritys);
    }
    
    if (ppDNSQuestionRecords)
    {
        DNSFreeQuestionRecordList(
                ppDNSQuestionRecords,
                wQuestions);
    }
    
    *ppDNSResponse = NULL;

    goto cleanup;
}
Exemple #2
0
DWORD
DNSUpdateReceiveUpdateResponse(
    HANDLE hDNSHandle,
    PDNS_UPDATE_RESPONSE * ppDNSResponse
    )
{
    PDNS_UPDATE_RESPONSE pDNSResponse = NULL;
    DWORD dwError = 0;
    WORD wnIdentification,wIdentification = 0;
    WORD wnParameter, wParameter = 0;
    WORD wnZones, wZones = 0;
    WORD wnPRs, wPRs = 0;
    WORD wnAdditionals, wAdditionals = 0;
    WORD wnUpdates, wUpdates = 0;
    DWORD dwRead = 0;
    PDNS_RR_RECORD * ppDNSPRRecords = NULL;
    PDNS_RR_RECORD *  ppDNSAdditionalRecords = NULL;
    PDNS_RR_RECORD *  ppDNSUpdateRecords = NULL;
    PDNS_ZONE_RECORD * ppDNSZoneRecords = NULL;
    HANDLE hRecvBuffer = (HANDLE)NULL;

    dwError = DNSCreateReceiveBuffer(&hRecvBuffer);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    dwError = DNSReceiveBufferContext(
                hDNSHandle, 
                hRecvBuffer,
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);

    dwError = DNSDumpRecvBufferContext(hRecvBuffer);
    BAIL_ON_LWDNS_ERROR(dwError);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnIdentification,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    wIdentification = ntohs(wnIdentification);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnParameter,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    wParameter = ntohs(wnParameter);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnZones,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    wZones = ntohs(wnZones);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnPRs,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    wPRs = ntohs(wnPRs);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnUpdates,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    wUpdates = ntohs(wnUpdates);

    dwError = DNSUnmarshallBuffer(
                hRecvBuffer,
                (PBYTE)&wnAdditionals,
                sizeof(WORD),
                &dwRead);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    wAdditionals = ntohs(wnAdditionals);

    if (wZones)
    {
        dwError = DNSUpdateUnmarshallZoneSection(
                    hRecvBuffer,
                    wZones,
                    &ppDNSZoneRecords);
        BAIL_ON_LWDNS_ERROR(dwError);
    }

    if (wPRs)
    {
        dwError = DNSUpdateUnmarshallPRSection(
                    hRecvBuffer,
                    wPRs,
                    &ppDNSPRRecords);
        BAIL_ON_LWDNS_ERROR(dwError);
    }

    if (wUpdates)
    {
        dwError = DNSUpdateUnmarshallUpdateSection(
                    hRecvBuffer,
                    wUpdates,
                    &ppDNSUpdateRecords);
        BAIL_ON_LWDNS_ERROR(dwError);
    }

    if (wAdditionals)
    {
        dwError = DNSUpdateUnmarshallAdditionalSection(
                    hRecvBuffer,
                    wAdditionals,
                    &ppDNSAdditionalRecords);
        BAIL_ON_LWDNS_ERROR(dwError);
    }

    dwError = DNSUpdateAllocateResponse(&pDNSResponse);
    BAIL_ON_LWDNS_ERROR(dwError);
    
    pDNSResponse->wIdentification = wIdentification;
    pDNSResponse->wParameter = wParameter;
    pDNSResponse->wZones = wZones;
    pDNSResponse->wPRs = wPRs;
    pDNSResponse->wUpdates = wUpdates;
    pDNSResponse->wAdditionals = wAdditionals;

    pDNSResponse->ppZoneRRSet = ppDNSZoneRecords;
    pDNSResponse->ppPRRRSet = ppDNSPRRecords;
    pDNSResponse->ppUpdateRRSet = ppDNSUpdateRecords;
    pDNSResponse->ppAdditionalRRSet = ppDNSAdditionalRecords;
    
    *ppDNSResponse = pDNSResponse;

cleanup:

    if (hRecvBuffer != (HANDLE)NULL)
    {
        DNSFreeReceiveBufferContext(hRecvBuffer);
    }

    return dwError;
    
error:

    if (pDNSResponse)
    {
        DNSUpdateFreeResponse(pDNSResponse);
    }
    
    if (ppDNSPRRecords)
    {
        DNSFreeRecordList(
                ppDNSPRRecords,
                wPRs);
    }
    
    if (ppDNSAdditionalRecords)
    {
        DNSFreeRecordList(
                ppDNSAdditionalRecords,
                wAdditionals);
    }
    
    if (ppDNSUpdateRecords)
    {
        DNSFreeRecordList(
                ppDNSUpdateRecords,
                wUpdates);
    }
    
    if (ppDNSZoneRecords)
    {
        DNSFreeZoneRecordList(
                ppDNSZoneRecords,
                wZones);
    }

    *ppDNSResponse = NULL;

    goto cleanup;
}