r17805: Sorry Jerry, I could not stand the warnings... :-)
[Samba.git] / source / libaddns / dnssock.c
blob88bd44e0e2b495d08487de7349b845c5a0d66609
1 /*
2 Linux DNS client library implementation
4 Copyright (C) 2006 Krishna Ganugapati <krishnag@centeris.com>
5 Copyright (C) 2006 Gerald Carter <jerry@samba.org>
7 ** NOTE! The following LGPL license applies to the libaddns
8 ** library. This does NOT imply that all of Samba is released
9 ** under the LGPL
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 02110-1301 USA
27 #include "dns.h"
29 /********************************************************************
30 ********************************************************************/
32 static DNS_ERROR DNSTCPOpen( char *nameserver, HANDLE * phDNSServer )
34 DNS_ERROR dwError = ERROR_DNS_INVALID_PARAMETER;
35 int sockServer;
36 unsigned long ulAddress;
37 struct hostent *pHost;
38 struct sockaddr_in s_in;
39 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
41 if ( (pDNSContext = TALLOC_P( NULL, DNS_CONNECTION_CONTEXT )) == NULL ) {
42 return ERROR_DNS_NO_MEMORY;
45 if ( (ulAddress = inet_addr( nameserver )) == INADDR_NONE ) {
46 if ( (pHost = gethostbyname( nameserver )) == NULL ) {
47 dwError = ERROR_DNS_INVALID_NAME_SERVER;
48 BAIL_ON_DNS_ERROR( dwError );
50 memcpy( &ulAddress, pHost->h_addr, pHost->h_length );
53 if ( (sockServer = socket( PF_INET, SOCK_STREAM, 0 )) == INVALID_SOCKET ) {
54 dwError = ERROR_DNS_NO_MEMORY;
55 BAIL_ON_DNS_ERROR( dwError );
58 s_in.sin_family = AF_INET;
59 s_in.sin_addr.s_addr = ulAddress;
60 s_in.sin_port = htons( DNS_TCP_PORT );
62 if ( (connect( sockServer, (struct sockaddr*)&s_in, sizeof( s_in ))) == SOCKET_ERROR ) {
63 dwError = ERROR_DNS_CONNECTION_FAILED;
64 BAIL_ON_DNS_ERROR( dwError );
67 pDNSContext->s = sockServer;
68 pDNSContext->hType = DNS_TCP;
70 *phDNSServer = ( HANDLE ) pDNSContext;
72 dwError = ERROR_DNS_SUCCESS;
74 return dwError;
76 error:
77 TALLOC_FREE( pDNSContext );
78 *phDNSServer = ( HANDLE ) NULL;
80 return dwError;
83 /********************************************************************
84 ********************************************************************/
86 static DNS_ERROR DNSUDPOpen( char *nameserver, HANDLE * phDNSServer )
88 DNS_ERROR dwError = ERROR_DNS_INVALID_PARAMETER;
89 int SendSocket;
90 unsigned long ulAddress;
91 struct hostent *pHost;
92 struct sockaddr_in RecvAddr;
93 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
95 if ( (pDNSContext = TALLOC_P( NULL, DNS_CONNECTION_CONTEXT )) == NULL ) {
96 return ERROR_DNS_NO_MEMORY;
99 if ( (ulAddress = inet_addr( nameserver )) == INADDR_NONE ) {
100 if ( (pHost = gethostbyname( nameserver )) == NULL ) {
101 dwError = ERROR_DNS_INVALID_NAME_SERVER;
102 BAIL_ON_DNS_ERROR( dwError );
104 memcpy( &ulAddress, pHost->h_addr, pHost->h_length );
107 /* Create a socket for sending data */
109 SendSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
111 /* Set up the RecvAddr structure with the IP address of
112 the receiver (in this example case "123.456.789.1")
113 and the specified port number. */
115 RecvAddr.sin_family = AF_INET;
116 RecvAddr.sin_port = htons( DNS_UDP_PORT );
117 RecvAddr.sin_addr.s_addr = ulAddress;
119 pDNSContext->s = SendSocket;
120 pDNSContext->hType = DNS_UDP;
121 memcpy( &pDNSContext->RecvAddr, &RecvAddr, sizeof( struct sockaddr_in ) );
123 *phDNSServer = ( HANDLE ) pDNSContext;
125 dwError = ERROR_DNS_SUCCESS;
127 return dwError;
129 error:
130 TALLOC_FREE( pDNSContext );
131 *phDNSServer = ( HANDLE ) NULL;
133 return dwError;
136 /********************************************************************
137 ********************************************************************/
139 DNS_ERROR DNSOpen( char *nameserver, int32 dwType, HANDLE * phDNSServer )
141 switch ( dwType ) {
142 case DNS_TCP:
143 return DNSTCPOpen( nameserver, phDNSServer );
144 case DNS_UDP:
145 return DNSUDPOpen( nameserver, phDNSServer );
148 return ERROR_DNS_INVALID_PARAMETER;
151 /********************************************************************
152 ********************************************************************/
154 static int32 DNSSendTCPRequest( HANDLE hDNSHandle,
155 uint8 * pDNSSendBuffer,
156 int32 dwBufferSize, int32 * pdwBytesSent )
158 int32 dwError = 0;
159 int32 dwBytesSent = 0;
160 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
163 pDNSContext = ( DNS_CONNECTION_CONTEXT * ) hDNSHandle;
165 dwBytesSent = send( pDNSContext->s, pDNSSendBuffer, dwBufferSize, 0 );
166 if ( dwBytesSent == SOCKET_ERROR ) {
167 dwError = WSAGetLastError( );
168 BAIL_ON_ERROR( dwError );
171 *pdwBytesSent = dwBytesSent;
173 return dwError;
175 error:
176 *pdwBytesSent = 0;
177 return dwError;
180 /********************************************************************
181 ********************************************************************/
183 static int32 DNSSendUDPRequest( HANDLE hDNSHandle,
184 uint8 * pDNSSendBuffer,
185 int32 dwBufferSize, int32 * pdwBytesSent )
187 int32 dwError = 0;
188 int32 dwBytesSent = 0;
189 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
191 pDNSContext = ( DNS_CONNECTION_CONTEXT * ) hDNSHandle;
193 dwBytesSent = sendto( pDNSContext->s,
194 pDNSSendBuffer,
195 dwBufferSize,
197 ( struct sockaddr * ) & pDNSContext->RecvAddr,
198 sizeof( pDNSContext->RecvAddr )
200 if ( dwBytesSent == SOCKET_ERROR ) {
201 dwError = WSAGetLastError( );
202 BAIL_ON_ERROR( dwError );
203 } else {
204 *pdwBytesSent = dwBytesSent;
207 return dwError;
209 error:
210 *pdwBytesSent = 0;
211 return dwError;
214 /********************************************************************
215 ********************************************************************/
217 static int32 DNSSelect( HANDLE hDNSHandle )
219 int32 dwError = 0;
220 fd_set rfds;
221 struct timeval tv;
222 int32 dwNumSockets = 0;
223 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
225 pDNSContext = ( DNS_CONNECTION_CONTEXT * ) hDNSHandle;
226 FD_ZERO( &rfds );
227 FD_SET( pDNSContext->s, &rfds );
229 tv.tv_sec = 10;
230 tv.tv_usec = 0;
231 dwNumSockets = select( pDNSContext->s + 1, &rfds, NULL, NULL, &tv );
232 if ( dwNumSockets == SOCKET_ERROR ) {
233 dwError = WSAGetLastError( );
234 BAIL_ON_ERROR( dwError );
237 if ( !dwNumSockets ) {
238 #ifndef WIN32
239 dwError = ETIMEDOUT;
240 #elif
241 dwError = WSAETIMEDOUT;
242 #endif
245 error:
247 return dwError;
250 /********************************************************************
251 ********************************************************************/
253 static int32 DNSTCPReceiveBufferContext( HANDLE hDNSHandle,
254 HANDLE hDNSRecvBuffer, int32 * pdwBytesRead )
256 int32 dwError = 0;
257 int32 dwRead = 0;
258 int16 wBytesToRead = 0;
259 int16 wnBytesToRead = 0;
260 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
261 DNS_RECEIVEBUFFER_CONTEXT *pDNSRecvContext = NULL;
263 pDNSContext = ( DNS_CONNECTION_CONTEXT * ) hDNSHandle;
264 pDNSRecvContext = ( DNS_RECEIVEBUFFER_CONTEXT * ) hDNSRecvBuffer;
266 dwError = DNSSelect( hDNSHandle );
267 BAIL_ON_ERROR( dwError );
269 dwRead = recv( pDNSContext->s, ( char * ) &wnBytesToRead,
270 sizeof( int16 ), 0 );
271 if ( dwRead == SOCKET_ERROR ) {
272 dwError = WSAGetLastError( );
273 BAIL_ON_ERROR( dwError );
276 wBytesToRead = ntohs( wnBytesToRead );
278 dwError = DNSSelect( hDNSHandle );
279 BAIL_ON_ERROR( dwError );
281 dwRead = recv( pDNSContext->s,
282 ( char * ) pDNSRecvContext->pRecvBuffer, wBytesToRead,
283 0 );
284 if ( dwRead == SOCKET_ERROR ) {
285 dwError = WSAGetLastError( );
286 BAIL_ON_ERROR( dwError );
289 pDNSRecvContext->dwBytesRecvd = dwRead;
291 *pdwBytesRead = ( int32 ) dwRead;
293 return dwError;
295 error:
297 return dwError;
300 /********************************************************************
301 ********************************************************************/
303 static int32 DNSUDPReceiveBufferContext( HANDLE hDNSHandle,
304 HANDLE hDNSRecvBuffer, int32 * pdwBytesRead )
306 int32 dwError = 0;
307 int32 dwRead = 0;
308 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
309 DNS_RECEIVEBUFFER_CONTEXT *pDNSRecvContext = NULL;
311 pDNSContext = ( DNS_CONNECTION_CONTEXT * ) hDNSHandle;
312 pDNSRecvContext = ( DNS_RECEIVEBUFFER_CONTEXT * ) hDNSRecvBuffer;
314 dwError = DNSSelect( hDNSHandle );
315 BAIL_ON_ERROR( dwError );
317 dwRead = recv( pDNSContext->s,
318 ( char * ) pDNSRecvContext->pRecvBuffer, 512, 0 );
319 if ( dwRead == SOCKET_ERROR ) {
320 dwError = WSAGetLastError( );
321 BAIL_ON_ERROR( dwError );
324 pDNSRecvContext->dwBytesRecvd = dwRead;
326 *pdwBytesRead = ( int32 ) dwRead;
328 error:
330 return dwError;
333 /********************************************************************
334 ********************************************************************/
336 int32 DNSReceiveBufferContext( HANDLE hDNSHandle,
337 HANDLE hDNSRecvBuffer, int32 * pdwBytesRead )
339 int32 dwError = 0;
340 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
342 pDNSContext = ( DNS_CONNECTION_CONTEXT * ) hDNSHandle;
344 switch ( pDNSContext->hType ) {
345 case DNS_TCP:
346 dwError =
347 DNSTCPReceiveBufferContext( hDNSHandle,
348 hDNSRecvBuffer,
349 pdwBytesRead );
350 break;
351 case DNS_UDP:
352 dwError =
353 DNSUDPReceiveBufferContext( hDNSHandle,
354 hDNSRecvBuffer,
355 pdwBytesRead );
356 break;
358 return dwError;
361 /********************************************************************
362 ********************************************************************/
364 int32 DNSCreateSendBuffer( HANDLE * phDNSSendBuffer )
366 int32 dwError = 0;
367 DNS_SENDBUFFER_CONTEXT *pDNSContext = NULL;
368 uint8 *pSendBuffer = NULL;
370 dwError = DNSAllocateMemory( sizeof( DNS_SENDBUFFER_CONTEXT ),
371 ( void * ) &pDNSContext );
372 BAIL_ON_ERROR( dwError );
374 dwError =
375 DNSAllocateMemory( SENDBUFFER_SIZE,
376 ( void * ) &pSendBuffer );
377 BAIL_ON_ERROR( dwError );
379 pDNSContext->pSendBuffer = pSendBuffer;
380 pDNSContext->dwBufferSize = SENDBUFFER_SIZE;
382 /* We will offset into the buffer by 2 bytes
383 If we are doing a TCP write; we will fill in these
384 two bytes and send + 2 bytes
385 If we are doing a UDP write; we will start our send
386 +2 bytes and only send dwWritten; */
388 pDNSContext->dwBufferOffset += 2;
390 *phDNSSendBuffer = ( HANDLE ) pDNSContext;
392 return dwError;
394 error:
396 if ( pSendBuffer ) {
397 DNSFreeMemory( pSendBuffer );
399 if ( pDNSContext ) {
400 DNSFreeMemory( pDNSContext );
402 *phDNSSendBuffer = ( HANDLE ) NULL;
404 return dwError;
408 /********************************************************************
409 ********************************************************************/
411 int32 DNSMarshallBuffer( HANDLE hDNSSendBuffer,
412 uint8 * pDNSSendBuffer,
413 int32 dwBufferSize, int32 * pdwBytesWritten )
415 int32 dwError = 0;
416 uint8 *pTemp = NULL;
417 DNS_SENDBUFFER_CONTEXT *pDNSContext = NULL;
419 /* BugBug - we need to check for amount of space remaining in the
420 SendBuffer Context - if its insufficent, we want to realloc the
421 Buffer and copy the context; Right now the assumption is we have a big
422 enough buffer */
424 pDNSContext = ( DNS_SENDBUFFER_CONTEXT * ) hDNSSendBuffer;
426 pTemp = pDNSContext->pSendBuffer + pDNSContext->dwBufferOffset;
428 memcpy( pTemp, pDNSSendBuffer, dwBufferSize );
430 pDNSContext->dwBytesWritten += dwBufferSize;
431 pDNSContext->dwBufferOffset += dwBufferSize;
433 *pdwBytesWritten = dwBufferSize;
435 return dwError;
438 /********************************************************************
439 ********************************************************************/
441 static int32 DNSTCPSendBufferContext( HANDLE hDNSServer,
442 HANDLE hSendBuffer, int32 * pdwBytesSent )
444 DNS_SENDBUFFER_CONTEXT *pSendBufferContext = NULL;
445 int32 dwError = 0;
446 int16 wBytesWritten = 0;
447 int16 wnBytesWritten = 0;
449 pSendBufferContext = ( DNS_SENDBUFFER_CONTEXT * ) hSendBuffer;
451 wBytesWritten = ( int16 ) pSendBufferContext->dwBytesWritten;
452 wnBytesWritten = htons( wBytesWritten );
454 memcpy( pSendBufferContext->pSendBuffer, &wnBytesWritten,
455 sizeof( int16 ) );
457 dwError = DNSSendTCPRequest( hDNSServer,
458 pSendBufferContext->pSendBuffer,
459 pSendBufferContext->dwBytesWritten + 2,
460 pdwBytesSent );
461 BAIL_ON_ERROR( dwError );
463 error:
465 return dwError;
468 /********************************************************************
469 ********************************************************************/
471 static int32 DNSUDPSendBufferContext( HANDLE hDNSServer,
472 HANDLE hSendBuffer, int32 * pdwBytesSent )
474 DNS_SENDBUFFER_CONTEXT *pSendBufferContext = NULL;
475 int32 dwError = 0;
477 pSendBufferContext = ( DNS_SENDBUFFER_CONTEXT * ) hSendBuffer;
479 /* Now remember to send 2 bytes ahead of pSendBuffer; because
480 we ignore the 2 bytes size field. */
482 dwError = DNSSendUDPRequest( hDNSServer,
483 pSendBufferContext->pSendBuffer + 2,
484 pSendBufferContext->dwBytesWritten,
485 pdwBytesSent );
486 BAIL_ON_ERROR( dwError );
488 error:
490 return dwError;
493 /********************************************************************
494 ********************************************************************/
496 int32 DNSSendBufferContext( HANDLE hDNSServer,
497 HANDLE hSendBuffer, int32 * pdwBytesSent )
499 DNS_CONNECTION_CONTEXT *pDNSContext = NULL;
500 int32 dwError = 0;
502 pDNSContext = ( DNS_CONNECTION_CONTEXT * ) hDNSServer;
504 switch ( pDNSContext->hType ) {
505 case DNS_TCP:
506 dwError = DNSTCPSendBufferContext( hDNSServer,
507 hSendBuffer,
508 pdwBytesSent );
509 BAIL_ON_ERROR( dwError );
510 break;
512 case DNS_UDP:
513 dwError = DNSUDPSendBufferContext( hDNSServer,
514 hSendBuffer,
515 pdwBytesSent );
516 BAIL_ON_ERROR( dwError );
517 break;
519 error:
521 return dwError;
524 /********************************************************************
525 ********************************************************************/
527 int32 DNSDumpSendBufferContext( HANDLE hSendBuffer )
529 DNS_SENDBUFFER_CONTEXT *pSendBufferContext = NULL;
530 int32 dwError = 0;
531 int32 dwCurLine = 0;
532 int32 i = 0;
534 pSendBufferContext = ( DNS_SENDBUFFER_CONTEXT * ) hSendBuffer;
535 printf( "\n" );
536 printf( "Buffer Size is: %d\n", pSendBufferContext->dwBytesWritten );
537 while ( i < pSendBufferContext->dwBytesWritten ) {
538 if ( ( i / 16 ) > dwCurLine ) {
539 printf( "\n" );
540 dwCurLine++;
542 if ( ( i % 8 ) == 0 ) {
543 printf( " " );
545 printf( "%.2x ", pSendBufferContext->pSendBuffer[i] );
546 i++;
548 return dwError;
551 /********************************************************************
552 ********************************************************************/
554 int32 DNSDumpRecvBufferContext( HANDLE hRecvBuffer )
556 DNS_RECEIVEBUFFER_CONTEXT *pRecvBufferContext = NULL;
557 int32 dwError = 0;
558 int32 dwCurLine = 0;
559 int32 i = 0;
561 pRecvBufferContext = ( DNS_RECEIVEBUFFER_CONTEXT * ) hRecvBuffer;
563 printf( "\n" );
564 printf( "Buffer Size is: %d\n", pRecvBufferContext->dwBytesRecvd );
566 while ( i < pRecvBufferContext->dwBytesRecvd ) {
567 if ( ( i / 16 ) > dwCurLine ) {
568 printf( "\n" );
569 dwCurLine++;
571 if ( ( i % 8 ) == 0 ) {
572 printf( " " );
574 printf( "%.2x ", pRecvBufferContext->pRecvBuffer[i] );
575 i++;
577 return dwError;
580 /********************************************************************
581 ********************************************************************/
583 int32 DNSCreateReceiveBuffer( HANDLE * phDNSRecvBuffer )
585 int32 dwError = 0;
586 DNS_RECEIVEBUFFER_CONTEXT *pDNSContext = NULL;
587 uint8 *pRecvBuffer = NULL;
589 dwError = DNSAllocateMemory( sizeof( DNS_RECEIVEBUFFER_CONTEXT ),
590 ( void * ) &pDNSContext );
591 BAIL_ON_ERROR( dwError );
593 dwError =
594 DNSAllocateMemory( RECVBUFFER_SIZE,
595 ( void * ) &pRecvBuffer );
596 BAIL_ON_ERROR( dwError );
598 pDNSContext->pRecvBuffer = pRecvBuffer;
599 pDNSContext->dwBufferSize = RECVBUFFER_SIZE;
601 *phDNSRecvBuffer = ( HANDLE ) pDNSContext;
603 return dwError;
605 error:
607 if ( pRecvBuffer ) {
608 DNSFreeMemory( pRecvBuffer );
610 if ( pDNSContext ) {
611 DNSFreeMemory( pDNSContext );
613 *phDNSRecvBuffer = ( HANDLE ) NULL;
615 return dwError;
618 /********************************************************************
619 ********************************************************************/
621 int32 DNSUnmarshallBuffer( HANDLE hDNSRecvBuffer,
622 uint8 * pDNSRecvBuffer,
623 int32 dwBufferSize, int32 * pdwBytesRead )
625 int32 dwError = 0;
626 uint8 *pTemp = NULL;
627 DNS_RECEIVEBUFFER_CONTEXT *pDNSContext = NULL;
629 /* BugBug - we need to check for amount of space remaining in the
630 SendBuffer Context - if its insufficent, we want to realloc the
631 Buffer and copy the context; Right now the assumption is we have a big
632 enough buffer */
634 pDNSContext = ( DNS_RECEIVEBUFFER_CONTEXT * ) hDNSRecvBuffer;
636 pTemp = pDNSContext->pRecvBuffer + pDNSContext->dwBytesRead;
638 memcpy( pDNSRecvBuffer, pTemp, dwBufferSize );
640 pDNSContext->dwBytesRead += dwBufferSize;
642 *pdwBytesRead = dwBufferSize;
644 return dwError;
647 /********************************************************************
648 ********************************************************************/
650 int32 DNSUnmarshallDomainNameAtOffset( HANDLE hRecvBuffer,
651 int16 wOffset,
652 DNS_DOMAIN_NAME ** ppDomainName )
654 int32 dwError = 0;
655 DNS_DOMAIN_LABEL *pLabel = NULL;
656 DNS_DOMAIN_LABEL *pLabelList = NULL;
657 DNS_DOMAIN_NAME *pDomainName = NULL;
658 char *pszLabel = NULL;
659 char szLabel[65];
660 uint8 uLen = 0;
661 int32 dwCurrent = 0;
662 DNS_RECEIVEBUFFER_CONTEXT *pRecvContext = NULL;
664 pRecvContext = ( DNS_RECEIVEBUFFER_CONTEXT * ) hRecvBuffer;
665 dwCurrent = wOffset;
667 while ( 1 ) {
669 memcpy( &uLen, pRecvContext->pRecvBuffer + dwCurrent,
670 sizeof( char ) );
671 dwCurrent++;
673 if ( uLen == 0 ) {
674 break;
677 memset( szLabel, 0, 65 );
678 memcpy( szLabel, pRecvContext->pRecvBuffer + dwCurrent,
679 uLen );
680 dwCurrent += uLen;
682 dwError = DNSAllocateString( szLabel, &pszLabel );
683 BAIL_ON_ERROR( dwError );
685 dwError =
686 DNSAllocateMemory( sizeof( DNS_DOMAIN_LABEL ),
687 ( void * ) &pLabel );
688 BAIL_ON_ERROR( dwError );
690 pLabel->pszLabel = pszLabel;
691 dwError = DNSAppendLabel( pLabelList, pLabel, &pLabelList );
692 BAIL_ON_ERROR( dwError );
695 dwError =
696 DNSAllocateMemory( sizeof( DNS_DOMAIN_NAME ),
697 ( void * ) &pDomainName );
698 BAIL_ON_ERROR( dwError );
699 pDomainName->pLabelList = pLabelList;
701 *ppDomainName = pDomainName;
703 return dwError;
705 error:
707 *ppDomainName = NULL;
708 return dwError;
711 /********************************************************************
712 ********************************************************************/
714 int32 DNSReceiveBufferMoveBackIndex( HANDLE hRecvBuffer, int16 wOffset )
716 int32 dwError = 0;
717 DNS_RECEIVEBUFFER_CONTEXT *pDNSContext = NULL;
719 pDNSContext = ( DNS_RECEIVEBUFFER_CONTEXT * ) hRecvBuffer;
720 pDNSContext->dwBytesRead -= wOffset;
722 return dwError;
725 /********************************************************************
726 ********************************************************************/
728 void DNSFreeSendBufferContext( HANDLE hSendBuffer )
730 DNS_SENDBUFFER_CONTEXT *pSendBufferContext = NULL;
732 pSendBufferContext = ( DNS_SENDBUFFER_CONTEXT * ) hSendBuffer;
734 if ( pSendBufferContext->pSendBuffer ) {
735 DNSFreeMemory( pSendBufferContext->pSendBuffer );
737 if ( pSendBufferContext ) {
738 DNSFreeMemory( pSendBufferContext );
742 /********************************************************************
743 ********************************************************************/
745 int32 DNSGetSendBufferContextSize( HANDLE hSendBuffer )
747 DNS_SENDBUFFER_CONTEXT *pSendBufferContext = NULL;
749 pSendBufferContext = ( DNS_SENDBUFFER_CONTEXT * ) hSendBuffer;
751 return ( pSendBufferContext->dwBytesWritten );
755 /********************************************************************
756 ********************************************************************/
758 uint8 *DNSGetSendBufferContextBuffer( HANDLE hSendBuffer )
760 DNS_SENDBUFFER_CONTEXT *pSendBufferContext = NULL;
762 pSendBufferContext = ( DNS_SENDBUFFER_CONTEXT * ) hSendBuffer;
764 return ( pSendBufferContext->pSendBuffer );