VOID DNSUpdateFreeRequest( PDNS_UPDATE_REQUEST pDNSRequest ) { if (pDNSRequest->ppZoneRRSet) { DNSFreeZoneRecordList( pDNSRequest->ppZoneRRSet, pDNSRequest->wZones); } if (pDNSRequest->ppPRRRSet) { DNSFreeRecordList( pDNSRequest->ppPRRRSet, pDNSRequest->wPRs); } if (pDNSRequest->ppUpdateRRSet) { DNSFreeRecordList( pDNSRequest->ppUpdateRRSet, pDNSRequest->wUpdates); } if (pDNSRequest->ppAdditionalRRSet) { DNSFreeRecordList( pDNSRequest->ppAdditionalRRSet, pDNSRequest->wAdditionals); } DNSFreeMemory(pDNSRequest); }
VOID DNSStdFreeResponse( PDNS_RESPONSE pDNSResponse ) { if (pDNSResponse->ppQuestionRRSet) { DNSFreeQuestionRecordList( pDNSResponse->ppQuestionRRSet, pDNSResponse->wQuestions); } if (pDNSResponse->ppAnswerRRSet) { DNSFreeRecordList( pDNSResponse->ppAnswerRRSet, pDNSResponse->wAnswers); } if (pDNSResponse->ppAuthorityRRSet) { DNSFreeRecordList( pDNSResponse->ppAuthorityRRSet, pDNSResponse->wAuthoritys); } if (pDNSResponse->ppAdditionalRRSet) { DNSFreeRecordList( pDNSResponse->ppAdditionalRRSet, pDNSResponse->wAdditionals); } if (pDNSResponse->pDNSOutBuffer) { DNSFreeMemory(pDNSResponse->pDNSOutBuffer); } DNSFreeMemory(pDNSResponse); }
VOID DNSUpdateFreeResponse( PDNS_UPDATE_RESPONSE pDNSResponse ) { if (pDNSResponse->ppZoneRRSet) { DNSFreeZoneRecordList( pDNSResponse->ppZoneRRSet, pDNSResponse->wZones); } if (pDNSResponse->ppPRRRSet) { DNSFreeRecordList( pDNSResponse->ppPRRRSet, pDNSResponse->wPRs); } if (pDNSResponse->ppUpdateRRSet) { DNSFreeRecordList( pDNSResponse->ppUpdateRRSet, pDNSResponse->wUpdates); } if (pDNSResponse->ppAdditionalRRSet) { DNSFreeRecordList( pDNSResponse->ppAdditionalRRSet, pDNSResponse->wAdditionals); } if (pDNSResponse->pDNSOutBuffer) { DNSFreeMemory(pDNSResponse->pDNSOutBuffer); } DNSFreeMemory(pDNSResponse); }
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; }
static DWORD DNSStdUnmarshallAdditionalSection( HANDLE hReceiveBuffer, WORD wAdditionals, PDNS_RR_RECORD ** pppDNSAdditionalsRRRecords ) { DWORD dwError = 0; DWORD i = 0; PDNS_RR_RECORD pDNSRRRecord = NULL; PDNS_RR_RECORD * ppDNSAdditionalRRRecords = NULL; PBYTE pRData = NULL; DNS_RR_HEADER RRHeader = {0}; PDNS_RR_HEADER pRRHeader = &RRHeader; dwError = DNSAllocateMemory( wAdditionals * sizeof(PDNS_RR_RECORD), (PVOID *)&ppDNSAdditionalRRRecords); BAIL_ON_LWDNS_ERROR(dwError); for (i = 0; i < wAdditionals; i++) { DWORD dwRead = 0; memset(pRRHeader, 0, sizeof(DNS_RR_HEADER)); dwError = DNSUnmarshallRRHeader( hReceiveBuffer, pRRHeader); BAIL_ON_LWDNS_ERROR(dwError); dwError = DNSUnmarshallRData( hReceiveBuffer, pRRHeader->wRDataSize, &pRData, &dwRead); BAIL_ON_LWDNS_ERROR(dwError); dwError = DNSAllocateMemory( sizeof(DNS_RR_RECORD), (PVOID *)&pDNSRRRecord); BAIL_ON_LWDNS_ERROR(dwError); memcpy(&pDNSRRRecord->RRHeader, pRRHeader, sizeof(DNS_RR_HEADER)); pRRHeader->pDomainName = NULL; pDNSRRRecord->pRData = pRData; pRData = NULL; *(ppDNSAdditionalRRRecords + i) = pDNSRRRecord; pDNSRRRecord = NULL; } *pppDNSAdditionalsRRRecords = ppDNSAdditionalRRRecords; cleanup: return dwError; error: if (pRData) { DNSFreeMemory(pRData); } if (pDNSRRRecord) { DNSFreeRecord(pDNSRRRecord); } if (pRRHeader && pRRHeader->pDomainName) { DNSFreeDomainName(pRRHeader->pDomainName); } if (ppDNSAdditionalRRRecords) { DNSFreeRecordList( ppDNSAdditionalRRRecords, wAdditionals); } *pppDNSAdditionalsRRRecords = NULL; goto cleanup; }
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; }