Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5421 lines
115 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. print.c
  5. Abstract:
  6. Domain Name System (DNS) Library
  7. Print routines.
  8. Author:
  9. Jim Gilroy (jamesg) February 8, 1997
  10. Revision History:
  11. --*/
  12. #include "local.h"
  13. #include "svcguid.h" // RnR guids
  14. #include "..\dnsapi\dnsapip.h" // Private query stuff
  15. #include "..\resolver\idl\resrpc.h" // Resolver interface structs
  16. //
  17. // Print globals
  18. //
  19. CRITICAL_SECTION DnsAtomicPrintCs;
  20. PCRITICAL_SECTION pDnsAtomicPrintCs = NULL;
  21. //
  22. // Empty string for simple switching of UTF-8/Unicode print
  23. // (macros in dnslib.h)
  24. //
  25. DWORD DnsEmptyString = 0;
  26. //
  27. // Indenting
  28. //
  29. // Serve up as many indenting tabs as indent level indicates
  30. //
  31. CHAR IndentString[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
  32. #define INDENT_STRING( level ) (IndentString + (sizeof(IndentString) - 1 - (level)))
  33. //
  34. // Print Locking
  35. //
  36. // Unless caller initilizes print locking by supplying lock,
  37. // print locking is disabled.
  38. //
  39. VOID
  40. DnsPrint_InitLocking(
  41. IN PCRITICAL_SECTION pLock
  42. )
  43. /*++
  44. Routine Description:
  45. Setup DNS printing to use a lock.
  46. Can use already initialized lock from caller, or will
  47. create default lock.
  48. Arguments:
  49. pLock - ptr to CS to use as lock; if NULL, create one
  50. Return Value:
  51. None
  52. --*/
  53. {
  54. if ( pLock )
  55. {
  56. pDnsAtomicPrintCs = pLock;
  57. }
  58. else if ( !pDnsAtomicPrintCs )
  59. {
  60. InitializeCriticalSection( &DnsAtomicPrintCs );
  61. pDnsAtomicPrintCs = &DnsAtomicPrintCs;
  62. }
  63. }
  64. VOID
  65. DnsPrint_Lock(
  66. VOID
  67. )
  68. /*++
  69. Routine Description:
  70. Lock to get atomic DNS print.
  71. --*/
  72. {
  73. if ( pDnsAtomicPrintCs )
  74. {
  75. EnterCriticalSection( pDnsAtomicPrintCs );
  76. }
  77. }
  78. VOID
  79. DnsPrint_Unlock(
  80. VOID
  81. )
  82. /*++
  83. Routine Description:
  84. Unlock to debug print.
  85. --*/
  86. {
  87. if ( pDnsAtomicPrintCs )
  88. {
  89. LeaveCriticalSection( pDnsAtomicPrintCs );
  90. }
  91. }
  92. //
  93. // Print routines for general types and structures
  94. //
  95. VOID
  96. DnsPrint_String(
  97. IN PRINT_ROUTINE PrintRoutine,
  98. IN OUT PPRINT_CONTEXT pContext,
  99. IN PSTR pszHeader OPTIONAL,
  100. IN PSTR pszString,
  101. IN BOOL fUnicode,
  102. IN PSTR pszTrailer OPTIONAL
  103. )
  104. /*++
  105. Routine Description:
  106. Print DNS string given in either Unicode or UTF-8 format.
  107. --*/
  108. {
  109. if ( !pszHeader )
  110. {
  111. pszHeader = "";
  112. }
  113. if ( !pszTrailer )
  114. {
  115. pszTrailer = "";
  116. }
  117. if ( ! pszString )
  118. {
  119. PrintRoutine(
  120. pContext,
  121. "%s(NULL DNS string ptr)%s",
  122. pszHeader,
  123. pszTrailer );
  124. }
  125. else if (fUnicode)
  126. {
  127. PrintRoutine(
  128. pContext,
  129. "%s%S%s",
  130. pszHeader,
  131. (PWSTR ) pszString,
  132. pszTrailer );
  133. }
  134. else
  135. {
  136. PrintRoutine(
  137. pContext,
  138. "%s%s%s",
  139. pszHeader,
  140. (PSTR ) pszString,
  141. pszTrailer );
  142. }
  143. }
  144. VOID
  145. DnsPrint_StringCharSet(
  146. IN PRINT_ROUTINE PrintRoutine,
  147. IN OUT PPRINT_CONTEXT pContext,
  148. IN PSTR pszHeader OPTIONAL,
  149. IN PSTR pszString,
  150. IN DNS_CHARSET CharSet,
  151. IN PSTR pszTrailer OPTIONAL
  152. )
  153. /*++
  154. Routine Description:
  155. Print string of given CHARSET.
  156. --*/
  157. {
  158. DnsPrint_String(
  159. PrintRoutine,
  160. pContext,
  161. pszHeader,
  162. pszString,
  163. (CharSet == DnsCharSetUnicode),
  164. pszTrailer );
  165. }
  166. VOID
  167. DnsPrint_UnicodeStringBytes(
  168. IN PRINT_ROUTINE PrintRoutine,
  169. IN OUT PPRINT_CONTEXT pContext,
  170. IN PSTR pszHeader,
  171. IN PWCHAR pUnicode,
  172. IN DWORD Length
  173. )
  174. /*++
  175. Routine Description:
  176. Print chars (WORDs) of unicode string.
  177. --*/
  178. {
  179. DWORD i;
  180. PrintRoutine(
  181. pContext,
  182. "%s\r\n"
  183. "\twide string %S\r\n"
  184. "\tlength %d\r\n"
  185. "\tbytes ",
  186. pszHeader,
  187. pUnicode,
  188. Length );
  189. for ( i=0; i<Length; i++ )
  190. {
  191. PrintRoutine(
  192. pContext,
  193. "%04hx ",
  194. pUnicode[i] );
  195. }
  196. printf( "\r\n" );
  197. }
  198. VOID
  199. DnsPrint_Utf8StringBytes(
  200. IN PRINT_ROUTINE PrintRoutine,
  201. IN OUT PPRINT_CONTEXT pContext,
  202. IN PSTR pszHeader,
  203. IN PCHAR pUtf8,
  204. IN DWORD Length
  205. )
  206. /*++
  207. Routine Description:
  208. Print bytes of UTF8 string.
  209. --*/
  210. {
  211. DWORD i;
  212. PrintRoutine(
  213. pContext,
  214. "%s\r\n"
  215. "\tUTF8 string %s\r\n"
  216. "\tlength %d\r\n"
  217. "\tbytes ",
  218. pszHeader,
  219. pUtf8,
  220. Length );
  221. for ( i=0; i<Length; i++ )
  222. {
  223. PrintRoutine(
  224. pContext,
  225. "%02x ",
  226. (UCHAR) pUtf8[i] );
  227. }
  228. printf( "\r\n" );
  229. }
  230. VOID
  231. DnsPrint_StringArray(
  232. IN PRINT_ROUTINE PrintRoutine,
  233. IN OUT PPRINT_CONTEXT pContext,
  234. IN PSTR pszHeader,
  235. IN PSTR * StringArray,
  236. IN DWORD Count, OPTIONAL
  237. IN BOOL fUnicode
  238. )
  239. /*++
  240. Routine Description:
  241. Print string array.
  242. --*/
  243. {
  244. DWORD i = 0;
  245. PCHAR pstr;
  246. if ( !pszHeader )
  247. {
  248. pszHeader = "StringArray:";
  249. }
  250. if ( !StringArray )
  251. {
  252. PrintRoutine(
  253. pContext,
  254. "%s NULL pointer!\r\n",
  255. pszHeader );
  256. }
  257. DnsPrint_Lock();
  258. if ( Count )
  259. {
  260. PrintRoutine(
  261. pContext,
  262. "%s Count = %d\r\n",
  263. pszHeader,
  264. Count );
  265. }
  266. else
  267. {
  268. PrintRoutine(
  269. pContext,
  270. "%s\r\n",
  271. pszHeader );
  272. }
  273. //
  274. // print args
  275. // - stop at Count (if given)
  276. // OR
  277. // - on NULL arg (if no count given)
  278. //
  279. while ( (!Count || i < Count) )
  280. {
  281. pstr = StringArray[i++];
  282. if ( !pstr && !Count )
  283. {
  284. break;
  285. }
  286. PrintRoutine(
  287. pContext,
  288. (fUnicode) ? "\t%S\r\n" : "\t%s\r\n",
  289. pstr );
  290. }
  291. DnsPrint_Unlock();
  292. }
  293. VOID
  294. DnsPrint_Argv(
  295. IN PRINT_ROUTINE PrintRoutine,
  296. IN OUT PPRINT_CONTEXT pContext,
  297. IN PSTR pszHeader,
  298. IN CHAR ** Argv,
  299. IN DWORD Argc, OPTIONAL
  300. IN BOOL fUnicode
  301. )
  302. /*++
  303. Routine Description:
  304. Print Argv array.
  305. --*/
  306. {
  307. //
  308. // this is just special case of string print
  309. //
  310. DnsPrint_StringArray(
  311. PrintRoutine,
  312. pContext,
  313. pszHeader
  314. ? pszHeader
  315. : "Argv:",
  316. Argv,
  317. Argc,
  318. fUnicode );
  319. }
  320. VOID
  321. DnsPrint_DwordArray(
  322. IN PRINT_ROUTINE PrintRoutine,
  323. IN OUT PPRINT_CONTEXT pContext,
  324. IN PSTR pszHeader,
  325. IN PSTR pszName,
  326. IN DWORD dwCount,
  327. IN PDWORD adwArray
  328. )
  329. /*++
  330. Routine Description:
  331. Print DWORD array.
  332. --*/
  333. {
  334. DWORD i;
  335. DnsPrint_Lock();
  336. if ( pszHeader )
  337. {
  338. PrintRoutine(
  339. pContext,
  340. pszHeader );
  341. }
  342. if ( !pszName )
  343. {
  344. pszName = "DWORD";
  345. }
  346. PrintRoutine(
  347. pContext,
  348. "%s Array Count = %d\r\n",
  349. pszName,
  350. dwCount );
  351. for( i=0; i<dwCount; i++ )
  352. {
  353. PrintRoutine(
  354. pContext,
  355. "\t%s[%d] => 0x%p (%d)\r\n",
  356. pszName,
  357. i,
  358. adwArray[i],
  359. adwArray[i] );
  360. }
  361. DnsPrint_Unlock();
  362. }
  363. VOID
  364. DnsPrint_IpAddressArray(
  365. IN PRINT_ROUTINE PrintRoutine,
  366. IN OUT PPRINT_CONTEXT pContext,
  367. IN PSTR pszHeader,
  368. IN PSTR pszName,
  369. IN DWORD dwIpAddrCount,
  370. IN PIP_ADDRESS pIpAddrs
  371. )
  372. /*++
  373. Routine Description:
  374. Print IP address array.
  375. --*/
  376. {
  377. DWORD i;
  378. DnsPrint_Lock();
  379. if ( !pszName )
  380. {
  381. pszName = "IP Addr";
  382. }
  383. PrintRoutine(
  384. pContext,
  385. "%s%s Count = %d\r\n",
  386. pszHeader ? pszHeader : "",
  387. pszName,
  388. dwIpAddrCount );
  389. if ( dwIpAddrCount != 0 && pIpAddrs != NULL )
  390. {
  391. // print array with count
  392. // use character print so works even if NOT DWORD aligned
  393. for( i=0; i<dwIpAddrCount; i++ )
  394. {
  395. PrintRoutine(
  396. pContext,
  397. "\t%s[%d] => %d.%d.%d.%d\r\n",
  398. pszName,
  399. i,
  400. * ( (PUCHAR) &pIpAddrs[i] + 0 ),
  401. * ( (PUCHAR) &pIpAddrs[i] + 1 ),
  402. * ( (PUCHAR) &pIpAddrs[i] + 2 ),
  403. * ( (PUCHAR) &pIpAddrs[i] + 3 ) );
  404. }
  405. }
  406. #if 0
  407. // this spins if printing zero length IP_ARRAY struct
  408. else if ( pIpAddrs != NULL )
  409. {
  410. // print NULL terminated array (ex. hostents IPs)
  411. i = 0;
  412. while ( pIpAddrs[i] )
  413. {
  414. PrintRoutine(
  415. pContext,
  416. "\t%s[%d] => %s\r\n",
  417. pszName,
  418. i,
  419. inet_ntoa( *(struct in_addr *) &pIpAddrs[i] ) );
  420. }
  421. }
  422. #endif
  423. DnsPrint_Unlock();
  424. }
  425. VOID
  426. DnsPrint_IpArray(
  427. IN PRINT_ROUTINE PrintRoutine,
  428. IN OUT PPRINT_CONTEXT pContext,
  429. IN PSTR pszHeader,
  430. IN PSTR pszName,
  431. IN PIP_ARRAY pIpArray
  432. )
  433. /*++
  434. Routine Description:
  435. Print IP address array struct
  436. Just pass through to more generic print routine.
  437. --*/
  438. {
  439. // protect against NULL case
  440. if ( !pIpArray )
  441. {
  442. PrintRoutine(
  443. pContext,
  444. "%s\tNULL IP Array.\r\n",
  445. pszHeader ? pszHeader : "" );
  446. }
  447. // call uncoupled IP array routine
  448. else
  449. {
  450. DnsPrint_IpAddressArray(
  451. PrintRoutine,
  452. pContext,
  453. pszHeader,
  454. pszName,
  455. pIpArray->AddrCount,
  456. pIpArray->AddrArray );
  457. }
  458. }
  459. VOID
  460. DnsPrint_DnsAddrArray(
  461. IN PRINT_ROUTINE PrintRoutine,
  462. IN OUT PPRINT_CONTEXT pContext,
  463. IN PSTR pszHeader,
  464. IN PDNS_ADDR_ARRAY pAddrArray
  465. )
  466. /*++
  467. Routine Description:
  468. Print IP address info array.
  469. --*/
  470. {
  471. DWORD i;
  472. if ( !pszHeader )
  473. {
  474. pszHeader = "Addr Array";
  475. }
  476. if ( !pAddrArray )
  477. {
  478. PrintRoutine(
  479. pContext,
  480. "%s NULL AddrArray ptr.\r\n",
  481. pszHeader );
  482. return;
  483. }
  484. DnsPrint_Lock();
  485. PrintRoutine(
  486. pContext,
  487. "%s\r\n"
  488. " Ptr = %p\r\n"
  489. " Count = %d\r\n",
  490. pszHeader ? pszHeader : "IP Address Info",
  491. pAddrArray,
  492. pAddrArray->AddrCount );
  493. //
  494. // print array up to count
  495. //
  496. // DCR: IP6 address info blob
  497. //
  498. for( i=0; i<pAddrArray->AddrCount; i++ )
  499. {
  500. IP_ADDRESS ip = pAddrArray->AddrArray[i].IpAddr;
  501. IP_ADDRESS subnetMask = pAddrArray->AddrArray[i].SubnetMask;
  502. PrintRoutine(
  503. pContext,
  504. "\tIP Address[%d] => %d.%d.%d.%d\r\n"
  505. "\tSubnetMask[%d] => %d.%d.%d.%d\r\n",
  506. i,
  507. (ip & 0xff),
  508. ((ip>>8) & 0xff),
  509. ((ip>>16) & 0xff),
  510. ((ip>>24) & 0xff),
  511. i,
  512. (subnetMask & 0xff),
  513. ((subnetMask>>8) & 0xff),
  514. ((subnetMask>>16) & 0xff),
  515. ((subnetMask>>24) & 0xff)
  516. );
  517. }
  518. DnsPrint_Unlock();
  519. }
  520. VOID
  521. DnsPrint_Ip6Address(
  522. IN PRINT_ROUTINE PrintRoutine,
  523. IN OUT PPRINT_CONTEXT pContext,
  524. IN PSTR pszHeader,
  525. IN PIP6_ADDRESS pIp6Address,
  526. IN PSTR pszTrailer
  527. )
  528. /*++
  529. Routine Description:
  530. Print IP6 address.
  531. Arguments:
  532. PrintRoutine -- print routine to call
  533. pContext -- first argument to print routine
  534. pszHeader -- header to print
  535. NOTE: unlike other print routines this routine
  536. requires header to contain newline,tab, etc if
  537. multiline print is desired; the reason is to allow
  538. use of this routine for single line print
  539. pIp6Address -- ptr to IP6 address to print
  540. pszTrailer -- trailer to print
  541. NOTE: again this routine is designed to allow single
  542. line print; if newline required after print, send
  543. newline in trailer
  544. Return Value:
  545. Ptr to next location in buffer (the terminating NULL).
  546. --*/
  547. {
  548. CHAR buffer[ IP6_ADDRESS_STRING_BUFFER_LENGTH ];
  549. if ( !pszHeader )
  550. {
  551. pszHeader = "IP6 Address: ";
  552. }
  553. if ( !pszTrailer )
  554. {
  555. pszHeader = "\r\n";
  556. }
  557. if ( !pIp6Address )
  558. {
  559. PrintRoutine(
  560. pContext,
  561. "%s NULL IP6 address ptr.%s",
  562. pszHeader,
  563. pszTrailer );
  564. }
  565. // convert IP6 address to string
  566. Dns_Ip6AddressToString_A(
  567. buffer,
  568. pIp6Address );
  569. PrintRoutine(
  570. pContext,
  571. "%s%s%s",
  572. pszHeader,
  573. buffer,
  574. pszTrailer );
  575. }
  576. //
  577. // Print routines for DNS types and structures
  578. //
  579. INT
  580. Dns_WritePacketNameToBuffer(
  581. OUT PCHAR pBuffer,
  582. OUT PCHAR * ppBufferOut,
  583. IN PBYTE pMsgName,
  584. IN PDNS_HEADER pMsgHead, OPTIONAL
  585. IN PBYTE pMsgEnd OPTIONAL
  586. )
  587. /*++
  588. Routine Description:
  589. Write packet name into buffer.
  590. Arguments:
  591. pBuffer - buffer to print to,
  592. bounds checking done only on each loop to limit to
  593. twice DNS_MAX_NAME_LENGTH, recommend input buffer
  594. of at least that length
  595. ppBufferOut - ptr to terminating NULL in buffer conversion, this
  596. is position at which additional printing to buffer
  597. could resume
  598. pMsgName - ptr to name in packet to print
  599. pMsgHead - ptr to DNS message; need for offsetting, if not given
  600. names are not printed past first offset
  601. pMsgEnd - ptr to end of message, specifically byte immediately after
  602. message
  603. Return Value:
  604. Count of bytes in packet name occupied.
  605. This offset from pMsgName is the next field in the packet.
  606. Zero return indicates error in message name.
  607. --*/
  608. {
  609. register PUCHAR pchbuf;
  610. register PUCHAR pchmsg;
  611. register UCHAR cch;
  612. PCHAR pbufStop;
  613. PCHAR pnextLabel;
  614. UCHAR compressionType;
  615. WORD offset;
  616. PCHAR pbyteAfterFirstOffset = NULL;
  617. //
  618. // no message end specified?
  619. // make it max ptr so we can do single test for ptr validity
  620. // rather than testing for pMsgEnd existence first
  621. //
  622. if ( !pMsgEnd )
  623. {
  624. pMsgEnd = (PVOID)(INT_PTR)(-1);
  625. }
  626. //
  627. // loop until copy as printable name, or hit compression or name error
  628. //
  629. pchbuf = pBuffer;
  630. pbufStop = pchbuf + DNS_MAX_NAME_LENGTH + DNS_MAX_LABEL_LENGTH;
  631. pchmsg = pMsgName;
  632. while ( 1 )
  633. {
  634. // bounds checking to survive bad packet
  635. //
  636. // DEVNOTE: note this is not strictly a bad packet (could be just a
  637. // heck of a lot of labels) and we could
  638. // a) let packet processing proceed without printing
  639. // or
  640. // b) require buffer that could contain max legal DNS name
  641. // but not worth the effort
  642. if ( pchbuf >= pbufStop )
  643. {
  644. pchbuf += sprintf(
  645. pchbuf,
  646. "[ERROR name exceeds safe print buffer length]\r\n" );
  647. pchmsg = pMsgName;
  648. break;
  649. }
  650. cch = (UCHAR) *pchmsg++;
  651. compressionType = cch & 0xC0;
  652. DNSDBG( OFF, (
  653. "byte = (%d) (0x%02x)\r\n"
  654. "compress flag = (%d) (0x%02x)\r\n",
  655. cch, cch,
  656. compressionType, compressionType ));
  657. //
  658. // normal length byte
  659. // - write length field
  660. // - copy label to print buffer
  661. //
  662. if ( compressionType == 0 )
  663. {
  664. pchbuf += sprintf( pchbuf, "(%d)", (INT)cch );
  665. // terminate at root name
  666. if ( ! cch )
  667. {
  668. break;
  669. }
  670. // check that within packet
  671. pnextLabel = pchmsg + cch;
  672. if ( pnextLabel >= pMsgEnd )
  673. {
  674. pchbuf += sprintf(
  675. pchbuf,
  676. "[ERROR length byte: 0x%02X at %p leads outside message]\r\n",
  677. cch,
  678. pchmsg );
  679. // force zero byte return
  680. pchmsg = pMsgName;
  681. break;
  682. }
  683. // copy label to output string
  684. memcpy(
  685. pchbuf,
  686. pchmsg,
  687. cch );
  688. pchbuf += cch;
  689. pchmsg = pnextLabel;
  690. continue;
  691. }
  692. //
  693. // valid compression
  694. //
  695. else if ( compressionType == (UCHAR)0xC0 )
  696. {
  697. // check that compression word not straddling message end
  698. if ( pchmsg >= pMsgEnd )
  699. {
  700. pchbuf += sprintf(
  701. pchbuf,
  702. "[ERROR compression word at %p is outside message]\r\n",
  703. pchmsg );
  704. // force zero byte return
  705. pchmsg = pMsgName;
  706. break;
  707. }
  708. // calculate offset
  709. offset = cch; // high byte
  710. offset <<= 8;
  711. offset |= *pchmsg++; // low byte
  712. pchbuf += sprintf(
  713. pchbuf,
  714. "[%04hX]",
  715. offset );
  716. if ( pMsgHead )
  717. {
  718. //
  719. // on first compression, save ptr to byte immediately after
  720. // name, so can calculate next byte
  721. //
  722. // save ptr to next byte in mess, to calculate actual length
  723. // name takes up in packet
  724. //
  725. if ( ! pbyteAfterFirstOffset )
  726. {
  727. pbyteAfterFirstOffset = pchmsg;
  728. }
  729. //
  730. // jump to offset for continuation of name
  731. // - clear two highest bits to get length
  732. //
  733. offset = offset ^ 0xC000;
  734. DNS_ASSERT( (offset & 0xC000) == 0 );
  735. pnextLabel = (PCHAR)pMsgHead + offset;
  736. if ( pnextLabel >= pchmsg - sizeof(WORD) )
  737. {
  738. pchbuf += sprintf(
  739. pchbuf,
  740. "[ERROR offset at %p to higher byte in packet %p]\r\n",
  741. pchmsg - sizeof(WORD),
  742. pnextLabel );
  743. break;
  744. }
  745. pchmsg = pnextLabel;
  746. continue;
  747. }
  748. // if no ptr to message head, can not continue at offset
  749. // NULL terminate previous label
  750. else
  751. {
  752. *pchbuf++ = 0;
  753. break;
  754. }
  755. }
  756. //
  757. // invalid compression
  758. // - force zero byte return to indicate error
  759. else
  760. {
  761. pchbuf += sprintf(
  762. pchbuf,
  763. "[ERROR length byte: 0x%02X]",
  764. cch );
  765. pchmsg = pMsgName;
  766. break;
  767. }
  768. }
  769. //
  770. // return ptr to next position in output buffer
  771. //
  772. if ( ppBufferOut )
  773. {
  774. *ppBufferOut = pchbuf;
  775. }
  776. //
  777. // return number of bytes read from message
  778. //
  779. if ( pbyteAfterFirstOffset )
  780. {
  781. pchmsg = pbyteAfterFirstOffset;
  782. }
  783. return (INT)( pchmsg - pMsgName );
  784. }
  785. INT
  786. DnsPrint_PacketName(
  787. IN PRINT_ROUTINE PrintRoutine,
  788. IN OUT PPRINT_CONTEXT pContext,
  789. IN PSTR pszHeader, OPTIONAL
  790. IN PBYTE pMsgName,
  791. IN PDNS_HEADER pMsgHead, OPTIONAL
  792. IN PBYTE pMsgEnd, OPTIONAL
  793. IN PSTR pszTrailer OPTIONAL
  794. )
  795. /*++
  796. Routine Description:
  797. Print DNS name given in packet format.
  798. Arguments:
  799. PrintRoutine - routine to print with
  800. pszHeader - header to print
  801. pMsgHead - ptr to DNS message; need for offsetting, if not given
  802. names are not printed past first offset
  803. pMsgName - ptr to name in packet to print
  804. pMsgEnd - ptr to end of message; OPTIONAL, but needed to protect
  805. against AV accessing bad packet names
  806. pszTrailer - trailer to print after name
  807. Return Value:
  808. Count of bytes in packet name occupied.
  809. This offset from pMsgName is the next field in the packet.
  810. Zero return indicates error in message name.
  811. --*/
  812. {
  813. INT countNameBytes;
  814. // name buffer, allow space for full name, plus parens on length
  815. // fields plus several compression flags
  816. CHAR PrintName[ 2*DNS_MAX_NAME_LENGTH ];
  817. if ( ! pMsgName )
  818. {
  819. PrintRoutine(
  820. pContext,
  821. "%s(NULL packet name ptr)%s\r\n",
  822. pszHeader ? pszHeader : "",
  823. pszTrailer ? pszTrailer : ""
  824. );
  825. return 0;
  826. }
  827. //
  828. // build packet name into buffer, then print
  829. //
  830. countNameBytes = Dns_WritePacketNameToBuffer(
  831. PrintName,
  832. NULL,
  833. pMsgName,
  834. pMsgHead,
  835. pMsgEnd
  836. );
  837. PrintRoutine(
  838. pContext,
  839. "%s%s%s",
  840. pszHeader ? pszHeader : "",
  841. PrintName,
  842. pszTrailer ? pszTrailer : ""
  843. );
  844. return( countNameBytes );
  845. }
  846. VOID
  847. DnsPrint_Message(
  848. IN PRINT_ROUTINE PrintRoutine,
  849. IN OUT PPRINT_CONTEXT pContext,
  850. IN PSTR pszHeader,
  851. IN PDNS_MSG_BUF pMsg
  852. )
  853. /*++
  854. Routine Description:
  855. Print DNS message buffer.
  856. Includes context information as well as actual DNS message.
  857. --*/
  858. {
  859. PDNS_HEADER pmsgHeader;
  860. PCHAR pchRecord;
  861. PBYTE pmsgEnd;
  862. INT i;
  863. INT isection;
  864. INT cchName;
  865. WORD wLength;
  866. WORD wOffset;
  867. WORD wXid;
  868. WORD wQuestionCount;
  869. WORD wAnswerCount;
  870. WORD wNameServerCount;
  871. WORD wAdditionalCount;
  872. WORD countSectionRR;
  873. BOOL fFlipped = FALSE;
  874. DnsPrint_Lock();
  875. if ( pszHeader )
  876. {
  877. PrintRoutine(
  878. pContext,
  879. "%s\r\n",
  880. pszHeader );
  881. }
  882. // get message info
  883. //
  884. // note: length may not be correctly set while building message,
  885. // so make pmsgEnd greater of given length and pCurrent ptr
  886. // but allow for case where set back to pre-OPT length
  887. //
  888. wLength = pMsg->MessageLength;
  889. pmsgHeader = &pMsg->MessageHead;
  890. pmsgEnd = ((PBYTE)pmsgHeader) + wLength;
  891. if ( pmsgEnd < pMsg->pCurrent &&
  892. pmsgEnd != pMsg->pPreOptEnd )
  893. {
  894. pmsgEnd = pMsg->pCurrent;
  895. }
  896. //
  897. // print header info
  898. //
  899. PrintRoutine(
  900. pContext,
  901. "%s %s info at %p\r\n"
  902. " Socket = %d\r\n"
  903. " Remote addr %s, port %ld\r\n"
  904. " Buf length = 0x%04x\r\n"
  905. " Msg length = 0x%04x\r\n"
  906. " Message:\r\n",
  907. ( pMsg->fTcp
  908. ? "TCP"
  909. : "UDP" ),
  910. ( pmsgHeader->IsResponse
  911. ? "response"
  912. : "question" ),
  913. pMsg,
  914. pMsg->Socket,
  915. MSG_REMOTE_IP_STRING( pMsg ),
  916. MSG_REMOTE_IP_PORT( pMsg ),
  917. pMsg->BufferLength,
  918. wLength
  919. );
  920. PrintRoutine(
  921. pContext,
  922. " XID 0x%04hx\r\n"
  923. " Flags 0x%04hx\r\n"
  924. " QR 0x%lx (%s)\r\n"
  925. " OPCODE 0x%lx (%s)\r\n"
  926. " AA 0x%lx\r\n"
  927. " TC 0x%lx\r\n"
  928. " RD 0x%lx\r\n"
  929. " RA 0x%lx\r\n"
  930. " Z 0x%lx\r\n"
  931. " RCODE 0x%lx (%s)\r\n"
  932. " QCOUNT 0x%hx\r\n"
  933. " ACOUNT 0x%hx\r\n"
  934. " NSCOUNT 0x%hx\r\n"
  935. " ARCOUNT 0x%hx\r\n",
  936. pmsgHeader->Xid,
  937. ntohs((*((PWORD)pmsgHeader + 1))),
  938. pmsgHeader->IsResponse,
  939. (pmsgHeader->IsResponse ? "response" : "question"),
  940. pmsgHeader->Opcode,
  941. Dns_OpcodeString( pmsgHeader->Opcode ),
  942. pmsgHeader->Authoritative,
  943. pmsgHeader->Truncation,
  944. pmsgHeader->RecursionDesired,
  945. pmsgHeader->RecursionAvailable,
  946. pmsgHeader->Reserved,
  947. pmsgHeader->ResponseCode,
  948. Dns_ResponseCodeString( pmsgHeader->ResponseCode ),
  949. pmsgHeader->QuestionCount,
  950. pmsgHeader->AnswerCount,
  951. pmsgHeader->NameServerCount,
  952. pmsgHeader->AdditionalCount );
  953. //
  954. // determine if byte flipped and get correct count
  955. //
  956. wXid = pmsgHeader->Xid;
  957. wQuestionCount = pmsgHeader->QuestionCount;
  958. wAnswerCount = pmsgHeader->AnswerCount;
  959. wNameServerCount = pmsgHeader->NameServerCount;
  960. wAdditionalCount = pmsgHeader->AdditionalCount;
  961. if ( wQuestionCount )
  962. {
  963. fFlipped = wQuestionCount & 0xff00;
  964. }
  965. else if ( wNameServerCount )
  966. {
  967. fFlipped = wNameServerCount & 0xff00;
  968. }
  969. if ( fFlipped )
  970. {
  971. wXid = ntohs( wXid );
  972. wQuestionCount = ntohs( wQuestionCount );
  973. wAnswerCount = ntohs( wAnswerCount );
  974. wNameServerCount = ntohs( wNameServerCount );
  975. wAdditionalCount = ntohs( wAdditionalCount );
  976. }
  977. //
  978. // catch record flipping problems -- all are flipped or none at all
  979. // and no record count should be > 256 EXCEPT answer count
  980. // during FAST zone transfer
  981. //
  982. DNS_ASSERT( ! (wQuestionCount & 0xff00) );
  983. DNS_ASSERT( ! (wNameServerCount & 0xff00) );
  984. DNS_ASSERT( ! (wAdditionalCount & 0xff00) );
  985. #if 0
  986. //
  987. // stop here if WINS response -- don't have parsing ready
  988. //
  989. if ( pmsgHeader->IsResponse && IS_WINS_XID(wXid) )
  990. {
  991. PrintRoutine(
  992. pContext,
  993. " WINS Response packet.\r\n\r\n" );
  994. goto Unlock;
  995. }
  996. #endif
  997. //
  998. // print questions and resource records
  999. //
  1000. pchRecord = (PCHAR)(pmsgHeader + 1);
  1001. for ( isection=0; isection<4; isection++)
  1002. {
  1003. PrintRoutine(
  1004. pContext,
  1005. " %s Section:\r\n",
  1006. Dns_SectionNameString( isection, pmsgHeader->Opcode ) );
  1007. if ( isection==0 )
  1008. {
  1009. countSectionRR = wQuestionCount;
  1010. }
  1011. else if ( isection==1 )
  1012. {
  1013. countSectionRR = wAnswerCount;
  1014. }
  1015. else if ( isection==2 )
  1016. {
  1017. countSectionRR = wNameServerCount;
  1018. }
  1019. else if ( isection==3 )
  1020. {
  1021. countSectionRR = wAdditionalCount;
  1022. }
  1023. for ( i=0; i < countSectionRR; i++ )
  1024. {
  1025. //
  1026. // verify not overrunning length
  1027. // - check against pCurrent as well as message length
  1028. // so can print packets while being built
  1029. //
  1030. wOffset = (WORD)(pchRecord - (PCHAR)pmsgHeader);
  1031. if ( wOffset >= wLength
  1032. &&
  1033. pchRecord >= pMsg->pCurrent )
  1034. {
  1035. PrintRoutine(
  1036. pContext,
  1037. "ERROR: BOGUS PACKET:\r\n"
  1038. "\tFollowing RR (offset %d) past packet length (%d).\r\n",
  1039. wOffset,
  1040. wLength
  1041. );
  1042. goto Unlock;
  1043. }
  1044. //
  1045. // print RR name
  1046. //
  1047. PrintRoutine(
  1048. pContext,
  1049. " Name Offset = 0x%04x\r\n",
  1050. wOffset
  1051. );
  1052. cchName = DnsPrint_PacketName(
  1053. PrintRoutine,
  1054. pContext,
  1055. " Name \"",
  1056. pchRecord,
  1057. pmsgHeader,
  1058. pmsgEnd,
  1059. "\"\r\n" );
  1060. if ( ! cchName )
  1061. {
  1062. PrintRoutine(
  1063. pContext,
  1064. "ERROR: Invalid name length, stop packet print\r\n" );
  1065. DNS_ASSERT( FALSE );
  1066. break;
  1067. }
  1068. pchRecord += cchName;
  1069. // print question or resource record
  1070. if ( isection == 0 )
  1071. {
  1072. PrintRoutine(
  1073. pContext,
  1074. " QTYPE %d\r\n"
  1075. " QCLASS %d\r\n",
  1076. FlipUnalignedWord( pchRecord ),
  1077. FlipUnalignedWord( pchRecord + sizeof(WORD) )
  1078. );
  1079. pchRecord += sizeof( DNS_WIRE_QUESTION );
  1080. }
  1081. else
  1082. {
  1083. pchRecord += DnsPrint_PacketRecord(
  1084. PrintRoutine,
  1085. pContext,
  1086. NULL,
  1087. (PDNS_WIRE_RECORD) pchRecord,
  1088. pmsgHeader,
  1089. pmsgEnd
  1090. );
  1091. }
  1092. }
  1093. }
  1094. // check that at proper end of packet
  1095. wOffset = (WORD)(pchRecord - (PCHAR)pmsgHeader);
  1096. if ( pchRecord < pMsg->pCurrent || wOffset < wLength )
  1097. {
  1098. PrintRoutine(
  1099. pContext,
  1100. "WARNING: message continues beyond these records\r\n"
  1101. "\tpch = %p, pCurrent = %p, %d bytes\r\n"
  1102. "\toffset = %d, msg length = %d, %d bytes\r\n",
  1103. pchRecord,
  1104. pMsg->pCurrent,
  1105. pMsg->pCurrent - pchRecord,
  1106. wOffset,
  1107. wLength,
  1108. wLength - wOffset );
  1109. }
  1110. PrintRoutine(
  1111. pContext,
  1112. " Message length = %04x\n\r\n",
  1113. wOffset );
  1114. Unlock:
  1115. DnsPrint_Unlock();
  1116. } // DnsPrint_Message
  1117. INT
  1118. DnsPrint_PacketRecord(
  1119. IN PRINT_ROUTINE PrintRoutine,
  1120. IN OUT PPRINT_CONTEXT pContext,
  1121. IN PSTR pszHeader,
  1122. IN PDNS_WIRE_RECORD pMsgRR,
  1123. IN PDNS_HEADER pMsgHead, OPTIONAL
  1124. IN PBYTE pMsgEnd OPTIONAL
  1125. )
  1126. /*++
  1127. Routine Description:
  1128. Print RR in packet format.
  1129. Arguments:
  1130. pszHeader - Header message/name for RR.
  1131. pMsgRR - resource record to print
  1132. pMsgHead - ptr to DNS message; need for offsetting, if not given
  1133. names are not printed past first offset
  1134. pMsgEnd - ptr to end of message, specifically byte immediately after
  1135. message
  1136. Return Value:
  1137. Number of bytes in record.
  1138. --*/
  1139. {
  1140. PCHAR pdata = (PCHAR)(pMsgRR + 1);
  1141. PCHAR pdataStop;
  1142. WORD dlen = FlipUnalignedWord( &pMsgRR->DataLength );
  1143. WORD type;
  1144. PCHAR pRRString;
  1145. DnsPrint_Lock();
  1146. //
  1147. // print RR fixed fields
  1148. //
  1149. type = FlipUnalignedWord( &pMsgRR->RecordType );
  1150. pRRString = Dns_RecordStringForType( type );
  1151. if ( pszHeader )
  1152. {
  1153. PrintRoutine(
  1154. pContext,
  1155. "%s\r\n",
  1156. pszHeader );
  1157. }
  1158. PrintRoutine(
  1159. pContext,
  1160. " TYPE %s (%u)\r\n"
  1161. " CLASS %u\r\n"
  1162. " TTL %lu\r\n"
  1163. " DLEN %u\r\n"
  1164. " DATA ",
  1165. pRRString,
  1166. type,
  1167. FlipUnalignedWord( &pMsgRR->RecordClass ),
  1168. FlipUnalignedDword( &pMsgRR->TimeToLive ),
  1169. dlen );
  1170. //
  1171. // update records may not have data
  1172. //
  1173. if ( dlen == 0 )
  1174. {
  1175. PrintRoutine(
  1176. pContext,
  1177. "(none)\r\n" );
  1178. goto Done;
  1179. }
  1180. // stop byte after RR data
  1181. pdataStop = pdata + dlen;
  1182. if ( pMsgEnd < pdataStop )
  1183. {
  1184. PrintRoutine(
  1185. pContext,
  1186. "ERROR: record at %p extends past end of packet!\n"
  1187. "\tpmsg = %p\n"
  1188. "\tpmsgEnd = %p\n"
  1189. "\trecord end = %p\n",
  1190. pMsgRR,
  1191. pMsgHead,
  1192. pMsgEnd,
  1193. pdataStop );
  1194. goto Done;
  1195. }
  1196. //
  1197. // print RR data
  1198. //
  1199. switch ( type )
  1200. {
  1201. case DNS_TYPE_A:
  1202. PrintRoutine(
  1203. pContext,
  1204. "%d.%d.%d.%d\r\n",
  1205. * (PUCHAR)( pdata + 0 ),
  1206. * (PUCHAR)( pdata + 1 ),
  1207. * (PUCHAR)( pdata + 2 ),
  1208. * (PUCHAR)( pdata + 3 )
  1209. );
  1210. break;
  1211. case DNS_TYPE_AAAA:
  1212. {
  1213. IP6_ADDRESS ip6;
  1214. RtlCopyMemory(
  1215. &ip6,
  1216. pdata,
  1217. sizeof(ip6) );
  1218. PrintRoutine(
  1219. pContext,
  1220. "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
  1221. ip6.IP6Word[0],
  1222. ip6.IP6Word[1],
  1223. ip6.IP6Word[2],
  1224. ip6.IP6Word[3],
  1225. ip6.IP6Word[4],
  1226. ip6.IP6Word[5],
  1227. ip6.IP6Word[6],
  1228. ip6.IP6Word[7]
  1229. );
  1230. break;
  1231. }
  1232. case DNS_TYPE_PTR:
  1233. case DNS_TYPE_NS:
  1234. case DNS_TYPE_CNAME:
  1235. case DNS_TYPE_MD:
  1236. case DNS_TYPE_MB:
  1237. case DNS_TYPE_MF:
  1238. case DNS_TYPE_MG:
  1239. case DNS_TYPE_MR:
  1240. //
  1241. // these RRs contain single domain name
  1242. //
  1243. DnsPrint_PacketName(
  1244. PrintRoutine,
  1245. pContext,
  1246. NULL,
  1247. pdata,
  1248. pMsgHead,
  1249. pMsgEnd,
  1250. "\r\n" );
  1251. break;
  1252. case DNS_TYPE_MX:
  1253. case DNS_TYPE_RT:
  1254. case DNS_TYPE_AFSDB:
  1255. //
  1256. // these RR contain
  1257. // - one preference value
  1258. // - one domain name
  1259. //
  1260. PrintRoutine(
  1261. pContext,
  1262. "%d ",
  1263. FlipUnalignedWord( pdata )
  1264. );
  1265. DnsPrint_PacketName(
  1266. PrintRoutine,
  1267. pContext,
  1268. NULL,
  1269. pdata + sizeof(WORD),
  1270. pMsgHead,
  1271. pMsgEnd,
  1272. "\r\n" );
  1273. break;
  1274. case DNS_TYPE_SOA:
  1275. pdata += DnsPrint_PacketName(
  1276. PrintRoutine,
  1277. pContext,
  1278. "\r\n\t\tPrimaryServer: ",
  1279. pdata,
  1280. pMsgHead,
  1281. pMsgEnd,
  1282. NULL );
  1283. pdata += DnsPrint_PacketName(
  1284. PrintRoutine,
  1285. pContext,
  1286. "\r\n\t\tAdministrator: ",
  1287. pdata,
  1288. pMsgHead,
  1289. pMsgEnd,
  1290. "\r\n" );
  1291. PrintRoutine(
  1292. pContext,
  1293. "\t\tSerialNo = %d\r\n"
  1294. "\t\tRefresh = %d\r\n"
  1295. "\t\tRetry = %d\r\n"
  1296. "\t\tExpire = %d\r\n"
  1297. "\t\tMinimumTTL = %d\r\n",
  1298. FlipUnalignedDword( pdata ),
  1299. FlipUnalignedDword( (PDWORD)pdata+1 ),
  1300. FlipUnalignedDword( (PDWORD)pdata+2 ),
  1301. FlipUnalignedDword( (PDWORD)pdata+3 ),
  1302. FlipUnalignedDword( (PDWORD)pdata+4 )
  1303. );
  1304. break;
  1305. case DNS_TYPE_MINFO:
  1306. case DNS_TYPE_RP:
  1307. //
  1308. // these RRs contain two domain names
  1309. //
  1310. pdata += DnsPrint_PacketName(
  1311. PrintRoutine,
  1312. pContext,
  1313. NULL,
  1314. pdata,
  1315. pMsgHead,
  1316. pMsgEnd,
  1317. NULL );
  1318. DnsPrint_PacketName(
  1319. PrintRoutine,
  1320. pContext,
  1321. " ",
  1322. pdata,
  1323. pMsgHead,
  1324. pMsgEnd,
  1325. "\r\n" );
  1326. break;
  1327. case DNS_TYPE_TEXT:
  1328. case DNS_TYPE_HINFO:
  1329. case DNS_TYPE_ISDN:
  1330. case DNS_TYPE_X25:
  1331. {
  1332. //
  1333. // all these are simply text string(s)
  1334. //
  1335. PCHAR pch = pdata;
  1336. PCHAR pchStop = pch + dlen;
  1337. UCHAR cch;
  1338. while ( pch < pchStop )
  1339. {
  1340. cch = (UCHAR) *pch++;
  1341. PrintRoutine(
  1342. pContext,
  1343. "\t%.*s\r\n",
  1344. cch,
  1345. pch );
  1346. pch += cch;
  1347. }
  1348. if ( pch != pchStop )
  1349. {
  1350. PrintRoutine(
  1351. pContext,
  1352. "ERROR: Bad RR. "
  1353. "Text strings do not add to RR length.\r\n" );
  1354. }
  1355. break;
  1356. }
  1357. case DNS_TYPE_WKS:
  1358. {
  1359. INT i;
  1360. PrintRoutine(
  1361. pContext,
  1362. "WKS: Address %d.%d.%d.%d\r\n"
  1363. "\t\tProtocol %d\r\n"
  1364. "\t\tBitmask\r\n",
  1365. * (PUCHAR)( pdata + 0 ),
  1366. * (PUCHAR)( pdata + 1 ),
  1367. * (PUCHAR)( pdata + 2 ),
  1368. * (PUCHAR)( pdata + 3 ),
  1369. * (PUCHAR)( pdata + 4 ) );
  1370. pdata += SIZEOF_WKS_FIXED_DATA;
  1371. for ( i=0; i < (INT)(dlen-SIZEOF_WKS_FIXED_DATA); i++ )
  1372. {
  1373. PrintRoutine(
  1374. pContext,
  1375. "\t\t\tbyte[%d] = %x\r\n",
  1376. i,
  1377. (UCHAR) pdata[i] );
  1378. }
  1379. break;
  1380. }
  1381. case DNS_TYPE_NULL:
  1382. DnsPrint_RawOctets(
  1383. PrintRoutine,
  1384. pContext,
  1385. NULL,
  1386. "\t\t",
  1387. pdata,
  1388. dlen );
  1389. break;
  1390. case DNS_TYPE_SRV:
  1391. // SRV <priority> <weight> <port> <target host>
  1392. PrintRoutine(
  1393. pContext,
  1394. "\t\tPriority = %d\r\n"
  1395. "\t\tWeight = %d\r\n"
  1396. "\t\tPort = %d\r\n",
  1397. FlipUnalignedWord( pdata ),
  1398. FlipUnalignedWord( (PWORD)pdata+1 ),
  1399. FlipUnalignedWord( (PWORD)pdata+2 )
  1400. );
  1401. DnsPrint_PacketName(
  1402. PrintRoutine,
  1403. pContext,
  1404. "\t\tTarget host ",
  1405. pdata + 3*sizeof(WORD),
  1406. pMsgHead,
  1407. pMsgEnd,
  1408. "\r\n" );
  1409. break;
  1410. case DNS_TYPE_OPT:
  1411. //
  1412. // OPT
  1413. // - RR class is buffer size
  1414. // - RR TTL contains
  1415. // <extended RCODE> low byte
  1416. // <version> second byte
  1417. // <flags-zero> high word
  1418. //
  1419. {
  1420. BYTE version;
  1421. BYTE extendedRcode;
  1422. DWORD fullRcode = 0;
  1423. WORD flags;
  1424. extendedRcode = *( (PBYTE) &pMsgRR->TimeToLive );
  1425. version = *( (PBYTE) &pMsgRR->TimeToLive + 1 );
  1426. flags = *( (PWORD) &pMsgRR->TimeToLive + 1 );
  1427. if ( pMsgHead->ResponseCode )
  1428. {
  1429. fullRcode = ((DWORD)extendedRcode << 4) +
  1430. (DWORD)pMsgHead->ResponseCode;
  1431. }
  1432. PrintRoutine(
  1433. pContext,
  1434. "\t\tBuffer Size = %d\r\n"
  1435. "\t\tRcode Ext = %d (%x)\r\n"
  1436. "\t\tRcode Full = %d\r\n"
  1437. "\t\tVersion = %d\r\n"
  1438. "\t\tFlags = %x\r\n",
  1439. FlipUnalignedWord( &pMsgRR->RecordClass ),
  1440. extendedRcode, extendedRcode,
  1441. fullRcode,
  1442. version,
  1443. flags );
  1444. }
  1445. break;
  1446. case DNS_TYPE_TKEY:
  1447. {
  1448. DWORD beginTime;
  1449. DWORD expireTime;
  1450. WORD keyLength;
  1451. WORD mode;
  1452. WORD extRcode;
  1453. WORD otherLength;
  1454. otherLength = (WORD)DnsPrint_PacketName(
  1455. PrintRoutine,
  1456. pContext,
  1457. "\r\n\t\tAlgorithm: ",
  1458. pdata,
  1459. pMsgHead,
  1460. pMsgEnd,
  1461. NULL );
  1462. if ( !otherLength )
  1463. {
  1464. PrintRoutine(
  1465. pContext,
  1466. "Invalid algorithm name in TKEY RR!\r\n" );
  1467. }
  1468. pdata += otherLength;
  1469. beginTime = InlineFlipUnalignedDword( pdata );
  1470. pdata += sizeof(DWORD);
  1471. expireTime = InlineFlipUnalignedDword( pdata );
  1472. pdata += sizeof(DWORD);
  1473. mode = InlineFlipUnalignedWord( pdata );
  1474. pdata += sizeof(WORD);
  1475. extRcode = InlineFlipUnalignedWord( pdata );
  1476. pdata += sizeof(WORD);
  1477. keyLength = InlineFlipUnalignedWord( pdata );
  1478. pdata += sizeof(WORD);
  1479. PrintRoutine(
  1480. pContext,
  1481. "\r\n"
  1482. "\t\tCreate time = %d\r\n"
  1483. "\t\tExpire time = %d\r\n"
  1484. "\t\tMode = %d\r\n"
  1485. "\t\tExtended RCODE = %d\r\n"
  1486. "\t\tKey Length = %d\r\n",
  1487. beginTime,
  1488. expireTime,
  1489. mode,
  1490. extRcode,
  1491. keyLength );
  1492. if ( pdata + keyLength > pdataStop )
  1493. {
  1494. PrintRoutine(
  1495. pContext,
  1496. "Invalid key length: exceeds record data!\r\n" );
  1497. break;
  1498. }
  1499. DnsPrint_RawOctets(
  1500. PrintRoutine,
  1501. pContext,
  1502. "\t\tKey:",
  1503. "\t\t ", // line header
  1504. pdata,
  1505. keyLength );
  1506. pdata += keyLength;
  1507. if ( pdata + sizeof(WORD) > pdataStop )
  1508. {
  1509. break;
  1510. }
  1511. otherLength = InlineFlipUnalignedWord( pdata );
  1512. pdata += sizeof(WORD);
  1513. PrintRoutine(
  1514. pContext,
  1515. "\r\n"
  1516. "\t\tOther Length = %d\r\n",
  1517. otherLength );
  1518. if ( pdata + otherLength > pdataStop )
  1519. {
  1520. PrintRoutine(
  1521. pContext,
  1522. "Invalid other data length: exceeds record data!\r\n" );
  1523. break;
  1524. }
  1525. DnsPrint_RawOctets(
  1526. PrintRoutine,
  1527. pContext,
  1528. "\t\tOther Data:",
  1529. "\t\t ", // line header
  1530. pdata,
  1531. otherLength );
  1532. break;
  1533. }
  1534. case DNS_TYPE_TSIG:
  1535. {
  1536. ULONGLONG signTime;
  1537. WORD fudgeTime;
  1538. WORD sigLength;
  1539. WORD extRcode;
  1540. WORD wOriginalId;
  1541. WORD otherLength;
  1542. otherLength = (WORD) DnsPrint_PacketName(
  1543. PrintRoutine,
  1544. pContext,
  1545. "\r\n\t\tAlgorithm: ",
  1546. pdata,
  1547. pMsgHead,
  1548. pMsgEnd,
  1549. NULL );
  1550. if ( !otherLength )
  1551. {
  1552. PrintRoutine(
  1553. pContext,
  1554. "Invalid algorithm name in TSIG RR!\r\n" );
  1555. }
  1556. pdata += otherLength;
  1557. signTime = InlineFlipUnaligned48Bits( pdata );
  1558. pdata += sizeof(DWORD) + sizeof(WORD);
  1559. fudgeTime = InlineFlipUnalignedWord( pdata );
  1560. pdata += sizeof(WORD);
  1561. sigLength = InlineFlipUnalignedWord( pdata );
  1562. pdata += sizeof(WORD);
  1563. PrintRoutine(
  1564. pContext,
  1565. "\r\n"
  1566. "\t\tSigned time = %I64u\r\n"
  1567. "\t\tFudge time = %u\r\n"
  1568. "\t\tSig Length = %u\r\n",
  1569. signTime,
  1570. fudgeTime,
  1571. sigLength );
  1572. if ( pdata + sigLength > pdataStop )
  1573. {
  1574. PrintRoutine(
  1575. pContext,
  1576. "Invalid signature length: exceeds record data!\r\n" );
  1577. break;
  1578. }
  1579. DnsPrint_RawOctets(
  1580. PrintRoutine,
  1581. pContext,
  1582. "\t\tSignature:",
  1583. "\t\t ", // line header
  1584. pdata,
  1585. sigLength );
  1586. pdata += sigLength;
  1587. if ( pdata + sizeof(DWORD) > pdataStop )
  1588. {
  1589. break;
  1590. }
  1591. wOriginalId = InlineFlipUnalignedWord( pdata );
  1592. pdata += sizeof(WORD);
  1593. extRcode = InlineFlipUnalignedWord( pdata );
  1594. pdata += sizeof(WORD);
  1595. otherLength = InlineFlipUnalignedWord( pdata );
  1596. pdata += sizeof(WORD);
  1597. PrintRoutine(
  1598. pContext,
  1599. "\r\n"
  1600. "\t\tOriginal XID = %x\r\n"
  1601. "\t\tExtended RCODE = %u\r\n"
  1602. "\t\tOther Length = %u\r\n",
  1603. wOriginalId,
  1604. extRcode,
  1605. otherLength );
  1606. if ( pdata + otherLength > pdataStop )
  1607. {
  1608. PrintRoutine(
  1609. pContext,
  1610. "Invalid other data length: exceeds record data!\r\n" );
  1611. break;
  1612. }
  1613. DnsPrint_RawOctets(
  1614. PrintRoutine,
  1615. pContext,
  1616. "\t\tOther Data:",
  1617. "\t\t ", // line header
  1618. pdata,
  1619. otherLength );
  1620. break;
  1621. }
  1622. case DNS_TYPE_WINS:
  1623. {
  1624. DWORD i;
  1625. DWORD winsFlags;
  1626. DWORD lookupTimeout;
  1627. DWORD cacheTimeout;
  1628. DWORD winsCount;
  1629. CHAR flagString[ WINS_FLAG_MAX_LENGTH ];
  1630. //
  1631. // WINS
  1632. // - scope/domain mapping flag
  1633. // - lookup timeout
  1634. // - cache timeout
  1635. // - WINS server count
  1636. // - WINS server list
  1637. //
  1638. winsFlags = FlipUnalignedDword( pdata );
  1639. pdata += sizeof(DWORD);
  1640. lookupTimeout = FlipUnalignedDword( pdata );
  1641. pdata += sizeof(DWORD);
  1642. cacheTimeout = FlipUnalignedDword( pdata );
  1643. pdata += sizeof(DWORD);
  1644. winsCount = FlipUnalignedDword( pdata );
  1645. pdata += sizeof(DWORD);
  1646. Dns_WinsRecordFlagString(
  1647. winsFlags,
  1648. flagString );
  1649. PrintRoutine(
  1650. pContext,
  1651. "\r\n"
  1652. "\t\tWINS flags = %s (%08x)\r\n"
  1653. "\t\tLookup timeout = %d\r\n"
  1654. "\t\tCaching TTL = %d\r\n",
  1655. flagString,
  1656. winsFlags,
  1657. lookupTimeout,
  1658. cacheTimeout );
  1659. if ( pdata + (winsCount * SIZEOF_IP_ADDRESS) > pdataStop )
  1660. {
  1661. PrintRoutine(
  1662. pContext,
  1663. "ERROR: WINS server count leads beyond record data length!\n"
  1664. "\tpmsg = %p\n"
  1665. "\tpmsgEnd = %p\n"
  1666. "\tpRR = %p\n"
  1667. "\trecord data end = %p\n"
  1668. "\twins count = %d\n"
  1669. "\tend of wins IPs = %p\n",
  1670. pMsgHead,
  1671. pMsgEnd,
  1672. pMsgRR,
  1673. pdataStop,
  1674. winsCount,
  1675. pdata + (winsCount * SIZEOF_IP_ADDRESS)
  1676. );
  1677. goto Done;
  1678. }
  1679. DnsPrint_IpAddressArray(
  1680. PrintRoutine,
  1681. pContext,
  1682. NULL,
  1683. "\tWINS",
  1684. winsCount,
  1685. (PIP_ADDRESS) pdata );
  1686. break;
  1687. }
  1688. case DNS_TYPE_WINSR:
  1689. {
  1690. DWORD winsFlags;
  1691. DWORD lookupTimeout;
  1692. DWORD cacheTimeout;
  1693. CHAR flagString[ WINS_FLAG_MAX_LENGTH ];
  1694. //
  1695. // NBSTAT
  1696. // - scope/domain mapping flag
  1697. // - lookup timeout
  1698. // - cache timeout
  1699. // - result domain -- optional
  1700. //
  1701. winsFlags = FlipUnalignedDword( pdata );
  1702. pdata += sizeof(DWORD);
  1703. lookupTimeout = FlipUnalignedDword( pdata );
  1704. pdata += sizeof(DWORD);
  1705. cacheTimeout = FlipUnalignedDword( pdata );
  1706. pdata += sizeof(DWORD);
  1707. Dns_WinsRecordFlagString(
  1708. winsFlags,
  1709. flagString );
  1710. PrintRoutine(
  1711. pContext,
  1712. "\r\n"
  1713. "\t\tWINS-R flags = %s (%08x)\r\n"
  1714. "\t\tLookup timeout = %d\r\n"
  1715. "\t\tCaching TTL = %d\r\n",
  1716. flagString,
  1717. winsFlags,
  1718. lookupTimeout,
  1719. cacheTimeout );
  1720. DnsPrint_PacketName(
  1721. PrintRoutine,
  1722. pContext,
  1723. "\t\tResult domain = ",
  1724. pdata,
  1725. pMsgHead,
  1726. pMsgEnd,
  1727. "\r\n" );
  1728. break;
  1729. }
  1730. case DNS_TYPE_KEY:
  1731. {
  1732. WORD flags;
  1733. BYTE protocol;
  1734. BYTE algorithm;
  1735. INT keyLength;
  1736. CHAR szKeyFlags[ 100 ];
  1737. keyLength = dlen - SIZEOF_KEY_FIXED_DATA;
  1738. flags = FlipUnalignedWord( pdata );
  1739. pdata += sizeof( WORD );
  1740. protocol = * ( PBYTE ) pdata;
  1741. ++pdata;
  1742. algorithm = * ( PBYTE ) pdata;
  1743. ++pdata;
  1744. PrintRoutine(
  1745. pContext,
  1746. "\r\n"
  1747. "\t\tKEY flags = 0x%04x %s\r\n"
  1748. "\t\tKEY protocol = %s (%d)\r\n"
  1749. "\t\tKEY algorithm = %s (%d)\r\n",
  1750. (INT) flags,
  1751. Dns_KeyFlagString( szKeyFlags, flags ),
  1752. Dns_GetKeyProtocolString( protocol ),
  1753. (INT) protocol,
  1754. Dns_GetDnssecAlgorithmString( algorithm ),
  1755. (INT) algorithm );
  1756. DnsPrint_RawOctets(
  1757. PrintRoutine,
  1758. pContext,
  1759. "\t\tPublic key:",
  1760. "\t\t ", // line header
  1761. pdata,
  1762. keyLength );
  1763. break;
  1764. }
  1765. case DNS_TYPE_SIG:
  1766. {
  1767. WORD typeCovered;
  1768. BYTE algorithm;
  1769. BYTE labelCount;
  1770. DWORD originalTTL;
  1771. DWORD sigInception;
  1772. DWORD sigExpiration;
  1773. WORD keyTag;
  1774. CHAR szSigInception[ 100 ];
  1775. CHAR szSigExpiration[ 100 ];
  1776. INT sigLength;
  1777. typeCovered = FlipUnalignedWord( pdata );
  1778. pdata += sizeof( WORD );
  1779. algorithm = * ( PBYTE ) pdata;
  1780. ++pdata;
  1781. labelCount = * ( PBYTE ) pdata;
  1782. ++pdata;
  1783. originalTTL = FlipUnalignedDword( pdata );
  1784. pdata += sizeof( DWORD );
  1785. sigExpiration = FlipUnalignedDword( pdata );
  1786. pdata += sizeof( DWORD );
  1787. sigInception = FlipUnalignedDword( pdata );
  1788. pdata += sizeof( DWORD );
  1789. keyTag = FlipUnalignedWord( pdata );
  1790. pdata += sizeof( WORD );
  1791. PrintRoutine(
  1792. pContext,
  1793. "\r\n"
  1794. "\t\tSIG type covered = %s\r\n"
  1795. "\t\tSIG algorithm = %s (%d)\r\n"
  1796. "\t\tSIG label count = %d\r\n"
  1797. "\t\tSIG original TTL = %d\r\n"
  1798. "\t\tSIG expiration = %s\r\n"
  1799. "\t\tSIG inception = %s\r\n"
  1800. "\t\tSIG key tag = %d\r\n",
  1801. Dns_RecordStringForType( typeCovered ),
  1802. Dns_GetDnssecAlgorithmString( ( BYTE ) algorithm ),
  1803. ( INT ) algorithm,
  1804. ( INT ) labelCount,
  1805. ( INT ) originalTTL,
  1806. Dns_SigTimeString( sigExpiration, szSigExpiration ),
  1807. Dns_SigTimeString( sigInception, szSigInception ),
  1808. ( INT ) keyTag );
  1809. pdata += DnsPrint_PacketName(
  1810. PrintRoutine,
  1811. pContext,
  1812. "\t\tSIG signer's name = ",
  1813. pdata,
  1814. pMsgHead,
  1815. pMsgEnd,
  1816. "\r\n" );
  1817. sigLength = ( INT ) ( pdataStop - pdata );
  1818. DnsPrint_RawOctets(
  1819. PrintRoutine,
  1820. pContext,
  1821. "\t\tSignature:",
  1822. "\t\t ", // line header
  1823. pdata,
  1824. sigLength );
  1825. break;
  1826. }
  1827. case DNS_TYPE_NXT:
  1828. {
  1829. INT bitmapLength;
  1830. INT byteIdx;
  1831. INT bitIdx;
  1832. pdata += DnsPrint_PacketName(
  1833. PrintRoutine,
  1834. pContext,
  1835. "\r\n\t\tNXT next name = ",
  1836. pdata,
  1837. pMsgHead,
  1838. pMsgEnd,
  1839. "\r\n" );
  1840. bitmapLength = ( INT ) ( pdataStop - pdata );
  1841. PrintRoutine( pContext, "\t\tNXT types covered = " );
  1842. for ( byteIdx = 0; byteIdx < bitmapLength; ++byteIdx )
  1843. {
  1844. for ( bitIdx = ( byteIdx ? 0 : 1 ); bitIdx < 8; ++bitIdx )
  1845. {
  1846. PCHAR pszType;
  1847. if ( !( pdata[ byteIdx ] & ( 1 << bitIdx ) ) )
  1848. {
  1849. continue; // Bit value is zero - do not write string.
  1850. }
  1851. pszType = Dns_RecordStringForType( byteIdx * 8 + bitIdx );
  1852. if ( !pszType )
  1853. {
  1854. ASSERT( FALSE );
  1855. continue; // This type has no string - do not write.
  1856. }
  1857. PrintRoutine( pContext, "%s ", pszType );
  1858. }
  1859. }
  1860. PrintRoutine( pContext, "\r\n" );
  1861. break;
  1862. }
  1863. default:
  1864. PrintRoutine(
  1865. pContext,
  1866. "Unknown resource record type %d at %p.\r\n",
  1867. type,
  1868. pMsgRR );
  1869. DnsPrint_RawOctets(
  1870. PrintRoutine,
  1871. pContext,
  1872. NULL,
  1873. "\t\t",
  1874. pdata,
  1875. dlen );
  1876. break;
  1877. }
  1878. Done:
  1879. DnsPrint_Unlock();
  1880. return( sizeof(DNS_WIRE_RECORD) + dlen );
  1881. }
  1882. //
  1883. // Print related utilities
  1884. //
  1885. INT
  1886. Dns_WriteFormattedSystemTimeToBuffer(
  1887. OUT PCHAR pBuffer,
  1888. IN PSYSTEMTIME pSystemTime
  1889. )
  1890. /*++
  1891. Routine Description:
  1892. Write SYSTEMTIME structure to buffer.
  1893. Arguments:
  1894. pBuffer -- buffer to write into, assumed to have at least 50
  1895. bytes available
  1896. pSystemTime -- system time to convert; assumed to be local, no
  1897. time zone conversion is done
  1898. Return Value:
  1899. Bytes in formatted string.
  1900. --*/
  1901. {
  1902. PCHAR pend = pBuffer + 60;
  1903. PCHAR pstart = pBuffer;
  1904. INT count;
  1905. pBuffer += GetDateFormat(
  1906. LOCALE_SYSTEM_DEFAULT,
  1907. LOCALE_NOUSEROVERRIDE,
  1908. (PSYSTEMTIME) pSystemTime,
  1909. NULL,
  1910. pBuffer,
  1911. (int)(pend - pBuffer) );
  1912. // Replace NULL from GetDateFormat with a space.
  1913. *( pBuffer - 1 ) = ' ';
  1914. pBuffer += GetTimeFormat(
  1915. LOCALE_SYSTEM_DEFAULT,
  1916. LOCALE_NOUSEROVERRIDE,
  1917. (PSYSTEMTIME) pSystemTime,
  1918. NULL,
  1919. pBuffer,
  1920. (int)(pend - pBuffer) );
  1921. if ( pBuffer <= pstart+1 )
  1922. {
  1923. return( 0 );
  1924. }
  1925. return (INT)( pBuffer - pstart );
  1926. }
  1927. //
  1928. // Response code print
  1929. //
  1930. #define DNS_RCODE_UNKNOWN (DNS_RCODE_BADTIME + 1)
  1931. PCHAR ResponseCodeStringTable[] =
  1932. {
  1933. "NOERROR",
  1934. "FORMERR",
  1935. "SERVFAIL",
  1936. "NXDOMAIN",
  1937. "NOTIMP",
  1938. "REFUSED",
  1939. "YXDOMAIN",
  1940. "YXRRSET",
  1941. "NXRRSET",
  1942. "NOTAUTH",
  1943. "NOTZONE",
  1944. "11 - unknown\r\n",
  1945. "12 - unknown\r\n",
  1946. "13 - unknown\r\n",
  1947. "14 - unknown\r\n",
  1948. "15 - unknown\r\n",
  1949. // DNS RCODEs stop at 15 -- these extended errors are available for security
  1950. "BADSIG",
  1951. "BADKEY",
  1952. "BADTIME",
  1953. "UNKNOWN"
  1954. };
  1955. PCHAR
  1956. Dns_ResponseCodeString(
  1957. IN INT ResponseCode
  1958. )
  1959. /*++
  1960. Routine Description:
  1961. Get string corresponding to a response code.
  1962. Arguments:
  1963. ResponseCode - response code
  1964. Return Value:
  1965. Ptr to string for code.
  1966. --*/
  1967. {
  1968. if ( ResponseCode > DNS_RCODE_UNKNOWN )
  1969. {
  1970. ResponseCode = DNS_RCODE_UNKNOWN;
  1971. }
  1972. return( ResponseCodeStringTable[ ResponseCode ] );
  1973. }
  1974. //
  1975. // More detailed RCODE strings
  1976. //
  1977. PCHAR ResponseCodeExplanationStringTable[] =
  1978. {
  1979. "NOERROR: no error",
  1980. "FORMERR: format error",
  1981. "SERVFAIL: server failure",
  1982. "NXDOMAIN: name error",
  1983. "NOTIMP: not implemented",
  1984. "REFUSED",
  1985. "YXDOMAIN: name exists that should not",
  1986. "YXRRSET: RR set exists that should not",
  1987. "NXRRSET: required RR set does not exist",
  1988. "NOTAUTH: not authoritative",
  1989. "NOTZONE: name not in zone",
  1990. "11 - unknown",
  1991. "12 - unknown",
  1992. "13 - unknown",
  1993. "14 - unknown",
  1994. "15 - unknown",
  1995. // DNS RCODEs stop at 15 -- these extended errors are available for security
  1996. "BADSIG: bad signature",
  1997. "BADKEY: bad signature",
  1998. "BADTIME: invalid or expired time on signature or key",
  1999. "UNKNOWN"
  2000. };
  2001. PCHAR
  2002. Dns_ResponseCodeExplanationString(
  2003. IN INT ResponseCode
  2004. )
  2005. /*++
  2006. Routine Description:
  2007. Get string corresponding to a response code.
  2008. Basically for use by packet debug routine above.
  2009. Arguments:
  2010. ResponseCode - response code
  2011. Return Value:
  2012. Ptr to string for code.
  2013. --*/
  2014. {
  2015. if ( ResponseCode > DNS_RCODE_UNKNOWN )
  2016. {
  2017. ResponseCode = DNS_RCODE_UNKNOWN;
  2018. }
  2019. return( ResponseCodeExplanationStringTable[ ResponseCode ] );
  2020. }
  2021. PCHAR
  2022. Dns_KeyFlagString(
  2023. IN OUT PCHAR pszBuff,
  2024. IN WORD Flags
  2025. )
  2026. /*++
  2027. Routine Description:
  2028. Formats a human-readable string based on the flags value
  2029. (DNSSEC KEY RR flags). See RFC2535 section 3.2.1.
  2030. Arguments:
  2031. pszBuff - buffer to dump string into should be min 100 chars
  2032. flags - flag value to generate string for
  2033. Return Value:
  2034. pszBuff
  2035. --*/
  2036. {
  2037. BOOL fZoneKey = FALSE;
  2038. *pszBuff = '\0';
  2039. // "type" bits
  2040. if ( ( Flags & 0xC000 ) == 0xC000 )
  2041. {
  2042. strcat( pszBuff, "NOKEY " );
  2043. }
  2044. else if ( ( Flags & 0xC000 ) == 0x8000 )
  2045. {
  2046. strcat( pszBuff, "NOAUTH " );
  2047. }
  2048. else if ( ( Flags & 0xC000 ) == 0x4000 )
  2049. {
  2050. strcat( pszBuff, "NOCONF " );
  2051. }
  2052. else
  2053. {
  2054. strcat( pszBuff, "NOAUTH NOCONF " );
  2055. }
  2056. // extended bit
  2057. if ( Flags & 0x1000 )
  2058. {
  2059. strcat( pszBuff, "EXTEND " );
  2060. }
  2061. // name type bits
  2062. if ( ( Flags & 0x0300 ) == 0x0300 )
  2063. {
  2064. strcat( pszBuff, "RESNT " ); // reserved name type
  2065. }
  2066. else if ( ( Flags & 0x0200 ) == 0x0100 )
  2067. {
  2068. strcat( pszBuff, "ENTITY " );
  2069. }
  2070. else if ( ( Flags & 0x0100 ) == 0x4000 )
  2071. {
  2072. strcat( pszBuff, "ZONE " );
  2073. fZoneKey = TRUE;
  2074. }
  2075. else
  2076. {
  2077. strcat( pszBuff, "USER " );
  2078. }
  2079. // signatory bits
  2080. if ( fZoneKey )
  2081. {
  2082. strcat( pszBuff, ( Flags & 0x0008 ) ? "MODEA " : "MODEB " );
  2083. if ( Flags & 0x0004 )
  2084. {
  2085. strcat( pszBuff, "STRONG " );
  2086. }
  2087. if ( Flags & 0x0002 )
  2088. {
  2089. strcat( pszBuff, "UNIQ " );
  2090. }
  2091. }
  2092. else
  2093. {
  2094. if ( Flags & 0x0008 )
  2095. {
  2096. strcat( pszBuff, "ZCTRL " );
  2097. }
  2098. if ( Flags & 0x0004 )
  2099. {
  2100. strcat( pszBuff, "STRONG " );
  2101. }
  2102. if ( Flags & 0x0002 )
  2103. {
  2104. strcat( pszBuff, "UNIQ " );
  2105. }
  2106. }
  2107. return pszBuff;
  2108. }
  2109. //
  2110. // Opcode print
  2111. //
  2112. PCHAR OpcodeStringTable[] =
  2113. {
  2114. "QUERY",
  2115. "IQUERY",
  2116. "SRV_STATUS",
  2117. "UNKNOWN",
  2118. "NOTIFY",
  2119. "UPDATE",
  2120. "UNKNOWN?"
  2121. };
  2122. CHAR OpcodeCharacterTable[] =
  2123. {
  2124. 'Q',
  2125. 'I',
  2126. 'S',
  2127. 'K',
  2128. 'N',
  2129. 'U',
  2130. '?'
  2131. };
  2132. #define DNS_OPCODE_UNSPEC (DNS_OPCODE_UPDATE + 1)
  2133. PCHAR
  2134. Dns_OpcodeString(
  2135. IN INT Opcode
  2136. )
  2137. /*++
  2138. Routine Description:
  2139. Get string corresponding to a response code.
  2140. Arguments:
  2141. Opcode - response code
  2142. Return Value:
  2143. Ptr to string for code.
  2144. --*/
  2145. {
  2146. if ( Opcode > DNS_OPCODE_UNSPEC )
  2147. {
  2148. Opcode = DNS_OPCODE_UNSPEC;
  2149. }
  2150. return( OpcodeStringTable[ Opcode ] );
  2151. }
  2152. CHAR
  2153. Dns_OpcodeCharacter(
  2154. IN INT Opcode
  2155. )
  2156. /*++
  2157. Routine Description:
  2158. Get string corresponding to an opcode.
  2159. Arguments:
  2160. Opcode - response code
  2161. Return Value:
  2162. Ptr to string for code.
  2163. --*/
  2164. {
  2165. if ( Opcode > DNS_OPCODE_UNSPEC )
  2166. {
  2167. Opcode = DNS_OPCODE_UNSPEC;
  2168. }
  2169. return( OpcodeCharacterTable[ Opcode ] );
  2170. }
  2171. //
  2172. // Section names
  2173. //
  2174. // With update get a new set of section names.
  2175. // Provide single interface to putting a name on them.
  2176. //
  2177. PSTR SectionNameArray[5] =
  2178. {
  2179. "Question",
  2180. "Answer",
  2181. "Authority",
  2182. "Additional",
  2183. "ERROR: Invalid Section"
  2184. };
  2185. PSTR UpdateSectionNameArray[5] =
  2186. {
  2187. "Zone",
  2188. "Prerequisite",
  2189. "Update",
  2190. "Additional",
  2191. "ERROR: Invalid Section"
  2192. };
  2193. PCHAR
  2194. Dns_SectionNameString(
  2195. IN INT iSection,
  2196. IN INT iOpcode
  2197. )
  2198. /*++
  2199. Routine Description:
  2200. Get string corresponding to name of RR section id.
  2201. For use by packet debug routine above.
  2202. Arguments:
  2203. iSection - section id (0-3 for Question-Additional)
  2204. iOpcode - opcode
  2205. Return Value:
  2206. Ptr to string for section name.
  2207. --*/
  2208. {
  2209. if ( iSection >= 4 )
  2210. {
  2211. iSection = 4;
  2212. }
  2213. if ( iOpcode == DNS_OPCODE_UPDATE )
  2214. {
  2215. return( UpdateSectionNameArray[iSection] );
  2216. }
  2217. else
  2218. {
  2219. return( SectionNameArray[iSection] );
  2220. }
  2221. }
  2222. VOID
  2223. DnsPrint_MessageNoContext(
  2224. IN PRINT_ROUTINE PrintRoutine,
  2225. IN OUT PPRINT_CONTEXT pContext,
  2226. IN PSTR pszHeader,
  2227. IN PDNS_HEADER pMsgHead,
  2228. IN WORD wLength OPTIONAL
  2229. )
  2230. /*++
  2231. Routine Description:
  2232. Print DNS message buffer.
  2233. Includes context information as well as actual DNS message.
  2234. --*/
  2235. {
  2236. PCHAR pchRecord;
  2237. PBYTE pmsgEnd;
  2238. INT i;
  2239. INT isection;
  2240. INT cchName;
  2241. WORD wOffset;
  2242. WORD wXid;
  2243. WORD wQuestionCount;
  2244. WORD wAnswerCount;
  2245. WORD wNameServerCount;
  2246. WORD wAdditionalCount;
  2247. WORD countSectionRR;
  2248. BOOL fFlipped = FALSE;
  2249. //
  2250. // processing limits
  2251. // - if length given set stop limit
  2252. // - if length not given set wLength so checks against
  2253. // length overrun always fail (are ok)
  2254. //
  2255. if ( wLength )
  2256. {
  2257. pmsgEnd = ((PBYTE)pMsgHead) + wLength;
  2258. }
  2259. else
  2260. {
  2261. wLength = MAXWORD;
  2262. pmsgEnd = NULL;
  2263. }
  2264. DnsPrint_Lock();
  2265. if ( pszHeader )
  2266. {
  2267. PrintRoutine( pContext, "%s\r\n", pszHeader );
  2268. }
  2269. PrintRoutine(
  2270. pContext,
  2271. "DNS message header at %p\r\n",
  2272. pMsgHead );
  2273. PrintRoutine(
  2274. pContext,
  2275. " XID 0x%04hx\r\n"
  2276. " Flags 0x%04hx\r\n"
  2277. " QR 0x%lx (%s)\r\n"
  2278. " OPCODE 0x%lx (%s)\r\n"
  2279. " AA 0x%lx\r\n"
  2280. " TC 0x%lx\r\n"
  2281. " RD 0x%lx\r\n"
  2282. " RA 0x%lx\r\n"
  2283. " Z 0x%lx\r\n"
  2284. " RCODE 0x%lx (%s)\r\n"
  2285. " QCOUNT 0x%hx\r\n"
  2286. " ACOUNT 0x%hx\r\n"
  2287. " NSCOUNT 0x%hx\r\n"
  2288. " ARCOUNT 0x%hx\r\n",
  2289. pMsgHead->Xid,
  2290. ntohs((*((PWORD)pMsgHead + 1))),
  2291. pMsgHead->IsResponse,
  2292. (pMsgHead->IsResponse ? "response" : "question"),
  2293. pMsgHead->Opcode,
  2294. Dns_OpcodeString( pMsgHead->Opcode ),
  2295. pMsgHead->Authoritative,
  2296. pMsgHead->Truncation,
  2297. pMsgHead->RecursionDesired,
  2298. pMsgHead->RecursionAvailable,
  2299. pMsgHead->Reserved,
  2300. pMsgHead->ResponseCode,
  2301. Dns_ResponseCodeString( pMsgHead->ResponseCode ),
  2302. pMsgHead->QuestionCount,
  2303. pMsgHead->AnswerCount,
  2304. pMsgHead->NameServerCount,
  2305. pMsgHead->AdditionalCount );
  2306. //
  2307. // determine if byte flipped and get correct count
  2308. //
  2309. wXid = pMsgHead->Xid;
  2310. wQuestionCount = pMsgHead->QuestionCount;
  2311. wAnswerCount = pMsgHead->AnswerCount;
  2312. wNameServerCount = pMsgHead->NameServerCount;
  2313. wAdditionalCount = pMsgHead->AdditionalCount;
  2314. if ( wQuestionCount )
  2315. {
  2316. fFlipped = wQuestionCount & 0xff00;
  2317. }
  2318. else if ( wNameServerCount )
  2319. {
  2320. fFlipped = wNameServerCount & 0xff00;
  2321. }
  2322. if ( fFlipped )
  2323. {
  2324. wXid = ntohs( wXid );
  2325. wQuestionCount = ntohs( wQuestionCount );
  2326. wAnswerCount = ntohs( wAnswerCount );
  2327. wNameServerCount = ntohs( wNameServerCount );
  2328. wAdditionalCount = ntohs( wAdditionalCount );
  2329. }
  2330. //
  2331. // catch record flipping problems -- all are flipped or none at all
  2332. // and no record count should be > 256 EXCEPT answer count
  2333. // during FAST zone transfer
  2334. //
  2335. DNS_ASSERT( ! (wQuestionCount & 0xff00) );
  2336. DNS_ASSERT( ! (wNameServerCount & 0xff00) );
  2337. DNS_ASSERT( ! (wAdditionalCount & 0xff00) );
  2338. #if 0
  2339. //
  2340. // stop here if WINS response -- don't have parsing ready
  2341. //
  2342. if ( pMsgHead->IsResponse && IS_WINS_XID(wXid) )
  2343. {
  2344. PrintRoutine( pContext, " WINS Response packet.\r\n\r\n" );
  2345. goto Unlock;
  2346. }
  2347. #endif
  2348. //
  2349. // print questions and resource records
  2350. //
  2351. pchRecord = (PCHAR)(pMsgHead + 1);
  2352. for ( isection=0; isection<4; isection++)
  2353. {
  2354. PrintRoutine(
  2355. pContext,
  2356. " %s Section:\r\n",
  2357. Dns_SectionNameString( isection, pMsgHead->Opcode ) );
  2358. if ( isection==0 )
  2359. {
  2360. countSectionRR = wQuestionCount;
  2361. }
  2362. else if ( isection==1 )
  2363. {
  2364. countSectionRR = wAnswerCount;
  2365. }
  2366. else if ( isection==2 )
  2367. {
  2368. countSectionRR = wNameServerCount;
  2369. }
  2370. else if ( isection==3 )
  2371. {
  2372. countSectionRR = wAdditionalCount;
  2373. }
  2374. for ( i=0; i < countSectionRR; i++ )
  2375. {
  2376. //
  2377. // verify not overrunning length
  2378. // - check against pCurrent as well as message length
  2379. // so can print packets while being built
  2380. //
  2381. wOffset = (WORD)(pchRecord - (PCHAR)pMsgHead);
  2382. if ( wOffset >= wLength )
  2383. {
  2384. PrintRoutine(
  2385. pContext,
  2386. "ERROR: BOGUS PACKET:\r\n"
  2387. "\tFollowing RR (offset %d) past packet length (%d).\r\n",
  2388. wOffset,
  2389. wLength
  2390. );
  2391. goto Unlock;
  2392. }
  2393. //
  2394. // print RR name
  2395. //
  2396. PrintRoutine(
  2397. pContext,
  2398. " Name Offset = 0x%04x\r\n",
  2399. wOffset
  2400. );
  2401. cchName = DnsPrint_PacketName(
  2402. PrintRoutine,
  2403. pContext,
  2404. " Name \"",
  2405. pchRecord,
  2406. pMsgHead,
  2407. pmsgEnd,
  2408. "\"\r\n" );
  2409. if ( !cchName )
  2410. {
  2411. PrintRoutine(
  2412. pContext,
  2413. "ERROR: Invalid name length, stop packet print\r\n" );
  2414. DNS_ASSERT( FALSE );
  2415. break;
  2416. }
  2417. pchRecord += cchName;
  2418. // print question or resource record
  2419. if ( isection == 0 )
  2420. {
  2421. PrintRoutine(
  2422. pContext,
  2423. " QTYPE %d\r\n"
  2424. " QCLASS %d\r\n",
  2425. FlipUnalignedWord( pchRecord ),
  2426. FlipUnalignedWord( pchRecord + sizeof(WORD) )
  2427. );
  2428. pchRecord += sizeof( DNS_WIRE_QUESTION );
  2429. }
  2430. else
  2431. {
  2432. pchRecord += DnsPrint_PacketRecord(
  2433. PrintRoutine,
  2434. pContext,
  2435. NULL,
  2436. (PDNS_WIRE_RECORD) pchRecord,
  2437. pMsgHead,
  2438. pmsgEnd
  2439. );
  2440. }
  2441. }
  2442. }
  2443. // check that at proper end of packet
  2444. wOffset = (WORD)(pchRecord - (PCHAR)pMsgHead);
  2445. PrintRoutine(
  2446. pContext,
  2447. " Message length = %04x\r\n\r\n",
  2448. wOffset );
  2449. // print warning if given message length and did not end up
  2450. // at end of message
  2451. // note: pmsgEnd test in case passed wLength==0, in which case
  2452. // wLength set to MAXDWORD above
  2453. if ( pmsgEnd && wOffset < wLength )
  2454. {
  2455. PrintRoutine(
  2456. pContext,
  2457. "WARNING: message continues beyond these records\r\n"
  2458. "\tpch = %p\r\n"
  2459. "\toffset = %d, msg length = %d, %d bytes\r\n",
  2460. pchRecord,
  2461. wOffset,
  2462. wLength,
  2463. wLength - wOffset );
  2464. DnsPrint_RawOctets(
  2465. PrintRoutine,
  2466. pContext,
  2467. "Remaining bytes:",
  2468. NULL,
  2469. pchRecord,
  2470. (wLength - wOffset) );
  2471. }
  2472. Unlock:
  2473. DnsPrint_Unlock();
  2474. } // DnsPrint_MessageNoContext
  2475. DWORD
  2476. DnsStringPrint_Guid(
  2477. OUT PCHAR pBuffer,
  2478. IN PGUID pGuid
  2479. )
  2480. /*++
  2481. Routine Description:
  2482. Print GUID to buffer.
  2483. Arguments:
  2484. pBuffer - buffer to print to
  2485. buffer must be big enough for GUID string
  2486. GUID_STRING_BUFFER_LENGTH covers it
  2487. pGuid - GUID to print
  2488. Return Value:
  2489. Count of bytes printed to string.
  2490. --*/
  2491. {
  2492. if ( !pGuid )
  2493. {
  2494. *pBuffer = 0;
  2495. return 0;
  2496. }
  2497. return sprintf(
  2498. pBuffer,
  2499. "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
  2500. pGuid->Data1,
  2501. pGuid->Data2,
  2502. pGuid->Data3,
  2503. *(PWORD) &pGuid->Data4[0],
  2504. pGuid->Data4[2],
  2505. pGuid->Data4[3],
  2506. pGuid->Data4[4],
  2507. pGuid->Data4[5],
  2508. pGuid->Data4[6],
  2509. pGuid->Data4[7],
  2510. pGuid->Data4[8] );
  2511. }
  2512. VOID
  2513. DnsPrint_Guid(
  2514. IN PRINT_ROUTINE PrintRoutine,
  2515. IN OUT PPRINT_CONTEXT pContext,
  2516. IN PSTR pszHeader,
  2517. IN PGUID pGuid
  2518. )
  2519. /*++
  2520. Routine Description:
  2521. Print GUID
  2522. Arguments:
  2523. pszHeader - Header message/name for RR.
  2524. pGuid -- ptr to GUID to print
  2525. Return Value:
  2526. None.
  2527. --*/
  2528. {
  2529. CHAR guidBuffer[ GUID_STRING_BUFFER_LENGTH ];
  2530. if ( !pszHeader )
  2531. {
  2532. pszHeader = "Guid";
  2533. }
  2534. if ( !pGuid )
  2535. {
  2536. PrintRoutine(
  2537. pContext,
  2538. "%s: NULL GUID pointer!\r\n",
  2539. pszHeader );
  2540. }
  2541. // convert GUID to string
  2542. DnsStringPrint_Guid(
  2543. guidBuffer,
  2544. pGuid );
  2545. PrintRoutine(
  2546. pContext,
  2547. "%s: (%p) %s\r\n",
  2548. pszHeader,
  2549. pGuid,
  2550. guidBuffer );
  2551. }
  2552. DWORD
  2553. DnsStringPrint_RawOctets(
  2554. OUT PCHAR pBuffer,
  2555. IN PCHAR pchData,
  2556. IN DWORD dwLength,
  2557. IN PSTR pszLineHeader,
  2558. IN DWORD dwLineLength
  2559. )
  2560. /*++
  2561. Routine Description:
  2562. Print raw octect data to sting
  2563. Arguments:
  2564. pBuffer - buffer to print to
  2565. pchData - data to print
  2566. dwLength - length of data to print
  2567. pszLineHeader - header on each line.
  2568. dwLineLength - number of bytes to print on line; default is
  2569. Return Value:
  2570. Count of bytes printed to string.
  2571. --*/
  2572. {
  2573. INT i;
  2574. INT lineCount = 0;
  2575. PCHAR pch = pBuffer;
  2576. *pch = 0;
  2577. //
  2578. // catch NULL pointer
  2579. // - return is null terminated
  2580. // - but indicate no bytes written
  2581. //
  2582. if ( !pchData )
  2583. {
  2584. return 0;
  2585. }
  2586. //
  2587. // write each byte in hex
  2588. // - if dwLineLength set break into lines with count
  2589. // or optional header
  2590. //
  2591. for ( i = 0; i < (INT)dwLength; i++ )
  2592. {
  2593. if ( dwLineLength && (i % dwLineLength) == 0 )
  2594. {
  2595. if ( pszLineHeader )
  2596. {
  2597. pch += sprintf( pch, "\r\n%s", pszLineHeader );
  2598. }
  2599. else
  2600. {
  2601. pch += sprintf( pch, "\r\n%3d> ", i );
  2602. }
  2603. lineCount++;
  2604. }
  2605. pch += sprintf( pch, "%02x ", (UCHAR)pchData[i] );
  2606. }
  2607. return( (DWORD)(pch - pBuffer) );
  2608. }
  2609. VOID
  2610. DnsPrint_RawBinary(
  2611. IN PRINT_ROUTINE PrintRoutine,
  2612. IN OUT PPRINT_CONTEXT pContext,
  2613. IN PSTR pszHeader,
  2614. IN PSTR pszLineHeader,
  2615. IN PCHAR pchData,
  2616. IN DWORD dwLength,
  2617. IN DWORD PrintSize
  2618. )
  2619. /*++
  2620. Routine Description:
  2621. Print raw data.
  2622. Arguments:
  2623. pszHeader - Header message/name for RR.
  2624. pszLineHeader - Header on each line.
  2625. pchData - data to print
  2626. dwLength - length of data to print
  2627. PrintSize - size to print in
  2628. size(QWORD)
  2629. size(DWORD)
  2630. size(WORD)
  2631. defaults to bytes
  2632. Return Value:
  2633. None.
  2634. --*/
  2635. {
  2636. DWORD i;
  2637. DWORD lineCount = 0;
  2638. CHAR buf[ 2000 ];
  2639. PCHAR pch = buf;
  2640. PCHAR pbyte;
  2641. PCHAR pend;
  2642. DnsPrint_Lock();
  2643. if ( pszHeader )
  2644. {
  2645. PrintRoutine(
  2646. pContext,
  2647. "%s",
  2648. pszHeader );
  2649. }
  2650. buf[0] = 0;
  2651. //
  2652. // print bytes
  2653. // - write 16 bytes a line
  2654. // - buffer up 10 lines for speed
  2655. //
  2656. // note: we'll write a partial (<16 byte) line the first
  2657. // time if data is unaligned with PrintSize, then we'll
  2658. // write at 16 a pop
  2659. //
  2660. if ( PrintSize == 0 )
  2661. {
  2662. PrintSize = 1;
  2663. }
  2664. i = 0;
  2665. pch = buf;
  2666. pend = (PBYTE)pchData + dwLength;
  2667. while ( i < dwLength )
  2668. {
  2669. DWORD lineBytes = (i%16);
  2670. if ( lineBytes==0 || lineBytes > (16-PrintSize) )
  2671. {
  2672. if ( lineCount > 10 )
  2673. {
  2674. PrintRoutine( pContext, buf );
  2675. lineCount = 0;
  2676. pch = buf;
  2677. }
  2678. if ( pszLineHeader )
  2679. {
  2680. pch += sprintf( pch, "\r\n%s", pszLineHeader );
  2681. }
  2682. else
  2683. {
  2684. pch += sprintf( pch, "\r\n\t%3d> ", i );
  2685. }
  2686. lineCount++;
  2687. //if ( i >= 128 && dlen > 256 )
  2688. //{
  2689. // PrintRoutine( pContext, "skipping remaining bytes ...\r\n" ));
  2690. //}
  2691. }
  2692. pbyte = &pchData[i];
  2693. if ( PrintSize == sizeof(QWORD) &&
  2694. POINTER_IS_ALIGNED( pbyte, ALIGN_QUAD ) &&
  2695. pbyte + sizeof(QWORD) <= pend )
  2696. {
  2697. pch += sprintf( pch, "%I64x ", *(PQWORD)pbyte );
  2698. i += sizeof(QWORD);
  2699. }
  2700. else if ( PrintSize == sizeof(DWORD) &&
  2701. POINTER_IS_ALIGNED( pbyte, ALIGN_DWORD ) &&
  2702. pbyte + sizeof(DWORD) <= pend )
  2703. {
  2704. pch += sprintf( pch, "%08x ", *(PDWORD)pbyte );
  2705. i += sizeof(DWORD);
  2706. }
  2707. else if ( PrintSize == sizeof(WORD) &&
  2708. POINTER_IS_ALIGNED( pbyte, ALIGN_WORD ) &&
  2709. pbyte + sizeof(WORD) <= pend )
  2710. {
  2711. pch += sprintf( pch, "%04x ", *(PWORD)pbyte );
  2712. i += sizeof(WORD);
  2713. }
  2714. else // default to byte print
  2715. {
  2716. pch += sprintf( pch, "%02x ", *pbyte );
  2717. i++;
  2718. }
  2719. }
  2720. // print remaining bytes in buffer
  2721. PrintRoutine(
  2722. pContext,
  2723. "%s\r\n",
  2724. buf );
  2725. DnsPrint_Unlock();
  2726. }
  2727. VOID
  2728. DnsPrint_RawOctets(
  2729. IN PRINT_ROUTINE PrintRoutine,
  2730. IN OUT PPRINT_CONTEXT pContext,
  2731. IN PSTR pszHeader,
  2732. IN PSTR pszLineHeader,
  2733. IN PCHAR pchData,
  2734. IN DWORD dwLength
  2735. )
  2736. /*++
  2737. Routine Description:
  2738. Print raw octect data.
  2739. Arguments:
  2740. pszHeader - Header message/name for RR.
  2741. pszLineHeader - Header on each line.
  2742. pchData - data to print
  2743. dwLength - length of data to print
  2744. Return Value:
  2745. None.
  2746. --*/
  2747. {
  2748. INT i;
  2749. INT lineCount = 0;
  2750. CHAR buf[ 2000 ];
  2751. PCHAR pch = buf;
  2752. DnsPrint_Lock();
  2753. if ( pszHeader )
  2754. {
  2755. PrintRoutine(
  2756. pContext,
  2757. "%s",
  2758. pszHeader );
  2759. }
  2760. buf[0] = 0;
  2761. // buffer every 20 lines for speed
  2762. for ( i = 0; i < (INT)dwLength; i++ )
  2763. {
  2764. if ( !(i%16) )
  2765. {
  2766. if ( lineCount > 10 )
  2767. {
  2768. PrintRoutine( pContext, buf );
  2769. lineCount = 0;
  2770. pch = buf;
  2771. }
  2772. if ( pszLineHeader )
  2773. {
  2774. pch += sprintf( pch, "\r\n%s", pszLineHeader );
  2775. }
  2776. else
  2777. {
  2778. pch += sprintf( pch, "\r\n%3d> ", i );
  2779. }
  2780. lineCount++;
  2781. //if ( i >= 128 && dlen > 256 )
  2782. //{
  2783. // PrintRoutine( pContext, "skipping remaining bytes ...\r\n" ));
  2784. //}
  2785. }
  2786. pch += sprintf( pch, "%02x ", (UCHAR)pchData[i] );
  2787. }
  2788. // print remaining bytes in buffer
  2789. PrintRoutine(
  2790. pContext,
  2791. "%s\r\n",
  2792. buf );
  2793. DnsPrint_Unlock();
  2794. }
  2795. VOID
  2796. DnsPrint_ParsedRecord(
  2797. IN PRINT_ROUTINE PrintRoutine,
  2798. IN OUT PPRINT_CONTEXT pContext,
  2799. IN PSTR pszHeader,
  2800. IN PDNS_PARSED_RR pParsedRR
  2801. )
  2802. /*++
  2803. Routine Description:
  2804. Print parsed RR structure.
  2805. Arguments:
  2806. pszHeader - Header message/name for RR.
  2807. pParsedRR - parsed RR to print
  2808. Return Value:
  2809. None.
  2810. --*/
  2811. {
  2812. if ( !pszHeader )
  2813. {
  2814. pszHeader = "Parsed RR:";
  2815. }
  2816. if ( !pParsedRR )
  2817. {
  2818. PrintRoutine(
  2819. pContext,
  2820. "%s %s\r\n",
  2821. pszHeader,
  2822. "NULL ParsedRR ptr." );
  2823. return;
  2824. }
  2825. PrintRoutine(
  2826. pContext,
  2827. "%s\r\n"
  2828. "\tpchName = %p\r\n"
  2829. "\tpchRR = %p\r\n"
  2830. "\tpchData = %p\r\n"
  2831. "\tpchNextRR = %p\r\n"
  2832. "\twType = %d\r\n"
  2833. "\twClass = %d\r\n"
  2834. "\tTTL = %d\r\n"
  2835. "\twDataLength = %d\r\n",
  2836. pszHeader,
  2837. pParsedRR->pchName,
  2838. pParsedRR->pchRR,
  2839. pParsedRR->pchData,
  2840. pParsedRR->pchNextRR,
  2841. pParsedRR->Type,
  2842. pParsedRR->Class,
  2843. pParsedRR->Ttl,
  2844. pParsedRR->DataLength
  2845. );
  2846. }
  2847. //
  2848. // Winsock RnR structures
  2849. //
  2850. VOID
  2851. DnsPrint_FdSet(
  2852. IN PRINT_ROUTINE PrintRoutine,
  2853. IN OUT PPRINT_CONTEXT pContext,
  2854. IN PSTR pszHeader,
  2855. IN struct fd_set * pfd_set
  2856. )
  2857. /*++
  2858. Routine Description:
  2859. Print sockets in FD_SET.
  2860. --*/
  2861. {
  2862. INT count;
  2863. INT i;
  2864. DNS_ASSERT( pfd_set );
  2865. count = (INT) pfd_set->fd_count;
  2866. DnsPrint_Lock();
  2867. PrintRoutine(
  2868. pContext,
  2869. "%s (count = %d)\r\n",
  2870. pszHeader ? pszHeader : "FD_SET:",
  2871. count );
  2872. for (i=0; i<count; i++)
  2873. {
  2874. PrintRoutine(
  2875. pContext,
  2876. "\tsocket[%d] = %d\r\n",
  2877. i,
  2878. pfd_set->fd_array[i] );
  2879. }
  2880. DnsPrint_Unlock();
  2881. }
  2882. VOID
  2883. DnsPrint_Sockaddr(
  2884. IN PRINT_ROUTINE PrintRoutine,
  2885. IN OUT PPRINT_CONTEXT pContext,
  2886. IN PSTR pszHeader,
  2887. IN DWORD Indent,
  2888. IN PSOCKADDR pSockaddr,
  2889. IN INT iSockaddrLength
  2890. )
  2891. /*++
  2892. Routine Description:
  2893. Print sockaddr structure and length used in call.
  2894. --*/
  2895. {
  2896. PSTR pindent = INDENT_STRING( Indent );
  2897. if ( !pszHeader )
  2898. {
  2899. pszHeader = "Sockaddr:";
  2900. }
  2901. if ( !pSockaddr )
  2902. {
  2903. PrintRoutine(
  2904. pContext,
  2905. "%s%s\tNULL Sockaddr passed to print.\r\n",
  2906. pindent,
  2907. pszHeader );
  2908. return;
  2909. }
  2910. DnsPrint_Lock();
  2911. PrintRoutine(
  2912. pContext,
  2913. "%s%s\r\n"
  2914. "%s\tpointer = %p\r\n"
  2915. "%s\tlength = %d\r\n"
  2916. "%s\tsa_family = %d\r\n",
  2917. pindent, pszHeader,
  2918. pindent, pSockaddr,
  2919. pindent, iSockaddrLength,
  2920. pindent, pSockaddr->sa_family
  2921. );
  2922. switch ( pSockaddr->sa_family )
  2923. {
  2924. case AF_INET:
  2925. {
  2926. PSOCKADDR_IN psin = (PSOCKADDR_IN) pSockaddr;
  2927. PrintRoutine(
  2928. pContext,
  2929. "%s\tsin_port = %04x\r\n"
  2930. "%s\tsin_addr = %s (%08x)\r\n"
  2931. "%s\tsin_zero = %08x %08x\r\n",
  2932. pindent, psin->sin_port,
  2933. pindent, inet_ntoa( psin->sin_addr ),
  2934. psin->sin_addr.s_addr,
  2935. pindent, *(PDWORD) &psin->sin_zero[0],
  2936. *(PDWORD) &psin->sin_zero[4]
  2937. );
  2938. break;
  2939. }
  2940. case AF_INET6:
  2941. {
  2942. PSOCKADDR_IN6 psin = (PSOCKADDR_IN6) pSockaddr;
  2943. CHAR buffer[ IP6_ADDRESS_STRING_BUFFER_LENGTH ];
  2944. Dns_Ip6AddressToString_A(
  2945. buffer,
  2946. (PIP6_ADDRESS) &psin->sin6_addr );
  2947. PrintRoutine(
  2948. pContext,
  2949. "%s\tsin6_port = %04x\r\n"
  2950. "%s\tsin6_flowinfo = %08x\r\n"
  2951. "%s\tsin6_addr = %s\r\n"
  2952. "%s\tsin6_scope_id = %08x\r\n",
  2953. pindent, psin->sin6_port,
  2954. pindent, psin->sin6_flowinfo,
  2955. pindent, buffer,
  2956. pindent, psin->sin6_scope_id
  2957. );
  2958. break;
  2959. }
  2960. default:
  2961. // print unknown in WORDs
  2962. // limit print as this is probably a busted sockaddr due to bug
  2963. {
  2964. DnsPrint_RawBinary(
  2965. PrintRoutine,
  2966. pContext,
  2967. "\tdata: ",
  2968. pindent, // line header
  2969. pSockaddr->sa_data,
  2970. iSockaddrLength < 100
  2971. ? iSockaddrLength
  2972. : 100,
  2973. sizeof(WORD)
  2974. );
  2975. break;
  2976. }
  2977. }
  2978. DnsPrint_Unlock();
  2979. }
  2980. VOID
  2981. DnsPrint_AddrInfo(
  2982. IN PRINT_ROUTINE PrintRoutine,
  2983. IN OUT PPRINT_CONTEXT pContext,
  2984. IN PSTR pszHeader,
  2985. IN DWORD Indent,
  2986. IN PADDRINFO pAddrInfo
  2987. )
  2988. /*++
  2989. Routine Description:
  2990. Print ADDRINFO structure.
  2991. --*/
  2992. {
  2993. PSTR pindent = INDENT_STRING( Indent );
  2994. if ( !pszHeader )
  2995. {
  2996. pszHeader = "AddrInfo:";
  2997. }
  2998. if ( !pAddrInfo )
  2999. {
  3000. PrintRoutine(
  3001. pContext,
  3002. "%s%s NULL AddrInfo.\r\n",
  3003. pindent,
  3004. pszHeader );
  3005. return;
  3006. }
  3007. DnsPrint_Lock();
  3008. PrintRoutine(
  3009. pContext,
  3010. "%s%s\n"
  3011. "%s\tPtr = %p\r\n"
  3012. "%s\tNext Ptr = %p\r\n"
  3013. "%s\tFlags = %08x\r\n"
  3014. "%s\tFamily = %d\r\n"
  3015. "%s\tSockType = %d\r\n"
  3016. "%s\tProtocol = %d\r\n"
  3017. "%s\tAddrLength = %d\r\n"
  3018. "%s\tName = %s\r\n",
  3019. pindent, pszHeader,
  3020. pindent, pAddrInfo,
  3021. pindent, pAddrInfo->ai_next,
  3022. pindent, pAddrInfo->ai_flags,
  3023. pindent, pAddrInfo->ai_family,
  3024. pindent, pAddrInfo->ai_socktype,
  3025. pindent, pAddrInfo->ai_protocol,
  3026. pindent, pAddrInfo->ai_addrlen,
  3027. pindent, pAddrInfo->ai_canonname
  3028. );
  3029. DnsPrint_Sockaddr(
  3030. PrintRoutine,
  3031. pContext,
  3032. NULL,
  3033. Indent + 1,
  3034. pAddrInfo->ai_addr,
  3035. pAddrInfo->ai_addrlen );
  3036. DnsPrint_Unlock();
  3037. }
  3038. VOID
  3039. DnsPrint_AddrInfoList(
  3040. IN PRINT_ROUTINE PrintRoutine,
  3041. IN OUT PPRINT_CONTEXT pContext,
  3042. IN PSTR pszHeader,
  3043. IN DWORD Indent,
  3044. IN PADDRINFO pAddrInfo
  3045. )
  3046. /*++
  3047. Routine Description:
  3048. Print ADDRINFO structure.
  3049. --*/
  3050. {
  3051. PADDRINFO paddr = pAddrInfo;
  3052. PSTR pindent = INDENT_STRING( Indent );
  3053. //
  3054. // list header
  3055. //
  3056. if ( !pszHeader )
  3057. {
  3058. pszHeader = "AddrInfo List:";
  3059. }
  3060. if ( !paddr )
  3061. {
  3062. PrintRoutine(
  3063. pContext,
  3064. "%s%s NULL AddrInfo List.\r\n",
  3065. pindent,
  3066. pszHeader );
  3067. return;
  3068. }
  3069. DnsPrint_Lock();
  3070. PrintRoutine(
  3071. pContext,
  3072. "%s%s\n",
  3073. pindent, pszHeader
  3074. );
  3075. //
  3076. // print each ADDRINFO in list
  3077. //
  3078. while ( paddr )
  3079. {
  3080. DnsPrint_AddrInfo(
  3081. PrintRoutine,
  3082. pContext,
  3083. NULL,
  3084. Indent,
  3085. paddr );
  3086. paddr = paddr->ai_next;
  3087. }
  3088. PrintRoutine(
  3089. pContext,
  3090. "End of AddrInfo list\n\n"
  3091. );
  3092. DnsPrint_Unlock();
  3093. }
  3094. VOID
  3095. DnsPrint_SocketAddress(
  3096. IN PRINT_ROUTINE PrintRoutine,
  3097. IN OUT PPRINT_CONTEXT pContext,
  3098. IN PSTR pszHeader,
  3099. IN DWORD Indent,
  3100. IN PSOCKET_ADDRESS pSocketAddress
  3101. )
  3102. /*++
  3103. Routine Description:
  3104. Print SOCKET_ADDRESS structure.
  3105. --*/
  3106. {
  3107. PSTR pindent = INDENT_STRING( Indent );
  3108. if ( !pszHeader )
  3109. {
  3110. pszHeader = "SocketAddress:";
  3111. }
  3112. if ( !pSocketAddress )
  3113. {
  3114. PrintRoutine(
  3115. pContext,
  3116. "%s%s NULL SocketAddress.\r\n",
  3117. pindent,
  3118. pszHeader );
  3119. return;
  3120. }
  3121. DnsPrint_Lock();
  3122. PrintRoutine(
  3123. pContext,
  3124. "%s%s\n"
  3125. "%s\tpSockaddr = %p\r\n"
  3126. "%s\tiSockaddrLength = %d\r\n",
  3127. pindent, pszHeader,
  3128. pindent, pSocketAddress->lpSockaddr,
  3129. pindent, pSocketAddress->iSockaddrLength );
  3130. DnsPrint_Sockaddr(
  3131. PrintRoutine,
  3132. pContext,
  3133. NULL,
  3134. Indent,
  3135. pSocketAddress->lpSockaddr,
  3136. pSocketAddress->iSockaddrLength );
  3137. DnsPrint_Unlock();
  3138. }
  3139. VOID
  3140. DnsPrint_CsAddr(
  3141. IN PRINT_ROUTINE PrintRoutine,
  3142. IN OUT PPRINT_CONTEXT pContext,
  3143. IN PSTR pszHeader,
  3144. IN DWORD Indent,
  3145. IN PCSADDR_INFO pCsAddr
  3146. )
  3147. /*++
  3148. Routine Description:
  3149. Print CSADDR_INFO structure.
  3150. Arguments:
  3151. PrintRoutine - routine to print with
  3152. pParam - ptr to print context
  3153. pszHeader - header
  3154. Indent - indent count, for formatting CSADDR inside larger struct
  3155. pCsAddr - ptr to CSADDRINFO to print
  3156. Return Value:
  3157. None.
  3158. --*/
  3159. {
  3160. PSTR pindent = INDENT_STRING( Indent );
  3161. if ( !pszHeader )
  3162. {
  3163. pszHeader = "CSAddrInfo:";
  3164. }
  3165. if ( !pCsAddr )
  3166. {
  3167. PrintRoutine(
  3168. pContext,
  3169. "%s%s \tNULL CSADDR_INFO ptr.\r\n",
  3170. pindent, pszHeader
  3171. );
  3172. return;
  3173. }
  3174. // print the struct
  3175. DnsPrint_Lock();
  3176. PrintRoutine(
  3177. pContext,
  3178. "%s%s\r\n"
  3179. "%s\tPtr = %p\n"
  3180. "%s\tSocketType = %d\n"
  3181. "%s\tProtocol = %d\n",
  3182. pindent, pszHeader,
  3183. pindent, pCsAddr,
  3184. pindent, pCsAddr->iSocketType,
  3185. pindent, pCsAddr->iProtocol
  3186. );
  3187. DnsPrint_SocketAddress(
  3188. PrintRoutine,
  3189. pContext,
  3190. "LocalAddress:",
  3191. Indent,
  3192. & pCsAddr->LocalAddr
  3193. );
  3194. DnsPrint_SocketAddress(
  3195. PrintRoutine,
  3196. pContext,
  3197. "RemoteAddress:",
  3198. Indent,
  3199. & pCsAddr->RemoteAddr
  3200. );
  3201. DnsPrint_Unlock();
  3202. }
  3203. VOID
  3204. DnsPrint_AfProtocolsArray(
  3205. IN PRINT_ROUTINE PrintRoutine,
  3206. IN OUT PPRINT_CONTEXT pContext,
  3207. IN PSTR pszHeader,
  3208. IN PAFPROTOCOLS pProtocolArray,
  3209. IN DWORD ProtocolCount
  3210. )
  3211. /*++
  3212. Routine Description:
  3213. Print AFPROTOCOLS array.
  3214. Arguments:
  3215. PrintRoutine - routine to print with
  3216. pszHeader - header
  3217. pProtocolArray - protocols array
  3218. ProtocolCount - array count
  3219. Return Value:
  3220. None.
  3221. --*/
  3222. {
  3223. DWORD i;
  3224. if ( !pszHeader )
  3225. {
  3226. pszHeader = "AFPROTOCOLS Array:";
  3227. }
  3228. // print
  3229. // - array + count
  3230. // - each protocol element
  3231. DnsPrint_Lock();
  3232. PrintRoutine(
  3233. pContext,
  3234. "%s\r\n"
  3235. "\tProtocol Array = %p\r\n"
  3236. "\tProtocol Count = %d\r\n",
  3237. pszHeader,
  3238. pProtocolArray,
  3239. ProtocolCount );
  3240. if ( pProtocolArray )
  3241. {
  3242. for ( i=0; i<ProtocolCount; i++ )
  3243. {
  3244. PrintRoutine(
  3245. pContext,
  3246. "\t\tfamily = %d; proto = %d\r\n",
  3247. pProtocolArray[i].iAddressFamily,
  3248. pProtocolArray[i].iProtocol );
  3249. }
  3250. }
  3251. DnsPrint_Unlock();
  3252. }
  3253. VOID
  3254. DnsPrint_WsaQuerySet(
  3255. IN PRINT_ROUTINE PrintRoutine,
  3256. IN OUT PPRINT_CONTEXT pContext,
  3257. IN PSTR pszHeader,
  3258. IN LPWSAQUERYSET pQuerySet,
  3259. IN BOOL fUnicode
  3260. )
  3261. /*++
  3262. Routine Description:
  3263. Print WSAQUERYSET structure.
  3264. Arguments:
  3265. PrintRoutine - routine to print with
  3266. pszHeader - header
  3267. pQuerySet - ptr to WSAQUERYSET to print
  3268. fUnicode - TRUE if WSAQUERYSET is wide (WSAQUERYSETW)
  3269. FALSE if ANSI
  3270. Return Value:
  3271. None.
  3272. --*/
  3273. {
  3274. CHAR serviceGuidBuffer[ GUID_STRING_BUFFER_LENGTH ];
  3275. CHAR nameSpaceGuidBuffer[ GUID_STRING_BUFFER_LENGTH ];
  3276. DWORD i;
  3277. if ( !pszHeader )
  3278. {
  3279. pszHeader = "WSAQuerySet:";
  3280. }
  3281. if ( !pQuerySet )
  3282. {
  3283. PrintRoutine(
  3284. pContext,
  3285. "%s NULL QuerySet ptr\r\n",
  3286. pszHeader );
  3287. return;
  3288. }
  3289. // convert GUIDs to strings
  3290. DnsStringPrint_Guid(
  3291. serviceGuidBuffer,
  3292. pQuerySet->lpServiceClassId
  3293. );
  3294. DnsStringPrint_Guid(
  3295. nameSpaceGuidBuffer,
  3296. pQuerySet->lpNSProviderId
  3297. );
  3298. // print the struct
  3299. DnsPrint_Lock();
  3300. PrintRoutine(
  3301. pContext,
  3302. "%s\r\n"
  3303. "\tSize = %d\r\n"
  3304. "\tServiceInstanceName = %S%s\r\n"
  3305. "\tService GUID = (%p) %s\r\n"
  3306. "\tWSA version = %p %x %d\r\n"
  3307. "\tComment = %S%s\r\n"
  3308. "\tName Space = %d %s\r\n"
  3309. "\tName Space GUID = (%p) %s\r\n"
  3310. "\tContext = %S%s\r\n"
  3311. "\tNumberOfProtocols = %d\r\n"
  3312. "\tProtocol Array = %p\r\n"
  3313. "\tQueryString = %S%s\r\n"
  3314. "\tCS Addr Count = %d\r\n"
  3315. "\tCS Addr Array = %p\r\n"
  3316. "\tOutput Flags = %08x\r\n"
  3317. "\tpBlob = %p\r\n",
  3318. pszHeader,
  3319. pQuerySet->dwSize,
  3320. DNSSTRING_WIDE( fUnicode, pQuerySet->lpszServiceInstanceName ),
  3321. DNSSTRING_ANSI( fUnicode, pQuerySet->lpszServiceInstanceName ),
  3322. pQuerySet->lpServiceClassId,
  3323. serviceGuidBuffer,
  3324. pQuerySet->lpVersion,
  3325. ( pQuerySet->lpVersion ) ? pQuerySet->lpVersion->dwVersion : 0,
  3326. ( pQuerySet->lpVersion ) ? pQuerySet->lpVersion->ecHow : 0,
  3327. DNSSTRING_WIDE( fUnicode, pQuerySet->lpszComment ),
  3328. DNSSTRING_ANSI( fUnicode, pQuerySet->lpszComment ),
  3329. pQuerySet->dwNameSpace,
  3330. Dns_GetRnrNameSpaceIdString( pQuerySet->dwNameSpace ),
  3331. pQuerySet->lpNSProviderId,
  3332. nameSpaceGuidBuffer,
  3333. DNSSTRING_WIDE( fUnicode, pQuerySet->lpszContext ),
  3334. DNSSTRING_ANSI( fUnicode, pQuerySet->lpszContext ),
  3335. pQuerySet->dwNumberOfProtocols,
  3336. pQuerySet->lpafpProtocols,
  3337. DNSSTRING_WIDE( fUnicode, pQuerySet->lpszQueryString ),
  3338. DNSSTRING_ANSI( fUnicode, pQuerySet->lpszQueryString ),
  3339. pQuerySet->dwNumberOfCsAddrs,
  3340. pQuerySet->lpcsaBuffer,
  3341. pQuerySet->dwOutputFlags,
  3342. pQuerySet->lpBlob
  3343. );
  3344. // print address-family\protocols array
  3345. if ( pQuerySet->lpafpProtocols )
  3346. {
  3347. DnsPrint_AfProtocolsArray(
  3348. PrintRoutine,
  3349. pContext,
  3350. "\tAFPROTOCOLS Array:",
  3351. pQuerySet->lpafpProtocols,
  3352. pQuerySet->dwNumberOfProtocols );
  3353. }
  3354. // print CSADDR_INFO array
  3355. if ( pQuerySet->dwNumberOfCsAddrs &&
  3356. pQuerySet->lpcsaBuffer )
  3357. {
  3358. PrintRoutine(
  3359. pContext,
  3360. "--- CS_ADDR array:\r\n" );
  3361. for ( i=0; i<pQuerySet->dwNumberOfCsAddrs; i++ )
  3362. {
  3363. DnsPrint_CsAddr(
  3364. PrintRoutine,
  3365. pContext,
  3366. NULL,
  3367. 1, // indent one level
  3368. & pQuerySet->lpcsaBuffer[i] );
  3369. }
  3370. }
  3371. // print blob (the hostent)
  3372. //
  3373. // DCR_FIX0: need some sort of test for blob type?
  3374. // - most blobs are hostent, but some are servent
  3375. //
  3376. if ( pQuerySet->lpBlob )
  3377. {
  3378. GUID ianaGuid = SVCID_INET_SERVICEBYNAME;
  3379. PrintRoutine(
  3380. pContext,
  3381. "--- BLOB:\n"
  3382. "\tcbSize = %d\r\n"
  3383. "\tpBlobData = %p\r\n",
  3384. pQuerySet->lpBlob->cbSize,
  3385. pQuerySet->lpBlob->pBlobData
  3386. );
  3387. // note: can't print blob as hostent
  3388. // 1) may not be hostent
  3389. // 2) is passed with offsets rather than pointers
  3390. DnsPrint_RawBinary(
  3391. PrintRoutine,
  3392. pContext,
  3393. NULL,
  3394. "\t\t",
  3395. pQuerySet->lpBlob->pBlobData,
  3396. pQuerySet->lpBlob->cbSize,
  3397. sizeof(DWORD)
  3398. );
  3399. }
  3400. DnsPrint_Unlock();
  3401. }
  3402. VOID
  3403. DnsPrint_WsaNsClassInfo(
  3404. IN PRINT_ROUTINE PrintRoutine,
  3405. IN OUT PPRINT_CONTEXT pContext,
  3406. IN PSTR pszHeader,
  3407. IN PWSANSCLASSINFO pInfo,
  3408. IN BOOL fUnicode
  3409. )
  3410. /*++
  3411. Routine Description:
  3412. Print WSACLASSINFO structure.
  3413. Arguments:
  3414. PrintRoutine - routine to print with
  3415. pszHeader - header
  3416. pInfo - ptr to WSACLASSINFO to print
  3417. fUnicode - TRUE if WSACLASSINFO is wide (WSACLASSINFOW)
  3418. FALSE if ANSI
  3419. Return Value:
  3420. None.
  3421. --*/
  3422. {
  3423. if ( !pszHeader )
  3424. {
  3425. pszHeader = "WSANsClassInfo:";
  3426. }
  3427. if ( !pInfo )
  3428. {
  3429. PrintRoutine(
  3430. pContext,
  3431. "%s NULL NsClassInfo ptr\r\n",
  3432. pszHeader );
  3433. return;
  3434. }
  3435. // print the struct
  3436. DnsPrint_Lock();
  3437. PrintRoutine(
  3438. pContext,
  3439. "%s\r\n"
  3440. "\tPtr = %d\r\n"
  3441. "\tName = %S%s\r\n"
  3442. "\tName Space = %d\r\n"
  3443. "\tValue Type = %d\r\n"
  3444. "\tValue Size = %d\r\n"
  3445. "\tpValue = %p\r\n",
  3446. pszHeader,
  3447. pInfo,
  3448. DNSSTRING_WIDE( fUnicode, pInfo->lpszName ),
  3449. DNSSTRING_ANSI( fUnicode, pInfo->lpszName ),
  3450. pInfo->dwNameSpace,
  3451. pInfo->dwValueType,
  3452. pInfo->dwValueSize,
  3453. pInfo->lpValue
  3454. );
  3455. if ( pInfo->lpValue )
  3456. {
  3457. PrintRoutine(
  3458. pContext,
  3459. "--- Value:\r\n"
  3460. );
  3461. DnsPrint_RawBinary(
  3462. PrintRoutine,
  3463. pContext,
  3464. NULL,
  3465. "\t\t",
  3466. pInfo->lpValue,
  3467. pInfo->dwValueSize,
  3468. sizeof(BYTE) // print in bytes
  3469. );
  3470. }
  3471. DnsPrint_Unlock();
  3472. }
  3473. VOID
  3474. DnsPrint_WsaServiceClassInfo(
  3475. IN PRINT_ROUTINE PrintRoutine,
  3476. IN OUT PPRINT_CONTEXT pContext,
  3477. IN PSTR pszHeader,
  3478. IN LPWSASERVICECLASSINFO pInfo,
  3479. IN BOOL fUnicode
  3480. )
  3481. /*++
  3482. Routine Description:
  3483. Print WSASERVICECLASSINFO structure.
  3484. Arguments:
  3485. PrintRoutine - routine to print with
  3486. pszHeader - header
  3487. pInfo - ptr to WSASERVICECLASSINFO to print
  3488. fUnicode - TRUE if WSASERVICECLASSINFO is wide (WSASERVICECLASSINFOW)
  3489. FALSE if ANSI
  3490. Return Value:
  3491. None.
  3492. --*/
  3493. {
  3494. CHAR serviceClassGuidBuffer[ GUID_STRING_BUFFER_LENGTH ];
  3495. if ( !pszHeader )
  3496. {
  3497. pszHeader = "WSAServiceClassInfo:";
  3498. }
  3499. if ( !pInfo )
  3500. {
  3501. PrintRoutine(
  3502. pContext,
  3503. "%s NULL ServiceClassInfo ptr\r\n",
  3504. pszHeader );
  3505. return;
  3506. }
  3507. // convert GUID to strings
  3508. DnsStringPrint_Guid(
  3509. serviceClassGuidBuffer,
  3510. pInfo->lpServiceClassId
  3511. );
  3512. // print the struct
  3513. DnsPrint_Lock();
  3514. PrintRoutine(
  3515. pContext,
  3516. "%s\r\n"
  3517. "\tPtr = %p\r\n"
  3518. "\tClass GUID = (%p) %s\r\n"
  3519. "\tClassName = %S%s\r\n"
  3520. "\tClass Info Count = %d\r\n"
  3521. "\tClass Info Array = %p\r\n",
  3522. pszHeader,
  3523. pInfo,
  3524. serviceClassGuidBuffer,
  3525. DNSSTRING_WIDE( fUnicode, pInfo->lpszServiceClassName ),
  3526. DNSSTRING_ANSI( fUnicode, pInfo->lpszServiceClassName ),
  3527. pInfo->dwCount,
  3528. pInfo->lpClassInfos
  3529. );
  3530. if ( pInfo->lpClassInfos )
  3531. {
  3532. DWORD i;
  3533. for ( i=0; i<pInfo->dwCount; i++ )
  3534. {
  3535. DnsPrint_WsaNsClassInfo(
  3536. PrintRoutine,
  3537. pContext,
  3538. NULL, // default header
  3539. & pInfo->lpClassInfos[i],
  3540. fUnicode
  3541. );
  3542. }
  3543. }
  3544. DnsPrint_Unlock();
  3545. }
  3546. VOID
  3547. DnsPrint_Hostent(
  3548. IN PRINT_ROUTINE PrintRoutine,
  3549. IN OUT PPRINT_CONTEXT pContext,
  3550. IN PSTR pszHeader,
  3551. IN PHOSTENT pHostent,
  3552. IN BOOL fUnicode
  3553. )
  3554. /*++
  3555. Routine Description:
  3556. Print hostent structure.
  3557. Arguments:
  3558. PrintRoutine - routine to print with
  3559. pszHeader - header
  3560. pHostent - ptr to hostent
  3561. fUnicode - TRUE if hostent is unicode
  3562. FALSE if ANSI
  3563. Return Value:
  3564. None.
  3565. --*/
  3566. {
  3567. DWORD i;
  3568. if ( !pszHeader )
  3569. {
  3570. pszHeader = "Hostent:";
  3571. }
  3572. if ( !pHostent )
  3573. {
  3574. PrintRoutine(
  3575. pContext,
  3576. "%s %s\r\n",
  3577. pszHeader,
  3578. "NULL Hostent ptr." );
  3579. return;
  3580. }
  3581. // print the struct
  3582. DnsPrint_Lock();
  3583. PrintRoutine(
  3584. pContext,
  3585. "%s\r\n"
  3586. "\th_name = %p %S%s\n"
  3587. "\th_aliases = %p\n"
  3588. "\th_addrtype = %d\n"
  3589. "\th_length = %d\n"
  3590. "\th_addrlist = %p\n",
  3591. pszHeader,
  3592. pHostent->h_name,
  3593. DNSSTRING_WIDE( fUnicode, pHostent->h_name ),
  3594. DNSSTRING_ANSI( fUnicode, pHostent->h_name ),
  3595. pHostent->h_aliases,
  3596. pHostent->h_addrtype,
  3597. pHostent->h_length,
  3598. pHostent->h_addr_list
  3599. );
  3600. // print the aliases
  3601. if ( pHostent->h_aliases )
  3602. {
  3603. PSTR * paliasArray = pHostent->h_aliases;
  3604. PSTR palias;
  3605. while ( palias = *paliasArray++ )
  3606. {
  3607. PrintRoutine(
  3608. pContext,
  3609. "\tAlias = (%p) %S%s\n",
  3610. palias,
  3611. DNSSTRING_WIDE( fUnicode, palias ),
  3612. DNSSTRING_ANSI( fUnicode, palias ) );
  3613. }
  3614. }
  3615. // print the addresses
  3616. if ( pHostent->h_addr_list )
  3617. {
  3618. PCHAR * ppaddr = pHostent->h_addr_list;
  3619. PCHAR pip;
  3620. INT i = 0;
  3621. INT family = pHostent->h_addrtype;
  3622. INT addrLength = pHostent->h_length;
  3623. CHAR stringBuf[ IP6_ADDRESS_STRING_BUFFER_LENGTH ];
  3624. while ( pip = ppaddr[i] )
  3625. {
  3626. DWORD bufLength = IP6_ADDRESS_STRING_BUFFER_LENGTH;
  3627. Dns_AddressToString_A(
  3628. stringBuf,
  3629. & bufLength,
  3630. pip,
  3631. addrLength,
  3632. family );
  3633. PrintRoutine(
  3634. pContext,
  3635. "\tAddr[%d] = %s \t(ptr=%p)\n",
  3636. i,
  3637. stringBuf,
  3638. pip );
  3639. i++;
  3640. }
  3641. }
  3642. DnsPrint_Unlock();
  3643. }
  3644. //
  3645. // Query print routines
  3646. //
  3647. VOID
  3648. DnsPrint_QueryBlob(
  3649. IN PRINT_ROUTINE PrintRoutine,
  3650. IN OUT PPRINT_CONTEXT pContext,
  3651. IN PSTR pszHeader,
  3652. IN PQUERY_BLOB pBlob
  3653. )
  3654. /*++
  3655. Routine Description:
  3656. Print query blob.
  3657. Arguments:
  3658. PrintRoutine - routine to print with
  3659. pContext - print context
  3660. pszHeader - header
  3661. pBlob - query info
  3662. Return Value:
  3663. None.
  3664. --*/
  3665. {
  3666. DWORD i;
  3667. if ( !pszHeader )
  3668. {
  3669. pszHeader = "Query Blob:";
  3670. }
  3671. if ( !pBlob )
  3672. {
  3673. PrintRoutine(
  3674. pContext,
  3675. "%s %s\r\n",
  3676. pszHeader,
  3677. "NULL Query Blob ptr." );
  3678. return;
  3679. }
  3680. // print the struct
  3681. DnsPrint_Lock();
  3682. PrintRoutine(
  3683. pContext,
  3684. "\tname orig %S\n"
  3685. "\tname orig wire %s\n"
  3686. "\tname wire %s\n"
  3687. "\ttype %d\n"
  3688. "\tflags %08x\n"
  3689. "\tname length %d\n"
  3690. "\tname attributes %08x\n"
  3691. "\tquery count %d\n"
  3692. "\tname flags %08x\n"
  3693. "\tfappendedName %d\n"
  3694. "\tstatus %d\n"
  3695. "\trcode %d\n"
  3696. "\tnetfail status %d\n"
  3697. "\tcache negative %d\n"
  3698. "\tno ip local %d\n"
  3699. "\trecords %p\n"
  3700. "\tlocal records %p\n"
  3701. "\tnetwork info %p\n"
  3702. "\tserver IPs %p\n"
  3703. "\tpmsg %p\n"
  3704. "\tevent %p\n",
  3705. pBlob->pNameOrig,
  3706. pBlob->pNameOrigWire,
  3707. pBlob->pNameWire,
  3708. pBlob->wType,
  3709. pBlob->Flags,
  3710. pBlob->NameLength,
  3711. pBlob->NameAttributes,
  3712. pBlob->QueryCount,
  3713. pBlob->NameFlags,
  3714. pBlob->fAppendedName,
  3715. pBlob->Status,
  3716. pBlob->Rcode,
  3717. pBlob->NetFailureStatus,
  3718. pBlob->fCacheNegative,
  3719. pBlob->fNoIpLocal,
  3720. pBlob->pRecords,
  3721. pBlob->pLocalRecords,
  3722. pBlob->pNetworkInfo,
  3723. pBlob->pDnsServers,
  3724. pBlob->pRecvMsg,
  3725. pBlob->hEvent
  3726. );
  3727. // DCR_FIX0: cleanup when results in use
  3728. DnsPrint_RecordSet(
  3729. PrintRoutine,
  3730. pContext,
  3731. "Records:\n",
  3732. pBlob->pRecords );
  3733. // DCR_FIX0: use results when ready
  3734. DnsPrint_Unlock();
  3735. }
  3736. VOID
  3737. DnsPrint_QueryResults(
  3738. IN PRINT_ROUTINE PrintRoutine,
  3739. IN OUT PPRINT_CONTEXT pContext,
  3740. IN PSTR pszHeader,
  3741. IN PDNS_RESULTS pResults
  3742. )
  3743. /*++
  3744. Routine Description:
  3745. Print query results.
  3746. Arguments:
  3747. PrintRoutine - routine to print with
  3748. pContext - print context
  3749. pszHeader - header
  3750. pResults - results info
  3751. Return Value:
  3752. None.
  3753. --*/
  3754. {
  3755. DWORD i;
  3756. if ( !pszHeader )
  3757. {
  3758. pszHeader = "Results:";
  3759. }
  3760. if ( !pResults )
  3761. {
  3762. PrintRoutine(
  3763. pContext,
  3764. "%s %s\r\n",
  3765. pszHeader,
  3766. "NULL Results ptr." );
  3767. return;
  3768. }
  3769. // print the struct
  3770. DnsPrint_Lock();
  3771. PrintRoutine(
  3772. pContext,
  3773. "\tstatus %d\n"
  3774. "\trcode %d\n"
  3775. "\tserver %s\n"
  3776. "\tpanswer %p\n"
  3777. "\tpalias %p\n"
  3778. "\tpauthority %p\n"
  3779. "\tpadditional %p\n"
  3780. "\tpsig %p\n"
  3781. "\tpmsg %p\n",
  3782. pResults->Status,
  3783. pResults->Rcode,
  3784. IP_STRING( pResults->ServerIp ),
  3785. pResults->pAnswerRecords,
  3786. pResults->pAliasRecords,
  3787. pResults->pAuthorityRecords,
  3788. pResults->pAdditionalRecords,
  3789. pResults->pSigRecords,
  3790. pResults->pMessage
  3791. );
  3792. DnsPrint_RecordSet(
  3793. PrintRoutine,
  3794. pContext,
  3795. "\tAnswer records:\n",
  3796. pResults->pAnswerRecords );
  3797. DnsPrint_RecordSet(
  3798. PrintRoutine,
  3799. pContext,
  3800. "\tAlias records:\n",
  3801. pResults->pAliasRecords );
  3802. DnsPrint_RecordSet(
  3803. PrintRoutine,
  3804. pContext,
  3805. "\tAuthority records:\n",
  3806. pResults->pAuthorityRecords );
  3807. DnsPrint_RecordSet(
  3808. PrintRoutine,
  3809. pContext,
  3810. "\tAdditional records:\n",
  3811. pResults->pAdditionalRecords );
  3812. DnsPrint_RecordSet(
  3813. PrintRoutine,
  3814. pContext,
  3815. "\tSignature records:\n",
  3816. pResults->pSigRecords );
  3817. DnsPrint_Unlock();
  3818. }
  3819. VOID
  3820. DnsPrint_ParsedMessage(
  3821. IN PRINT_ROUTINE PrintRoutine,
  3822. IN OUT PPRINT_CONTEXT pContext,
  3823. IN PSTR pszHeader,
  3824. IN PDNS_PARSED_MESSAGE pParsed
  3825. )
  3826. /*++
  3827. Routine Description:
  3828. Print parsed message.
  3829. Arguments:
  3830. PrintRoutine - routine to print with
  3831. pContext - print context
  3832. pszHeader - header
  3833. pResults - query info
  3834. Return Value:
  3835. None.
  3836. --*/
  3837. {
  3838. DWORD i;
  3839. if ( !pszHeader )
  3840. {
  3841. pszHeader = "Parsed Message:";
  3842. }
  3843. if ( !pParsed )
  3844. {
  3845. PrintRoutine(
  3846. pContext,
  3847. "%s %s\r\n",
  3848. pszHeader,
  3849. "NULL Parsed Message ptr." );
  3850. return;
  3851. }
  3852. // print the struct
  3853. DnsPrint_Lock();
  3854. PrintRoutine(
  3855. pContext,
  3856. "\tstatus %d (%08x)\n"
  3857. "\tchar set %d\n",
  3858. pParsed->Status, pParsed->Status,
  3859. pParsed->CharSet
  3860. );
  3861. PrintRoutine(
  3862. pContext,
  3863. "\tquestion:\n"
  3864. "\t\tname %S%s\n"
  3865. "\t\ttype %d\n"
  3866. "\t\tclass %d\n",
  3867. PRINT_STRING_WIDE_CHARSET( pParsed->pQuestionName, pParsed->CharSet ),
  3868. PRINT_STRING_ANSI_CHARSET( pParsed->pQuestionName, pParsed->CharSet ),
  3869. pParsed->QuestionType,
  3870. pParsed->QuestionClass
  3871. );
  3872. DnsPrint_RecordSet(
  3873. PrintRoutine,
  3874. pContext,
  3875. "Answer records:\n",
  3876. pParsed->pAnswerRecords );
  3877. DnsPrint_RecordSet(
  3878. PrintRoutine,
  3879. pContext,
  3880. "Alias records:\n",
  3881. pParsed->pAliasRecords );
  3882. DnsPrint_RecordSet(
  3883. PrintRoutine,
  3884. pContext,
  3885. "Authority records:\n",
  3886. pParsed->pAuthorityRecords );
  3887. DnsPrint_RecordSet(
  3888. PrintRoutine,
  3889. pContext,
  3890. "Additional records:\n",
  3891. pParsed->pAdditionalRecords );
  3892. DnsPrint_RecordSet(
  3893. PrintRoutine,
  3894. pContext,
  3895. "Signature records:\n",
  3896. pParsed->pSigRecords );
  3897. DnsPrint_Unlock();
  3898. }
  3899. VOID
  3900. DnsPrint_QueryInfo(
  3901. IN PRINT_ROUTINE PrintRoutine,
  3902. IN OUT PPRINT_CONTEXT pContext,
  3903. IN PSTR pszHeader,
  3904. IN PDNS_QUERY_INFO pQueryInfo
  3905. )
  3906. /*++
  3907. Routine Description:
  3908. Print query info
  3909. Arguments:
  3910. PrintRoutine - routine to print with
  3911. pContext - print context
  3912. pszHeader - header
  3913. pQueryInfo - query info
  3914. Return Value:
  3915. None.
  3916. --*/
  3917. {
  3918. DWORD i;
  3919. if ( !pszHeader )
  3920. {
  3921. pszHeader = "Query Info:";
  3922. }
  3923. if ( !pQueryInfo )
  3924. {
  3925. PrintRoutine(
  3926. pContext,
  3927. "%s %s\r\n",
  3928. pszHeader,
  3929. "NULL Query Info ptr." );
  3930. return;
  3931. }
  3932. // print the struct
  3933. DnsPrint_Lock();
  3934. PrintRoutine(
  3935. pContext,
  3936. "%s\n"
  3937. "\tpointer %p\n"
  3938. "\tstatus %d (%08x)\n"
  3939. "\tchar set %d\n"
  3940. "\tname %S%s\n"
  3941. "\tname resv. %s\n"
  3942. "\ttype %d\n"
  3943. "\trcode %d\n"
  3944. "\tflags %08x\n"
  3945. "\tpanswer %p\n"
  3946. "\tpalias %p\n"
  3947. "\tpauthority %p\n"
  3948. "\tpadditional %p\n"
  3949. //"\tpsig %p\n"
  3950. "\tevent %p\n"
  3951. "\tpDnsServers %p\n"
  3952. "\tpmsg %p\n",
  3953. pszHeader,
  3954. pQueryInfo,
  3955. pQueryInfo->Status, pQueryInfo->Status,
  3956. pQueryInfo->CharSet,
  3957. PRINT_STRING_WIDE_CHARSET( pQueryInfo->pName, pQueryInfo->CharSet ),
  3958. PRINT_STRING_ANSI_CHARSET( pQueryInfo->pName, pQueryInfo->CharSet ),
  3959. pQueryInfo->pReservedName,
  3960. pQueryInfo->Type,
  3961. pQueryInfo->Rcode,
  3962. pQueryInfo->Flags,
  3963. pQueryInfo->pAnswerRecords,
  3964. pQueryInfo->pAliasRecords,
  3965. pQueryInfo->pAuthorityRecords,
  3966. pQueryInfo->pAdditionalRecords,
  3967. //pQueryInfo->pSigRecords,
  3968. pQueryInfo->hEvent,
  3969. pQueryInfo->pDnsServers,
  3970. pQueryInfo->pMessage
  3971. );
  3972. DnsPrint_RecordSet(
  3973. PrintRoutine,
  3974. pContext,
  3975. "Answer records:\n",
  3976. pQueryInfo->pAnswerRecords );
  3977. DnsPrint_RecordSet(
  3978. PrintRoutine,
  3979. pContext,
  3980. "Alias records:\n",
  3981. pQueryInfo->pAliasRecords );
  3982. DnsPrint_RecordSet(
  3983. PrintRoutine,
  3984. pContext,
  3985. "Authority records:\n",
  3986. pQueryInfo->pAuthorityRecords );
  3987. DnsPrint_RecordSet(
  3988. PrintRoutine,
  3989. pContext,
  3990. "Additional records:\n",
  3991. pQueryInfo->pAdditionalRecords );
  3992. //DnsPrint_RecordSet(
  3993. // "Signature records:\n",
  3994. // pQueryInfo->pSigRecords );
  3995. DnsPrint_Unlock();
  3996. }
  3997. VOID
  3998. DnsPrint_EnvarInfo(
  3999. IN PRINT_ROUTINE PrintRoutine,
  4000. IN OUT PPRINT_CONTEXT pContext,
  4001. IN PSTR pszHeader,
  4002. IN PENVAR_DWORD_INFO pEnvar
  4003. )
  4004. /*++
  4005. Routine Description:
  4006. Print envar data
  4007. Arguments:
  4008. PrintRoutine - routine to print with
  4009. pContext - print context
  4010. pszHeader -- header to print with
  4011. pEnvar -- ptr to envar info
  4012. Return Value:
  4013. ERROR_SUCCESS if successful.
  4014. ErrorCode on failure.
  4015. --*/
  4016. {
  4017. PrintRoutine(
  4018. pContext,
  4019. "%s\n"
  4020. "\tId = %d\n"
  4021. "\tValue = %p\n"
  4022. "\tfFound = %d\n",
  4023. pszHeader ? pszHeader : "Envar Info:",
  4024. pEnvar->Id,
  4025. pEnvar->Value,
  4026. pEnvar->fFound
  4027. );
  4028. }
  4029. //
  4030. // Network info print routines.
  4031. //
  4032. VOID
  4033. DnsPrint_NetworkInfo(
  4034. IN PRINT_ROUTINE PrintRoutine,
  4035. IN OUT PPRINT_CONTEXT pPrintContext,
  4036. IN LPSTR pszHeader,
  4037. IN PDNS_NETINFO pNetworkInfo
  4038. )
  4039. /*++
  4040. Routine Description:
  4041. Prints and validates network info structure.
  4042. Should also touch all the memory and AV when bogus.
  4043. Arguments:
  4044. pNetworkInfo -- network info to print
  4045. Return Value:
  4046. None.
  4047. --*/
  4048. {
  4049. DWORD i;
  4050. if ( !pszHeader )
  4051. {
  4052. pszHeader = "NetworkInfo:";
  4053. }
  4054. if ( !pNetworkInfo )
  4055. {
  4056. PrintRoutine(
  4057. pPrintContext,
  4058. "%s NULL NetworkInfo.\n",
  4059. pszHeader );
  4060. return;
  4061. }
  4062. DnsPrint_Lock();
  4063. PrintRoutine(
  4064. pPrintContext,
  4065. "%s\n"
  4066. "\tpointer = %p\n"
  4067. "\tpszHostName = %s\n"
  4068. "\tpszDomainName = %s\n"
  4069. "\tpSearchList = %p\n"
  4070. "\tTimeStamp = %d\n"
  4071. "\tInfoFlags = %08x\n"
  4072. "\tReturnFlags = %08x\n"
  4073. "\tAdapterCount = %d\n"
  4074. "\tAdapterArraySize = %d\n",
  4075. pszHeader,
  4076. pNetworkInfo,
  4077. pNetworkInfo->pszHostName,
  4078. pNetworkInfo->pszDomainName,
  4079. pNetworkInfo->pSearchList,
  4080. pNetworkInfo->TimeStamp,
  4081. pNetworkInfo->InfoFlags,
  4082. pNetworkInfo->ReturnFlags,
  4083. pNetworkInfo->AdapterCount,
  4084. pNetworkInfo->MaxAdapterCount );
  4085. // print search list
  4086. DnsPrint_SearchList(
  4087. PrintRoutine,
  4088. pPrintContext,
  4089. "Search List: ",
  4090. pNetworkInfo->pSearchList );
  4091. // print server lists
  4092. for ( i=0; i < pNetworkInfo->AdapterCount; i++ )
  4093. {
  4094. CHAR header[60];
  4095. sprintf( header, "AdapterInfo[%d]:", i );
  4096. DnsPrint_AdapterInfo(
  4097. PrintRoutine,
  4098. pPrintContext,
  4099. header,
  4100. pNetworkInfo->AdapterArray[i] );
  4101. }
  4102. PrintRoutine(
  4103. pPrintContext,
  4104. "\n" );
  4105. DnsPrint_Unlock();
  4106. }
  4107. VOID
  4108. DnsPrint_AdapterInfo(
  4109. IN PRINT_ROUTINE PrintRoutine,
  4110. IN OUT PPRINT_CONTEXT pPrintContext,
  4111. IN LPSTR pszHeader,
  4112. IN PDNS_ADAPTER pAdapter
  4113. )
  4114. /*++
  4115. Routine Description:
  4116. Prints and validates DNS adapter info.
  4117. Should also touch all the memory and AV when bogus.
  4118. Arguments:
  4119. pAdapter -- DNS adapter to print
  4120. Return Value:
  4121. None.
  4122. --*/
  4123. {
  4124. DWORD i;
  4125. if ( !pszHeader )
  4126. {
  4127. pszHeader = "Adapter Info:";
  4128. }
  4129. if ( !pAdapter )
  4130. {
  4131. PrintRoutine(
  4132. pPrintContext,
  4133. "%s NULL Adapter info.\n",
  4134. pszHeader );
  4135. return;
  4136. }
  4137. DnsPrint_Lock();
  4138. PrintRoutine(
  4139. pPrintContext,
  4140. "%s\n"
  4141. "\tpointer = %p\n"
  4142. "\tDomain = %s\n"
  4143. "\tGuid Name = %s\n"
  4144. "\tInterfaceIndex = %d\n"
  4145. "\tInfoFlags = %08x\n"
  4146. "\tStatus = %d\n"
  4147. "\tRunFlags = %08x\n"
  4148. "\tServerIndex = %d\n"
  4149. "\tServerCount = %d\n"
  4150. "\tServerArraySize = %d\n",
  4151. pszHeader,
  4152. pAdapter,
  4153. pAdapter->pszAdapterDomain,
  4154. pAdapter->pszAdapterGuidName,
  4155. pAdapter->InterfaceIndex,
  4156. pAdapter->InfoFlags,
  4157. pAdapter->Status,
  4158. pAdapter->RunFlags,
  4159. pAdapter->ServerIndex,
  4160. pAdapter->ServerCount,
  4161. pAdapter->MaxServerCount );
  4162. // DNS server info
  4163. for ( i=0; i < pAdapter->ServerCount; i++ )
  4164. {
  4165. // DCR: IP6 DNS server address
  4166. PrintRoutine(
  4167. pPrintContext,
  4168. "\tDNS Server [%d]:\n"
  4169. "\t\tIpAddr = %s\n"
  4170. "\t\tPriority = %d\n"
  4171. "\t\tStatus = %d (%08x)\n",
  4172. i,
  4173. IP_STRING( pAdapter->ServerArray[i].IpAddress ),
  4174. pAdapter->ServerArray[i].Priority,
  4175. pAdapter->ServerArray[i].Status,
  4176. pAdapter->ServerArray[i].Status
  4177. );
  4178. }
  4179. // IP address info
  4180. DnsPrint_IpArray(
  4181. PrintRoutine,
  4182. pPrintContext,
  4183. "IP Addrs",
  4184. "IP",
  4185. pAdapter->pAdapterIPAddresses );
  4186. DnsPrint_IpArray(
  4187. PrintRoutine,
  4188. pPrintContext,
  4189. "IP Addr Subnets",
  4190. "Mask",
  4191. pAdapter->pAdapterIPSubnetMasks );
  4192. DnsPrint_Unlock();
  4193. }
  4194. VOID
  4195. DnsPrint_SearchList(
  4196. IN PRINT_ROUTINE PrintRoutine,
  4197. IN OUT PPRINT_CONTEXT pPrintContext,
  4198. IN LPSTR pszHeader,
  4199. IN PSEARCH_LIST pSearchList
  4200. )
  4201. /*++
  4202. Routine Description:
  4203. Prints and validates DNS search list.
  4204. Should also touch all the memory and AV when bogus.
  4205. Arguments:
  4206. pSearchList -- search list to print
  4207. Return Value:
  4208. None.
  4209. --*/
  4210. {
  4211. DWORD i;
  4212. if ( !pszHeader )
  4213. {
  4214. pszHeader = "DNS Search List:";
  4215. }
  4216. if ( ! pSearchList )
  4217. {
  4218. PrintRoutine(
  4219. pPrintContext,
  4220. "%s NULL search list.\n",
  4221. pszHeader );
  4222. return;
  4223. }
  4224. DnsPrint_Lock();
  4225. PrintRoutine(
  4226. pPrintContext,
  4227. "%s\n"
  4228. "\tpointer = %p\n"
  4229. "\tpszDomain = %s\n"
  4230. "\tcNameCount = %d\n"
  4231. "\tcTotalListSize = %d\n"
  4232. "\tCurrentName = %d\n"
  4233. "\tSearchListNames:\n",
  4234. pszHeader,
  4235. pSearchList,
  4236. pSearchList->pszDomainOrZoneName,
  4237. pSearchList->NameCount,
  4238. pSearchList->MaxNameCount,
  4239. pSearchList->CurrentNameIndex
  4240. );
  4241. for ( i=0; i < pSearchList->NameCount; i++ )
  4242. {
  4243. PrintRoutine(
  4244. pPrintContext,
  4245. "\t\t%s (Flags: %08x)\n",
  4246. pSearchList->SearchNameArray[i].pszName,
  4247. pSearchList->SearchNameArray[i].Flags );
  4248. }
  4249. DnsPrint_Unlock();
  4250. }
  4251. VOID
  4252. DnsPrint_HostentBlob(
  4253. IN PRINT_ROUTINE PrintRoutine,
  4254. IN OUT PPRINT_CONTEXT pContext,
  4255. IN PSTR pszHeader,
  4256. IN PHOSTENT_BLOB pBlob
  4257. )
  4258. /*++
  4259. Routine Description:
  4260. Print hostent structure.
  4261. Arguments:
  4262. PrintRoutine - routine to print with
  4263. pszHeader - header
  4264. pBlob - ptr to hostent blob
  4265. Return Value:
  4266. None.
  4267. --*/
  4268. {
  4269. DWORD i;
  4270. if ( !pszHeader )
  4271. {
  4272. pszHeader = "Hostent Blob:";
  4273. }
  4274. if ( !pBlob )
  4275. {
  4276. PrintRoutine(
  4277. pContext,
  4278. "%s %s\r\n",
  4279. pszHeader,
  4280. "NULL Hostent blob ptr." );
  4281. return;
  4282. }
  4283. // print the struct
  4284. DnsPrint_Lock();
  4285. PrintRoutine(
  4286. pContext,
  4287. "%s\r\n"
  4288. "\tPtr = %p\n"
  4289. "\tpHostent = %p\n"
  4290. "\tfAllocatedBlob = %d\n"
  4291. "\tfAllocatedBuf = %d\n"
  4292. "\tpBuffer = %p\n"
  4293. "\tBufferLength = %d\n"
  4294. "\tAvailLength = %d\n"
  4295. "\tpAvailBuffer = %p\n"
  4296. "\tpCurrent = %p\n"
  4297. "\tBytesLeft = %d\n"
  4298. "\tMaxAliasCount = %d\n"
  4299. "\tAliasCount = %d\n"
  4300. "\tMaxAddrCount = %d\n"
  4301. "\tAddrCount = %d\n"
  4302. "\tfWroteName = %d\n"
  4303. "\tfUnicode = %d\n"
  4304. "\tCharSet = %d\n",
  4305. pszHeader,
  4306. pBlob,
  4307. pBlob->pHostent,
  4308. pBlob->fAllocatedBlob,
  4309. pBlob->fAllocatedBuf,
  4310. pBlob->pBuffer,
  4311. pBlob->BufferLength,
  4312. pBlob->AvailLength,
  4313. pBlob->pAvailBuffer,
  4314. pBlob->pCurrent,
  4315. pBlob->BytesLeft,
  4316. pBlob->MaxAliasCount,
  4317. pBlob->AliasCount,
  4318. pBlob->MaxAddrCount,
  4319. pBlob->AddrCount,
  4320. pBlob->fWroteName,
  4321. pBlob->fUnicode,
  4322. pBlob->CharSet
  4323. );
  4324. // print the hostent
  4325. if ( pBlob->pHostent )
  4326. {
  4327. DnsPrint_Hostent(
  4328. PrintRoutine,
  4329. pContext,
  4330. NULL,
  4331. pBlob->pHostent,
  4332. pBlob->fUnicode
  4333. );
  4334. }
  4335. DnsPrint_Unlock();
  4336. }
  4337. //
  4338. // End of print.c
  4339. //