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.

4082 lines
89 KiB

  1. /*++
  2. Copyright (c) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. dnslib.h
  5. Abstract:
  6. Domain Name System (DNS) Library
  7. DNS Library Routines -- Main Header File
  8. Author:
  9. Jim Gilroy (jamesg) December 7, 1996
  10. Revision History:
  11. --*/
  12. #ifndef _DNSLIB_INCLUDED_
  13. #define _DNSLIB_INCLUDED_
  14. #include <windns.h>
  15. #include <dnsapi.h>
  16. #include <rpc.h>
  17. #define BACKCOMPAT 1
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif // __cplusplus
  22. //
  23. // Alignment and rounding macros
  24. //
  25. #define WORD_ALIGN(ptr) ((PVOID) ((UINT_PTR)((PBYTE)ptr + 1) & ~(UINT_PTR)1))
  26. #define DWORD_ALIGN(ptr) ((PVOID) ((UINT_PTR)((PBYTE)ptr + 3) & ~(UINT_PTR)3))
  27. #define QWORD_ALIGN(ptr) ((PVOID) ((UINT_PTR)((PBYTE)ptr + 7) & ~(UINT_PTR)7))
  28. #ifdef WIN64
  29. #define POINTER_ALIGN(ptr) QWORD_ALIGN(ptr)
  30. #else
  31. #define POINTER_ALIGN(ptr) DWORD_ALIGN(ptr)
  32. #endif
  33. #define WORD_ALIGN_DWORD(dw) (((WORD)dw + 1) & ~(DWORD)1)
  34. #define DWORD_ALIGN_DWORD(dw) (((DWORD)dw + 3) & ~(DWORD)3)
  35. #define QWORD_ALIGN_DWORD(dw) (((QWORD)dw + 7) & ~(DWORD)7)
  36. #ifdef WIN64
  37. #define POINTER_ALIGN_DWORD(dw) QWORD_ALIGN_DWORD(dw)
  38. #else
  39. #define POINTER_ALIGN_DWORD(dw) DWORD_ALIGN_DWORD(dw)
  40. #endif
  41. //
  42. // Inline byte flipping
  43. //
  44. __inline
  45. WORD
  46. inline_word_flip(
  47. IN WORD Word
  48. )
  49. {
  50. return ( (Word << 8) | (Word >> 8) );
  51. }
  52. #define inline_htons(w) inline_word_flip(w)
  53. #define inline_ntohs(w) inline_word_flip(w)
  54. __inline
  55. DWORD
  56. inline_dword_flip(
  57. IN DWORD Dword
  58. )
  59. {
  60. return ( ((Dword << 8) & 0x00ff0000) |
  61. (Dword << 24) |
  62. ((Dword >> 8) & 0x0000ff00) |
  63. (Dword >> 24) );
  64. }
  65. #define inline_htonl(d) inline_dword_flip(d)
  66. #define inline_ntohl(d) inline_dword_flip(d)
  67. //
  68. // Useful type defs
  69. //
  70. #define PGUID LPGUID
  71. #define PADDRINFO LPADDRINFO
  72. //
  73. // QWORD
  74. //
  75. #ifndef QWORD
  76. typedef DWORD64 QWORD, *PQWORD;
  77. #endif
  78. //
  79. // Until converted must define PDNS_NAME
  80. //
  81. // Note: PDNS_NAME is NOT really a LPTSTR.
  82. // Rather it's the definition of a field that can be
  83. // either an PWSTR or PSTR depending on some other field.
  84. //
  85. #ifdef UNICODE
  86. typedef PWSTR PDNS_NAME;
  87. #else
  88. typedef PSTR PDNS_NAME;
  89. #endif
  90. //
  91. // Flat buffer definition
  92. //
  93. // Note: using INT for sizes so that we can push BytesLeft negative
  94. // and use routines to determine REQUIRED space, even when no
  95. // buffer or buf too small.
  96. //
  97. typedef struct _FLATBUF
  98. {
  99. PBYTE pBuffer;
  100. PBYTE pEnd;
  101. PBYTE pCurrent;
  102. INT Size;
  103. INT BytesLeft;
  104. }
  105. FLATBUF, *PFLATBUF;
  106. //
  107. // Flat buffer routines -- argument versions
  108. //
  109. // These versions have the actual code so that we can
  110. // easily use this stuff with existing code that has
  111. // independent pCurrent and BytesLeft variables.
  112. //
  113. // FLATBUF structure versions just call these inline.
  114. //
  115. PBYTE
  116. FlatBuf_Arg_Reserve(
  117. IN OUT PBYTE * ppCurrent,
  118. IN OUT PINT pBytesLeft,
  119. IN DWORD Size,
  120. IN DWORD Alignment
  121. );
  122. PBYTE
  123. FlatBuf_Arg_WriteString(
  124. IN OUT PBYTE * ppCurrent,
  125. IN OUT PINT pBytesLeft,
  126. IN PSTR pString,
  127. IN BOOL fUnicode
  128. );
  129. PBYTE
  130. FlatBuf_Arg_CopyMemory(
  131. IN OUT PBYTE * ppCurrent,
  132. IN OUT PINT pBytesLeft,
  133. IN PVOID pMemory,
  134. IN DWORD Length,
  135. IN DWORD Alignment
  136. );
  137. __inline
  138. PBYTE
  139. FlatBuf_Arg_ReserveAlignPointer(
  140. IN OUT PBYTE * ppCurrent,
  141. IN OUT PINT pBytesLeft,
  142. IN DWORD Size
  143. )
  144. {
  145. return FlatBuf_Arg_Reserve(
  146. ppCurrent,
  147. pBytesLeft,
  148. Size,
  149. sizeof(PVOID) );
  150. }
  151. __inline
  152. PBYTE
  153. FlatBuf_Arg_ReserveAlignQword(
  154. IN OUT PBYTE * ppCurrent,
  155. IN OUT PINT pBytesLeft,
  156. IN DWORD Size
  157. )
  158. {
  159. return FlatBuf_Arg_Reserve(
  160. ppCurrent,
  161. pBytesLeft,
  162. Size,
  163. sizeof(QWORD) );
  164. }
  165. __inline
  166. PBYTE
  167. FlatBuf_Arg_ReserveAlignDword(
  168. IN OUT PBYTE * ppCurrent,
  169. IN OUT PINT pBytesLeft,
  170. IN DWORD Size
  171. )
  172. {
  173. return FlatBuf_Arg_Reserve(
  174. ppCurrent,
  175. pBytesLeft,
  176. Size,
  177. sizeof(DWORD) );
  178. }
  179. __inline
  180. PBYTE
  181. FlatBuf_Arg_ReserveAlignWord(
  182. IN OUT PBYTE * ppCurrent,
  183. IN OUT PINT pBytesLeft,
  184. IN DWORD Size
  185. )
  186. {
  187. return FlatBuf_Arg_Reserve(
  188. ppCurrent,
  189. pBytesLeft,
  190. Size,
  191. sizeof(WORD) );
  192. }
  193. __inline
  194. PBYTE
  195. FlatBuf_Arg_ReserveAlignByte(
  196. IN OUT PBYTE * ppCurrent,
  197. IN OUT PINT pBytesLeft,
  198. IN DWORD Size
  199. )
  200. {
  201. return FlatBuf_Arg_Reserve(
  202. ppCurrent,
  203. pBytesLeft,
  204. Size,
  205. 0 );
  206. }
  207. PBYTE
  208. __inline
  209. FlatBuf_Arg_WriteString_A(
  210. IN OUT PBYTE * ppCurrent,
  211. IN OUT PINT pBytesLeft,
  212. IN PSTR pString
  213. )
  214. {
  215. return FlatBuf_Arg_WriteString(
  216. ppCurrent,
  217. pBytesLeft,
  218. pString,
  219. FALSE // not unicode
  220. );
  221. }
  222. PBYTE
  223. __inline
  224. FlatBuf_Arg_WriteString_W(
  225. IN OUT PBYTE * ppCurrent,
  226. IN OUT PINT pBytesLeft,
  227. IN PWSTR pString
  228. )
  229. {
  230. return FlatBuf_Arg_WriteString(
  231. ppCurrent,
  232. pBytesLeft,
  233. (PSTR) pString,
  234. TRUE // unicode
  235. );
  236. }
  237. //
  238. // Flat buffer routines -- structure versions
  239. //
  240. VOID
  241. FlatBuf_Init(
  242. IN OUT PFLATBUF pFlatBuf,
  243. IN PBYTE pBuffer,
  244. IN INT Size
  245. );
  246. __inline
  247. PBYTE
  248. FlatBuf_Reserve(
  249. IN OUT PFLATBUF pBuf,
  250. IN DWORD Size,
  251. IN DWORD Alignment
  252. )
  253. {
  254. return FlatBuf_Arg_Reserve(
  255. & pBuf->pCurrent,
  256. & pBuf->BytesLeft,
  257. Size,
  258. Alignment );
  259. }
  260. __inline
  261. PBYTE
  262. FlatBuf_ReserveAlignPointer(
  263. IN OUT PFLATBUF pBuf,
  264. IN DWORD Size
  265. )
  266. {
  267. return FlatBuf_Arg_Reserve(
  268. & pBuf->pCurrent,
  269. & pBuf->BytesLeft,
  270. Size,
  271. sizeof(PVOID) );
  272. }
  273. __inline
  274. PBYTE
  275. FlatBuf_ReserveAlignQword(
  276. IN OUT PFLATBUF pBuf,
  277. IN DWORD Size
  278. )
  279. {
  280. return FlatBuf_Arg_Reserve(
  281. & pBuf->pCurrent,
  282. & pBuf->BytesLeft,
  283. Size,
  284. sizeof(QWORD) );
  285. }
  286. __inline
  287. PBYTE
  288. FlatBuf_ReserveAlignDword(
  289. IN OUT PFLATBUF pBuf,
  290. IN DWORD Size
  291. )
  292. {
  293. return FlatBuf_Arg_Reserve(
  294. & pBuf->pCurrent,
  295. & pBuf->BytesLeft,
  296. Size,
  297. sizeof(DWORD) );
  298. }
  299. __inline
  300. PBYTE
  301. FlatBuf_ReserveAlignWord(
  302. IN OUT PFLATBUF pBuf,
  303. IN DWORD Size
  304. )
  305. {
  306. return FlatBuf_Arg_Reserve(
  307. & pBuf->pCurrent,
  308. & pBuf->BytesLeft,
  309. Size,
  310. sizeof(WORD) );
  311. }
  312. __inline
  313. PBYTE
  314. FlatBuf_ReserveAlignByte(
  315. IN OUT PFLATBUF pBuf,
  316. IN DWORD Size
  317. )
  318. {
  319. return FlatBuf_Arg_Reserve(
  320. & pBuf->pCurrent,
  321. & pBuf->BytesLeft,
  322. Size,
  323. 0 );
  324. }
  325. PBYTE
  326. __inline
  327. FlatBuf_WriteString(
  328. IN OUT PFLATBUF pBuf,
  329. IN PSTR pString,
  330. IN BOOL fUnicode
  331. )
  332. {
  333. return FlatBuf_Arg_WriteString(
  334. & pBuf->pCurrent,
  335. & pBuf->BytesLeft,
  336. pString,
  337. fUnicode
  338. );
  339. }
  340. PBYTE
  341. __inline
  342. FlatBuf_WriteString_A(
  343. IN OUT PFLATBUF pBuf,
  344. IN PSTR pString
  345. )
  346. {
  347. return FlatBuf_Arg_WriteString(
  348. & pBuf->pCurrent,
  349. & pBuf->BytesLeft,
  350. pString,
  351. FALSE // not unicode
  352. );
  353. }
  354. PBYTE
  355. __inline
  356. FlatBuf_WriteString_W(
  357. IN OUT PFLATBUF pBuf,
  358. IN PWSTR pString
  359. )
  360. {
  361. return FlatBuf_Arg_WriteString(
  362. & pBuf->pCurrent,
  363. & pBuf->BytesLeft,
  364. (PSTR) pString,
  365. TRUE // unicode
  366. );
  367. }
  368. PBYTE
  369. __inline
  370. FlatBuf_CopyMemory(
  371. IN OUT PFLATBUF pBuf,
  372. IN PVOID pMemory,
  373. IN DWORD Length,
  374. IN DWORD Alignment
  375. )
  376. {
  377. return FlatBuf_Arg_CopyMemory(
  378. & pBuf->pCurrent,
  379. & pBuf->BytesLeft,
  380. pMemory,
  381. Length,
  382. Alignment );
  383. }
  384. //
  385. // Multicast off until new features ready
  386. //
  387. #define MULTICAST_ENABLED 0
  388. //
  389. // Multicast DNS definitions
  390. //
  391. #define MULTICAST_DNS_ADDR 0xEFFFFFFD // 239.255.255.253
  392. #define MULTICAST_DNS_RADDR 0xFDFFFFEF // Same as above, in host ordering
  393. #define MULTICAST_DNS_LOCAL_DOMAIN ("local.")
  394. #define MULTICAST_DNS_LOCAL_DOMAIN_W (L"local.")
  395. #define MULTICAST_DNS_SRV_RECORD_NAME ("_dns._udp.local.")
  396. #define MULTICAST_DNS_SRV_RECORD_NAME_W (L"_dns._udp.local.")
  397. #define MULTICAST_DNS_A_RECORD_NAME ("_dns.local.")
  398. #define MULTICAST_DNS_A_RECORD_NAME_W (L"_dns.local.")
  399. //
  400. // Read unaligned value from given position in packet
  401. //
  402. #define READ_PACKET_HOST_DWORD(pch) \
  403. FlipUnalignedDword( pch )
  404. #define READ_PACKET_NET_DWORD(pch) \
  405. ( *(UNALIGNED DWORD *)(pch) )
  406. #define READ_PACKET_HOST_WORD(pch) \
  407. FlipUnalignedWord( pch )
  408. #define READ_PACKET_NET_WORD(pch) \
  409. ( *(UNALIGNED WORD *)(pch) )
  410. //
  411. // Private DNS_RECORD Flag field structure definition and macros
  412. //
  413. // Note: don't add to this list -- private stuff in dnslibp.h
  414. //
  415. typedef struct _DnsRecordLibFlags
  416. {
  417. DWORD Section : 2;
  418. DWORD Delete : 1;
  419. DWORD CharSet : 2;
  420. DWORD Unused : 6;
  421. DWORD Matched : 1;
  422. DWORD FreeData : 1;
  423. DWORD FreeOwner : 1;
  424. DWORD Reserved : 18;
  425. }
  426. DNSRECLIB_FLAGS, *PDNSRECLIB_FLAGS;
  427. #define PFLAGS( pRecord ) ((PDNSRECLIB_FLAGS)&pRecord->Flags.DW)
  428. #define FLAG_Section( pRecord ) (PFLAGS( pRecord )->Section)
  429. #define FLAG_Delete( pRecord ) (PFLAGS( pRecord )->Delete)
  430. #define FLAG_CharSet( pRecord ) (PFLAGS( pRecord )->CharSet)
  431. #define FLAG_FreeData( pRecord ) (PFLAGS( pRecord )->FreeData)
  432. #define FLAG_FreeOwner( pRecord ) (PFLAGS( pRecord )->FreeOwner)
  433. #define FLAG_Matched( pRecord ) (PFLAGS( pRecord )->Matched)
  434. #define SET_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR) = TRUE)
  435. #define SET_FREE_DATA(pRR) (FLAG_FreeData(pRR) = TRUE)
  436. #define SET_RR_MATCHED(pRR) (FLAG_Matched(pRR) = TRUE)
  437. #define CLEAR_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR) = FALSE)
  438. #define CLEAR_FREE_DATA(pRR) (FLAG_FreeData(pRR) = FALSE)
  439. #define CLEAR_RR_MATCHED(pRR) (FLAG_Matched(pRR) = FALSE)
  440. #define IS_FREE_OWNER(pRR) (FLAG_FreeOwner(pRR))
  441. #define IS_FREE_DATA(pRR) (FLAG_FreeData(pRR))
  442. #define IS_RR_MATCHED(pRR) (FLAG_Matched(pRR))
  443. #define IS_ANSWER_RR(pRR) (FLAG_Section(pRR) == DNSREC_ANSWER)
  444. #define IS_AUTHORITY_RR(pRR) (FLAG_Section(pRR) == DNSREC_AUTHORITY)
  445. #define IS_ADDITIONAL_RR(pRR) (FLAG_Section(pRR) == DNSREC_ADDITIONAL)
  446. //
  447. // Converting RCODEs to\from DNS errors.
  448. //
  449. #define DNS_ERROR_FROM_RCODE(rcode) ((rcode)+DNS_ERROR_RESPONSE_CODES_BASE)
  450. #define DNS_RCODE_FROM_ERROR(err) ((err)-DNS_ERROR_RESPONSE_CODES_BASE)
  451. //
  452. // Record character sets
  453. //
  454. // Currently supports records in three character sets
  455. // - unicode
  456. // - ANSI
  457. // - UTF8
  458. //
  459. // Unicode and ANSI are supported through external DNSAPI interfaces.
  460. // UTF8 is not (at least offcially).
  461. //
  462. // However, internally unicode and UTF8 are used for caching, reading
  463. // to and writing from packet.
  464. //
  465. // All DNS_RECORD structs created by our code, are tagged with a
  466. // character set type in the flags CharSet field.
  467. //
  468. //
  469. // A couple of handy macros:
  470. //
  471. #define RECORD_CHARSET(pRR) \
  472. ( (DNS_CHARSET) (pRR)->Flags.S.CharSet )
  473. #define IS_UNICODE_RECORD(pRR) \
  474. ( (DNS_CHARSET) (pRR)->Flags.S.CharSet == DnsCharSetUnicode )
  475. //
  476. // Quick buffer size determination
  477. //
  478. // Strings are read from the wire into dotted UTF8 format.
  479. // Strings are in UTF8 in RPC buffers.
  480. //
  481. // Goal here is to quickly determine adequate buffer size,
  482. // slight overallocation is not critical.
  483. //
  484. // Currently supporting only UTF8 or Unicode, however, if later
  485. // support direct ANSI conversion that's ok too, as ANSI will
  486. // no (to my knowledge) use more space than UTF8.
  487. //
  488. #define STR_BUF_SIZE_GIVEN_UTF8_LEN( Utf8Length, CharSet ) \
  489. ( ((CharSet)==DnsCharSetUnicode) ? ((Utf8Length)+1)*2 : (Utf8Length)+1 )
  490. //
  491. // Default locale for string comparison and case mappings
  492. //
  493. // Sublang: US English (0x04) Lang: English (0x09)
  494. //
  495. #define DNS_DEFAULT_LOCALE (0x0409)
  496. //
  497. // IP Array utilities (iparray.c)
  498. //
  499. // Note some of these require memory allocation, see note
  500. // on memory allocation below.
  501. //
  502. #define DNS_NET_ORDER_LOOPBACK (0x0100007f)
  503. // NT5-autonet is 169.254.x.y
  504. #define AUTONET_MASK (0x0000ffff)
  505. #define AUTONET_NET (0x0000fea9)
  506. #define DNS_IS_AUTONET_IP(ip) ( ((ip) & AUTONET_MASK) == AUTONET_NET )
  507. #define DNS_IPARRAY_CLEAN_ZERO (0x00000001)
  508. #define DNS_IPARRAY_CLEAN_LOOPBACK (0x00000002)
  509. #define DNS_IPARRAY_CLEAN_AUTONET (0x00000010)
  510. //
  511. // Simple IP address array routines
  512. //
  513. PIP_ADDRESS
  514. Dns_CreateIpAddressArrayCopy(
  515. IN PIP_ADDRESS aipAddress,
  516. IN DWORD cipAddress
  517. );
  518. BOOL
  519. Dns_ValidateIpAddressArray(
  520. IN PIP_ADDRESS aipAddress,
  521. IN DWORD cipAddress,
  522. IN DWORD dwFlag
  523. );
  524. //
  525. // IP_ARRAY datatype routines
  526. //
  527. PIP_ARRAY
  528. Dns_CreateIpArray(
  529. IN DWORD cAddrCount
  530. );
  531. DWORD
  532. Dns_SizeofIpArray(
  533. IN PIP_ARRAY pIpArray
  534. );
  535. PIP_ARRAY
  536. Dns_BuildIpArray(
  537. IN DWORD cAddrCount,
  538. IN PIP_ADDRESS pipAddrs
  539. );
  540. PIP_ARRAY
  541. Dns_CopyAndExpandIpArray(
  542. IN PIP_ARRAY pIpArray,
  543. IN DWORD ExpandCount,
  544. IN BOOL fDeleteExisting
  545. );
  546. PIP_ARRAY
  547. Dns_CreateIpArrayCopy(
  548. IN PIP_ARRAY pIpArray
  549. );
  550. BOOL
  551. Dns_IsAddressInIpArray(
  552. IN PIP_ARRAY pIpArray,
  553. IN IP_ADDRESS ipAddress
  554. );
  555. BOOL
  556. Dns_AddIpToIpArray(
  557. IN OUT PIP_ARRAY pIpArray,
  558. IN IP_ADDRESS ipNew
  559. );
  560. VOID
  561. Dns_ClearIpArray(
  562. IN OUT PIP_ARRAY pIpArray
  563. );
  564. VOID
  565. Dns_ReverseOrderOfIpArray(
  566. IN OUT PIP_ARRAY pIpArray
  567. );
  568. BOOL
  569. Dns_CheckAndMakeIpArraySubset(
  570. IN OUT PIP_ARRAY pIpArraySub,
  571. IN PIP_ARRAY pIpArraySuper
  572. );
  573. INT
  574. WINAPI
  575. Dns_ClearIpFromIpArray(
  576. IN OUT PIP_ARRAY pIpArray,
  577. IN IP_ADDRESS IpDelete
  578. );
  579. INT
  580. WINAPI
  581. Dns_DeleteIpFromIpArray(
  582. IN OUT PIP_ARRAY pIpArray,
  583. IN IP_ADDRESS IpDelete
  584. );
  585. #define Dns_RemoveZerosFromIpArray(pArray) \
  586. Dns_DeleteIpFromIpArray( (pArray), 0 )
  587. INT
  588. WINAPI
  589. Dns_CleanIpArray(
  590. IN OUT PIP_ARRAY pIpArray,
  591. IN DWORD Flag
  592. );
  593. BOOL
  594. Dns_AreIpArraysEqual(
  595. IN PIP_ARRAY pIpArray1,
  596. IN PIP_ARRAY pIpArray2
  597. );
  598. BOOL
  599. Dns_AreIpArraysSimilar(
  600. IN PIP_ARRAY pIpArray1,
  601. IN PIP_ARRAY pIpArray2
  602. );
  603. DNS_STATUS
  604. WINAPI
  605. Dns_DiffOfIpArrays(
  606. IN PIP_ARRAY pIpArray1,
  607. IN PIP_ARRAY pIpArray2,
  608. OUT PIP_ARRAY * ppOnlyIn1,
  609. OUT PIP_ARRAY * ppOnlyIn2,
  610. OUT PIP_ARRAY * ppIntersect
  611. );
  612. BOOL
  613. WINAPI
  614. Dns_IsIntersectionOfIpArrays(
  615. IN PIP_ARRAY pIpArray1,
  616. IN PIP_ARRAY pIpArray2
  617. );
  618. DNS_STATUS
  619. WINAPI
  620. Dns_UnionOfIpArrays(
  621. IN PIP_ARRAY pIpArray1,
  622. IN PIP_ARRAY pIpArray2,
  623. OUT PIP_ARRAY * ppUnion
  624. );
  625. #define Dns_IntersectionOfIpArrays(p1, p2, ppInt) \
  626. Dns_DiffOfIpArrays( (p1), (p2), NULL, NULL, (ppInt) )
  627. DNS_STATUS
  628. Dns_CreateIpArrayFromMultiIpString(
  629. IN PSTR pchMultiIpString,
  630. OUT PIP_ARRAY * ppIpArray
  631. );
  632. PSTR
  633. Dns_CreateMultiIpStringFromIpArray(
  634. IN PIP_ARRAY pIpArray,
  635. IN CHAR chSeparator OPTIONAL
  636. );
  637. //
  638. // Type list array routines
  639. //
  640. DNS_STATUS
  641. Dns_CreateTypeArrayFromMultiTypeString(
  642. IN PSTR pchMultiTypeString,
  643. OUT INT * piTypeCount,
  644. OUT PWORD * ppwTypeArray
  645. );
  646. PSTR
  647. Dns_CreateMultiTypeStringFromTypeArray(
  648. IN INT iTypeCount,
  649. IN PWORD ppwTypeArray,
  650. IN CHAR chSeparator OPTIONAL
  651. );
  652. //
  653. // General utilities
  654. //
  655. //
  656. // Wrap free, multi-thread safe seconds timer (timer.c)
  657. //
  658. VOID
  659. Dns_InitializeSecondsTimer(
  660. VOID
  661. );
  662. DWORD
  663. Dns_GetCurrentTimeInSeconds(
  664. VOID
  665. );
  666. //
  667. // Tokenizer
  668. //
  669. DWORD
  670. Dns_TokenizeString(
  671. IN OUT PSTR pBuffer,
  672. OUT PCHAR * Argv,
  673. IN DWORD MaxArgs
  674. );
  675. //
  676. // IP interfaces on local machine (iplist.c)
  677. //
  678. #define DNS_MAX_NAME_SERVERS (50)
  679. #define DNS_MAX_IP_INTERFACE_COUNT (10000)
  680. DWORD
  681. Dns_GetIpAddresses(
  682. IN OUT PDNS_ADDRESS_INFO IpAddressInfoList,
  683. IN DWORD ListCount
  684. );
  685. PIP_ARRAY
  686. Dns_GetLocalIpAddressArray(
  687. VOID
  688. );
  689. //
  690. // IP interfaces on local machine (iplist4.c)
  691. //
  692. DWORD
  693. Dns_GetIpAddressesNT4(
  694. IN OUT PDNS_ADDRESS_INFO IpAddressInfoList,
  695. IN DWORD ListCount
  696. );
  697. //
  698. // IP interfaces on local machine (iplist9x.c)
  699. //
  700. DWORD
  701. Dns_GetIpAddressesWin9X(
  702. IN OUT PDNS_ADDRESS_INFO IpAddressInfoList,
  703. IN DWORD ListCount
  704. );
  705. //
  706. // DNS server list routines (servlist.c)
  707. //
  708. // Also includes default domain and search list information.
  709. //
  710. #define DNS_FLAG_IGNORE_ADAPTER (0x00000001)
  711. #define DNS_FLAG_IS_WAN_ADAPTER (0x00000002)
  712. #define DNS_FLAG_IS_AUTONET_ADAPTER (0x00000004)
  713. #define DNS_FLAG_IS_DHCP_CFG_ADAPTER (0x00000008)
  714. #define DNS_FLAG_REGISTER_DOMAIN_NAME (0x00000010)
  715. #define DNS_FLAG_REGISTER_IP_ADDRESSES (0x00000020)
  716. #define DNS_FLAG_ALLOW_MULTICAST (0x00000100)
  717. #define DNS_FLAG_MULTICAST_ON_NAME_ERROR (0x00000200)
  718. #define DNS_FLAG_AUTO_SERVER_DETECTED (0x00000400)
  719. #define DNS_FLAG_DUMMY_SEARCH_LIST (0x00000800)
  720. #define DNS_FLAG_SERVERS_UNREACHABLE (0x00010000)
  721. //
  722. // NetInfo structures
  723. //
  724. // WARNING: Do NOT use these!
  725. //
  726. // These are internal dnsapi.dll structures. They are only
  727. // included here for backward compatibility with previous
  728. // code (netdiag) which incorrectly used these.
  729. //
  730. // If you code with them you will inevitably wake up broken
  731. // down the road.
  732. //
  733. //#ifdef _DNSLIB_NETINFO_
  734. typedef struct
  735. {
  736. DNS_STATUS Status;
  737. DWORD Priority;
  738. IP_ADDRESS IpAddress;
  739. DWORD Reserved[3];
  740. }
  741. DNSLIB_SERVER_INFO, *PDNSLIB_SERVER_INFO;
  742. typedef struct
  743. {
  744. PSTR pszAdapterGuidName;
  745. PSTR pszAdapterDomain;
  746. PIP_ARRAY pAdapterIPAddresses;
  747. PIP_ARRAY pAdapterIPSubnetMasks;
  748. DWORD InterfaceIndex;
  749. DWORD InfoFlags;
  750. DWORD Reserved;
  751. DWORD Status;
  752. DWORD ReturnFlags;
  753. DWORD IpLastSend;
  754. DWORD cServerCount;
  755. DWORD cTotalListSize;
  756. DNSLIB_SERVER_INFO ServerArray[1];
  757. }
  758. DNSLIB_ADAPTER, *PDNSLIB_ADAPTER;
  759. #define DNS_MAX_SEARCH_LIST_ENTRIES (50)
  760. typedef struct
  761. {
  762. PSTR pszName;
  763. DWORD Flags;
  764. }
  765. DNSLIB_SEARCH_NAME, *PDNSLIB_SEARCH_NAME;
  766. typedef struct
  767. {
  768. PSTR pszDomainOrZoneName;
  769. DWORD cNameCount; // Zero for FindAuthoritativeZone
  770. DWORD cTotalListSize; // Zero for FindAuthoritativeZone
  771. DWORD CurrentName; // 0 for pszDomainOrZoneName
  772. // 1 for first name in array below
  773. // 2 for second name in array below
  774. // ...
  775. DNSLIB_SEARCH_NAME SearchNameArray[1];
  776. }
  777. DNSLIB_SEARCH_LIST, *PDNSLIB_SEARCH_LIST;
  778. typedef struct
  779. {
  780. PSTR pszDomainName;
  781. PSTR pszHostName;
  782. PDNSLIB_SEARCH_LIST pSearchList;
  783. DWORD TimeStamp;
  784. DWORD InfoFlags;
  785. DWORD Tag;
  786. DWORD ReturnFlags;
  787. DWORD cAdapterCount;
  788. DWORD cTotalListSize;
  789. PDNSLIB_ADAPTER AdapterArray[1];
  790. }
  791. DNSLIB_NETINFO, *PDNSLIB_NETINFO;
  792. //
  793. // Create correct internal\external definitions
  794. //
  795. #ifdef DNSAPI_INTERNAL
  796. typedef RPC_DNS_SERVER_INFO DNS_SERVER_INFO, *PDNS_SERVER_INFO;
  797. typedef RPC_DNS_ADAPTER DNS_ADAPTER, *PDNS_ADAPTER;
  798. typedef RPC_SEARCH_NAME SEARCH_NAME, *PSEARCH_NAME;
  799. typedef RPC_SEARCH_LIST SEARCH_LIST, *PSEARCH_LIST;
  800. typedef RPC_DNS_NETINFO DNS_NETINFO, *PDNS_NETINFO;
  801. #else // external
  802. typedef DNSLIB_SERVER_INFO DNS_SERVER_INFO, *PDNS_SERVER_INFO;
  803. typedef DNSLIB_ADAPTER DNS_ADAPTER, *PDNS_ADAPTER;
  804. typedef DNSLIB_SEARCH_NAME SEARCH_NAME, *PSEARCH_NAME;
  805. typedef DNSLIB_SEARCH_LIST SEARCH_LIST, *PSEARCH_LIST;
  806. typedef DNSLIB_NETINFO DNS_NETINFO, *PDNS_NETINFO;
  807. #endif
  808. //
  809. // NetInfo routines (should be private)
  810. //
  811. // But currently used in netdiag and nslookup
  812. // (nslookup problem is simply getting isolation
  813. // in header file)
  814. //
  815. BOOL
  816. Dns_IsUpdateNetworkInfo(
  817. IN PDNS_NETINFO pNetInfo
  818. );
  819. //
  820. // General DNS utilities (dnsutil.c)
  821. //
  822. IP_ADDRESS
  823. Dns_GetNetworkMask(
  824. IN IP_ADDRESS ipAddress
  825. );
  826. PSTR
  827. _fastcall
  828. Dns_StatusString(
  829. IN DNS_STATUS Status
  830. );
  831. #define Dns_StatusToErrorString_A(status) Dns_StatusString(status)
  832. DNS_STATUS
  833. _fastcall
  834. Dns_MapRcodeToStatus(
  835. IN BYTE ResponseCode
  836. );
  837. BYTE
  838. _fastcall
  839. Dns_IsStatusRcode(
  840. IN DNS_STATUS Status
  841. );
  842. //
  843. // Name utilities (name.c)
  844. //
  845. PSTR
  846. _fastcall
  847. Dns_GetDomainName(
  848. IN PCSTR pszName
  849. );
  850. PWSTR
  851. _fastcall
  852. Dns_GetDomainName_W(
  853. IN PCWSTR pwsName
  854. );
  855. PCHAR
  856. _fastcall
  857. Dns_GetTldForName(
  858. IN PCSTR pszName
  859. );
  860. BOOL
  861. _fastcall
  862. Dns_IsNameShort(
  863. IN PCSTR pszName
  864. );
  865. BOOL
  866. _fastcall
  867. Dns_IsNameFQDN(
  868. IN PCSTR pszName
  869. );
  870. DNS_STATUS
  871. Dns_ValidateAndCategorizeDnsNameEx(
  872. IN PCHAR pchName,
  873. IN DWORD cchNameLength,
  874. OUT PDWORD pLabelCount
  875. );
  876. #define Dns_ValidateAndCategorizeDnsName(p,c) \
  877. Dns_ValidateAndCategorizeDnsNameEx((p),(c),NULL)
  878. DWORD
  879. Dns_NameLabelCount(
  880. IN PCSTR pszName
  881. );
  882. #define DNS_NAME_UNKNOWN 0x00000000
  883. #define DNS_NAME_IS_FQDN 0x00000001
  884. #define DNS_NAME_SINGLE_LABEL 0x00000010
  885. #define DNS_NAME_MULTI_LABEL 0x00000100
  886. DWORD
  887. _fastcall
  888. Dns_GetNameAttributes(
  889. IN PCSTR pszName
  890. );
  891. //
  892. // Packet create\read\write (packet.c)
  893. //
  894. //
  895. // UDP packet buffer
  896. //
  897. // 1472 is the maximum ethernet IP\UDP payload size
  898. // without causing fragmentation, use as default buffer
  899. //
  900. #define DNS_MAX_UDP_PACKET_BUFFER_LENGTH (1472)
  901. // parsing RR
  902. // convenient to get WIRE records into aligned\host order format
  903. typedef struct _DNS_PARSED_RR
  904. {
  905. PCHAR pchName;
  906. PCHAR pchRR;
  907. PCHAR pchData;
  908. PCHAR pchNextRR;
  909. // note from here on down mimics wire record
  910. WORD Type;
  911. WORD Class;
  912. DWORD Ttl;
  913. WORD DataLength;
  914. }
  915. DNS_PARSED_RR, *PDNS_PARSED_RR;
  916. //
  917. // DNS Server Message Info structure
  918. //
  919. // This is structure in which requests are held while being
  920. // processed by the DNS server.
  921. //
  922. //
  923. // Sockaddr big enough for either IP4 or IP6
  924. //
  925. // DCR: make length field part of our sockaddr?
  926. //
  927. #define SIZE_IP6_SOCKADDR_DNS_PRIVATE (28)
  928. typedef union _DnsSockaddr
  929. {
  930. SOCKADDR_IN In4;
  931. #ifdef _WS2TCPIP_H_
  932. SOCKADDR_IN6 In6;
  933. #else
  934. BYTE In6[28];
  935. #endif
  936. }
  937. SOCKADDR_DNS, *PSOCKADDR_DNS;
  938. typedef struct _DnsMessageBuf
  939. {
  940. LIST_ENTRY ListEntry; // for queuing
  941. //
  942. // Addressing
  943. //
  944. SOCKET Socket;
  945. INT RemoteAddressLength;
  946. //16
  947. //SOCKADDR_IN RemoteAddress;
  948. SOCKADDR_DNS RemoteAddress;
  949. //
  950. // Basic packet info
  951. //
  952. //32
  953. DWORD BufferLength; // total length of buffer
  954. PCHAR pBufferEnd; // ptr to byte after buffer
  955. PBYTE pCurrent; // current location in buffer
  956. PWORD pCurrentCountField; // current count field being written
  957. //
  958. // Current lookup info
  959. //
  960. // 48
  961. DWORD Timeout; // recv timeout
  962. DWORD QueryTime; // time of original query
  963. WORD wTypeCurrent; // type of query being done
  964. WORD wOffsetCurrent;
  965. //
  966. // Queuing
  967. //
  968. WORD wQueuingXid; // match XID to response
  969. //64
  970. DWORD QueuingTime; // time queued
  971. DWORD ExpireTime; // queue timeout
  972. //
  973. // Basic packet flags
  974. //
  975. BOOLEAN fTcp;
  976. BOOLEAN fSwapped; // header in net order
  977. BOOLEAN fMessageComplete; // complete message received
  978. BOOLEAN fConvertUnicode; // convert to unicode
  979. BOOLEAN fSocketKeepalive; // keep socket alive
  980. BOOLEAN fLastSendOpt; // last send contained OPT
  981. //
  982. // TCP message reception
  983. //
  984. //80
  985. PCHAR pchRecv; // ptr to next pos in message
  986. //
  987. // End of message before OPT addition
  988. //
  989. PCHAR pPreOptEnd;
  990. //
  991. // WARNING !
  992. //
  993. // Message length MUST
  994. // - be a WORD type
  995. // - immediately preceed message itself
  996. // for proper send/recv of TCP messages.
  997. //
  998. // Use pointers above to DWORD (or QWORD) align, then recv bytes to push
  999. // message length against MessageHead. Note, that DNS_HEADER contains
  1000. // only WORDs as it's largest element and so should chummy up even on
  1001. // WORD boundary. DWORD boundary should be very safe.
  1002. //
  1003. //96
  1004. WORD BytesToReceive;
  1005. WORD MessageLength;
  1006. //
  1007. // DNS Message itself
  1008. //
  1009. DNS_HEADER MessageHead;
  1010. //
  1011. // Question and RR section
  1012. //
  1013. // This simply provides some coding simplicity in accessing
  1014. // this section given MESSAGE_INFO structure.
  1015. //
  1016. CHAR MessageBody[1];
  1017. }
  1018. DNS_MSG_BUF, *PDNS_MSG_BUF;
  1019. #define SIZEOF_MSG_BUF_OVERHEAD (sizeof(DNS_MSG_BUF) - sizeof(DNS_HEADER) - 1)
  1020. #define DNS_MESSAGE_END(pMsg) \
  1021. ((PCHAR)&(pMsg)->MessageHead + (pMsg)->MessageLength)
  1022. #define DNS_MESSAGE_OFFSET( pMsg, p ) \
  1023. ((PCHAR)(p) - (PCHAR)(&(pMsg)->MessageHead))
  1024. #define DNS_MESSAGE_CURRENT_OFFSET( pMsg ) \
  1025. DNS_MESSAGE_OFFSET( (pMsg), (pMsg)->pCurrent )
  1026. //
  1027. // Handy for packet setup
  1028. //
  1029. #define CLEAR_DNS_HEADER_FLAGS_AND_XID( pHead ) ( *(PDWORD)(pHead) = 0 )
  1030. PDNS_MSG_BUF
  1031. Dns_AllocateMsgBuf(
  1032. IN WORD wBufferLength OPTIONAL
  1033. );
  1034. VOID
  1035. Dns_InitializeMsgBuf(
  1036. IN OUT PDNS_MSG_BUF pMsg
  1037. );
  1038. PDNS_MSG_BUF
  1039. Dns_BuildPacket(
  1040. IN PDNS_HEADER pHeader,
  1041. IN BOOL fNoHeaderCounts,
  1042. IN PDNS_NAME pszQuestionName,
  1043. IN WORD wQuestionType,
  1044. IN PDNS_RECORD pRecord,
  1045. IN DWORD dwFlags,
  1046. IN BOOL fUpdatePacket
  1047. );
  1048. PCHAR
  1049. _fastcall
  1050. Dns_WriteDottedNameToPacket(
  1051. IN OUT PCHAR pch,
  1052. IN PCHAR pchStop,
  1053. IN PSTR pszName,
  1054. IN PSTR pszDomain, OPTIONAL
  1055. IN WORD wDomainOffset, OPTIONAL
  1056. IN BOOL fUnicodeName
  1057. );
  1058. PCHAR
  1059. _fastcall
  1060. Dns_WriteStringToPacket(
  1061. IN OUT PCHAR pch,
  1062. IN PCHAR pchStop,
  1063. IN PSTR pszString,
  1064. IN BOOL fUnicodeString
  1065. );
  1066. PCHAR
  1067. Dns_WriteQuestionToMessage(
  1068. IN OUT PDNS_MSG_BUF pMsg,
  1069. IN PDNS_NAME pszName,
  1070. IN WORD wType,
  1071. IN BOOL fUnicodeName
  1072. );
  1073. DNS_STATUS
  1074. Dns_WriteRecordStructureToMessage(
  1075. IN OUT PDNS_MSG_BUF pMsg,
  1076. IN WORD wType,
  1077. IN WORD wClass,
  1078. IN DWORD dwTtl,
  1079. IN WORD wDataLength
  1080. );
  1081. PCHAR
  1082. Dns_WriteRecordStructureToPacketEx(
  1083. IN OUT PCHAR pchBuf,
  1084. IN WORD wType,
  1085. IN WORD wClass,
  1086. IN DWORD dwTtl,
  1087. IN WORD wDataLength
  1088. );
  1089. DNS_STATUS
  1090. Dns_WriteRecordStructureToPacket(
  1091. IN OUT PCHAR pchBuf,
  1092. IN PDNS_RECORD pRecord,
  1093. IN BOOL fUpdatePacket
  1094. );
  1095. VOID
  1096. Dns_SetRecordDatalength(
  1097. IN OUT PDNS_WIRE_RECORD pRecord,
  1098. IN WORD wDataLength
  1099. );
  1100. DNS_STATUS
  1101. Dns_AddRecordsToMessage(
  1102. IN OUT PDNS_MSG_BUF pMsg,
  1103. IN PDNS_RECORD pRecord,
  1104. IN BOOL fUpdateMessage
  1105. );
  1106. PCHAR
  1107. _fastcall
  1108. Dns_SkipPacketName(
  1109. IN PCHAR pch,
  1110. IN PCHAR pchEnd
  1111. );
  1112. BOOL
  1113. Dns_IsSamePacketQuestion(
  1114. IN PDNS_MSG_BUF pMsg1,
  1115. IN PDNS_MSG_BUF pMsg2
  1116. );
  1117. PCHAR
  1118. _fastcall
  1119. Dns_SkipPacketRecord(
  1120. IN PCHAR pchRecord,
  1121. IN PCHAR pchMsgEnd
  1122. );
  1123. PCHAR
  1124. Dns_SkipToRecord(
  1125. IN PDNS_HEADER pMsgHead,
  1126. IN PCHAR pMsgEnd,
  1127. IN INT iCount
  1128. );
  1129. PCHAR
  1130. Dns_ReadRecordStructureFromPacket(
  1131. IN PCHAR pchPacket,
  1132. IN PCHAR pchMsgEnd,
  1133. IN OUT PDNS_PARSED_RR pParsedRR
  1134. );
  1135. DNS_STATUS
  1136. Dns_ExtractRecordsFromMessage(
  1137. IN PDNS_MSG_BUF pMsg,
  1138. IN BOOL fUnicode,
  1139. OUT PDNS_RECORD * ppRecord
  1140. );
  1141. DNS_STATUS
  1142. Dns_ExtractRecordsFromBuffer(
  1143. IN PDNS_MESSAGE_BUFFER pDnsBuffer,
  1144. IN WORD wMessageLength,
  1145. IN BOOL fUnicode,
  1146. OUT PDNS_RECORD * ppRecord
  1147. );
  1148. void
  1149. Dns_NormalizeAllRecordTtls(
  1150. IN PDNS_RECORD pRecord
  1151. );
  1152. PCHAR
  1153. _fastcall
  1154. Dns_ReadPacketName(
  1155. IN OUT PCHAR pchNameBuffer,
  1156. OUT PWORD pwNameLength,
  1157. IN OUT PWORD pwNameOffset, OPTIONAL
  1158. OUT PBOOL pfNameSameAsPrevious, OPTIONAL
  1159. IN PCHAR pchName,
  1160. IN PCHAR pchStart,
  1161. IN PCHAR pchEnd
  1162. );
  1163. PCHAR
  1164. _fastcall
  1165. Dns_ReadPacketNameAllocate(
  1166. IN OUT PCHAR * ppchName,
  1167. OUT PWORD pwNameLength,
  1168. IN OUT PWORD pwPrevNameOffset, OPTIONAL
  1169. OUT PBOOL pfNameSameAsPrevious, OPTIONAL
  1170. IN PCHAR pchPacketName,
  1171. IN PCHAR pchStart,
  1172. IN PCHAR pchEnd
  1173. );
  1174. WORD
  1175. Dns_GetRandomXid(
  1176. IN PVOID pSeed
  1177. );
  1178. //
  1179. // Socket setup (socket.c)
  1180. //
  1181. //
  1182. // these two routines really don't belong here -- system stuff should be elsewhere
  1183. //
  1184. DNS_STATUS
  1185. Dns_InitializeWinsock(
  1186. VOID
  1187. );
  1188. VOID
  1189. Dns_CleanupWinsock(
  1190. VOID
  1191. );
  1192. SOCKET
  1193. Dns_CreateSocket(
  1194. IN INT SockType,
  1195. IN IP_ADDRESS ipAddress,
  1196. IN USHORT Port
  1197. );
  1198. SOCKET
  1199. Dns_CreateMulticastSocket(
  1200. IN INT SockType,
  1201. IN IP_ADDRESS ipAddress,
  1202. IN USHORT Port,
  1203. IN BOOL fSend,
  1204. IN BOOL fReceive
  1205. );
  1206. VOID
  1207. Dns_CloseSocket(
  1208. IN SOCKET Socket
  1209. );
  1210. VOID
  1211. Dns_CloseConnection(
  1212. IN SOCKET Socket
  1213. );
  1214. DNS_STATUS
  1215. Dns_SetupGlobalAsyncSocket(
  1216. VOID
  1217. );
  1218. //
  1219. // Raw packet send and recv (send.c)
  1220. //
  1221. DNS_STATUS
  1222. Dns_SendEx(
  1223. IN OUT PDNS_MSG_BUF pMsg,
  1224. IN IP4_ADDRESS SendIp, OPTIONAL
  1225. IN BOOL fNoOpt
  1226. );
  1227. #define Dns_Send( pMsg ) Dns_SendEx( (pMsg), 0, 0 )
  1228. DNS_STATUS
  1229. Dns_Recv(
  1230. IN OUT PDNS_MSG_BUF pMsg
  1231. );
  1232. DNS_STATUS
  1233. Dns_RecvUdp(
  1234. IN OUT PDNS_MSG_BUF pMsg
  1235. );
  1236. VOID
  1237. Dns_SendMultipleUdp(
  1238. IN OUT PDNS_MSG_BUF pMsg,
  1239. IN PIP_ARRAY aipSendAddrs
  1240. );
  1241. DNS_STATUS
  1242. Dns_SendAndRecvUdp(
  1243. IN OUT PDNS_MSG_BUF pMsgSend,
  1244. OUT PDNS_MSG_BUF pMsgRecv,
  1245. IN DWORD dwFlags,
  1246. IN PIP_ARRAY aipServers,
  1247. IN OUT PDNS_NETINFO pAdapterInfo
  1248. );
  1249. DNS_STATUS
  1250. Dns_SendAndRecvMulticast(
  1251. IN OUT PDNS_MSG_BUF pMsgSend,
  1252. OUT PDNS_MSG_BUF pMsgRecv,
  1253. IN OUT PDNS_NETINFO pAdapterInfo OPTIONAL
  1254. );
  1255. DNS_STATUS
  1256. Dns_OpenTcpConnectionAndSend(
  1257. IN OUT PDNS_MSG_BUF pMsg,
  1258. IN IP_ADDRESS ipServer,
  1259. IN BOOL fBlocking
  1260. );
  1261. DNS_STATUS
  1262. Dns_RecvTcp(
  1263. IN OUT PDNS_MSG_BUF pMsg
  1264. );
  1265. DNS_STATUS
  1266. Dns_SendAndRecvTcp(
  1267. IN OUT PDNS_MSG_BUF pMsgSend,
  1268. OUT PDNS_MSG_BUF pMsgRecv,
  1269. IN PIP_ARRAY aipServers,
  1270. IN OUT PDNS_NETINFO pAdapterInfo
  1271. );
  1272. VOID
  1273. Dns_InitializeMsgRemoteSockaddr(
  1274. IN OUT PDNS_MSG_BUF pMsg,
  1275. IN IP_ADDRESS IpAddress
  1276. );
  1277. DNS_STATUS
  1278. Dns_SendAndRecv(
  1279. IN OUT PDNS_MSG_BUF pMsgSend,
  1280. OUT PDNS_MSG_BUF * ppMsgRecv,
  1281. OUT PDNS_RECORD * ppResponseRecords,
  1282. IN DWORD dwFlags,
  1283. IN PIP_ARRAY aipServers,
  1284. IN OUT PDNS_NETINFO pAdapterInfo
  1285. );
  1286. VOID
  1287. Dns_InitQueryTimeouts(
  1288. VOID
  1289. );
  1290. //
  1291. // Query (query.c)
  1292. //
  1293. //
  1294. // Flags to DnsQuery
  1295. //
  1296. // These are in addition to public flags in dnsapi.h
  1297. // They must all be in the reserved section defined by
  1298. // DNS_QUERY_RESERVED
  1299. //
  1300. // Unicode i\o
  1301. #define DNSQUERY_UNICODE_NAME (0x01000000)
  1302. #define DNSQUERY_UNICODE_OUT (0x02000000)
  1303. // DNS server query
  1304. #define DNS_SERVER_QUERY_NAME (L"..DnsServers")
  1305. DNS_STATUS
  1306. Dns_QueryLib(
  1307. IN OUT PDNS_MSG_BUF * ppMsgResponse,
  1308. OUT PDNS_RECORD * ppRecord,
  1309. IN PDNS_NAME pszName,
  1310. IN WORD wType,
  1311. IN DWORD dwFlags,
  1312. IN PIP_ARRAY aipDnsServers,
  1313. IN PDNS_NETINFO pNetworkInfo,
  1314. IN SOCKET Socket OPTIONAL
  1315. );
  1316. DNS_STATUS
  1317. Dns_QueryLibEx(
  1318. IN OUT PDNS_MSG_BUF * ppMsgResponse,
  1319. OUT PDNS_RECORD * ppResponseRecord,
  1320. IN PDNS_HEADER pHeader,
  1321. IN BOOL fNoHeaderCounts,
  1322. IN PDNS_NAME pszName,
  1323. IN WORD wType,
  1324. IN PDNS_RECORD pRecord,
  1325. IN DWORD dwFlags,
  1326. IN PIP_ARRAY aipDnsServers,
  1327. IN PDNS_NETINFO pNetworkInfo
  1328. );
  1329. DNS_STATUS
  1330. Dns_FindAuthoritativeZoneLib(
  1331. IN PDNS_NAME pszName,
  1332. IN DWORD dwFlags,
  1333. IN PIP_ARRAY aipQueryServers,
  1334. OUT PDNS_NETINFO * ppNetworkInfo
  1335. );
  1336. PDNS_NETINFO
  1337. Dns_BuildUpdateNetworkInfoFromFAZ(
  1338. IN PSTR pszZone,
  1339. IN PSTR pszPrimaryDns,
  1340. IN PDNS_RECORD pRecord
  1341. );
  1342. //
  1343. // Dynamic update (update.c)
  1344. //
  1345. PCHAR
  1346. Dns_WriteNoDataUpdateRecordToMessage(
  1347. IN PCHAR pch,
  1348. IN PCHAR pchStop,
  1349. IN WORD wClass,
  1350. IN WORD wType
  1351. );
  1352. PCHAR
  1353. Dns_WriteDataUpdateRecordToMessage(
  1354. IN PCHAR pch,
  1355. IN PCHAR pchStop,
  1356. IN WORD wClass,
  1357. IN WORD wType,
  1358. IN DWORD dwTtl,
  1359. IN WORD wDataLength
  1360. );
  1361. PDNS_MSG_BUF
  1362. Dns_BuildHostUpdateMessage(
  1363. IN OUT PDNS_MSG_BUF pMsg,
  1364. IN PSTR pszZone,
  1365. IN PSTR pszName,
  1366. IN PIP_ARRAY aipAddresses,
  1367. IN DWORD dwTtl
  1368. );
  1369. PDNS_RECORD
  1370. Dns_HostUpdateRRSet(
  1371. IN PSTR pszHostName,
  1372. IN PIP_ARRAY aipAddrs,
  1373. IN DWORD dwTtl
  1374. );
  1375. DNS_STATUS
  1376. Dns_UpdateHostAddrs(
  1377. IN PSTR pszName,
  1378. IN PIP_ARRAY aipAddresses,
  1379. IN PIP_ARRAY aipServers,
  1380. IN DWORD dwTtl
  1381. );
  1382. DNS_STATUS
  1383. Dns_UpdateHostAddrsOld(
  1384. IN PSTR pszName,
  1385. IN PIP_ARRAY aipAddresses,
  1386. IN PIP_ARRAY aipServers,
  1387. IN DWORD dwTtl
  1388. );
  1389. DNS_STATUS
  1390. Dns_UpdateLib(
  1391. IN PDNS_RECORD pRecord,
  1392. IN DWORD dwFlags,
  1393. IN PDNS_NETINFO pNetworkInfo,
  1394. IN HANDLE hCreds, OPTIONAL
  1395. OUT PDNS_MSG_BUF * ppMsgRecv OPTIONAL
  1396. );
  1397. DNS_STATUS
  1398. Dns_UpdateLibEx(
  1399. IN PDNS_RECORD pRecord,
  1400. IN DWORD dwFlags,
  1401. IN PDNS_NAME pszZone,
  1402. IN PDNS_NAME pszServerName,
  1403. IN PIP_ARRAY aipServers,
  1404. IN HANDLE hCreds, OPTIONAL
  1405. OUT PDNS_MSG_BUF * ppMsgRecv OPTIONAL
  1406. );
  1407. //
  1408. // List build
  1409. //
  1410. // pFirst points to first element in list.
  1411. // pLast points to last element in list.
  1412. //
  1413. // This builds a list for element types which have a pNext field
  1414. // as their first structure member.
  1415. //
  1416. typedef struct _Dns_List
  1417. {
  1418. PVOID pFirst;
  1419. PVOID pLast;
  1420. }
  1421. DNS_LIST, *PDNS_LIST;
  1422. //
  1423. // To init pFirst is NULL.
  1424. // But pLast points at the location of the pFirst pointer -- essentially
  1425. // treating the DNS_LIST as an element and pFirst as its next ptr.
  1426. //
  1427. // During an add, the address given in pLast, is set with the new element,
  1428. // equivalent to setting pLast's pNext field. Then pLast is reset to point
  1429. // at a new element.
  1430. //
  1431. // When the first element is added to the list, pLast is pointing at the
  1432. // DNS_LIST structure itself, so pFirst (as a dummy pNext) is set with
  1433. // the ptr to the first element.
  1434. //
  1435. // This works ONLY for elements which have a pNext field as the first
  1436. // structure member.
  1437. //
  1438. #define DNS_LIST_INIT( pList ) \
  1439. { \
  1440. PDNS_LIST _plist = (pList); \
  1441. _plist->pFirst = NULL; \
  1442. _plist->pLast = (_plist); \
  1443. }
  1444. #define DNS_LIST_ADD( pList, pnew ) \
  1445. { \
  1446. PDNS_LIST _plist = (pList); \
  1447. PVOID _pnew = (pnew); \
  1448. *(PVOID*)(_plist->pLast) = _pnew; \
  1449. _plist->pLast = _pnew; \
  1450. }
  1451. #define IS_DNS_LIST_EMPTY( pList ) \
  1452. ( (pList)->pFirst == NULL )
  1453. //
  1454. // DNS_LIST as structure macros
  1455. //
  1456. // Faster when function contains DNS_LIST structure itself and
  1457. // NO SIDE EFFECTS will be present in call.
  1458. //
  1459. #define DNS_LIST_STRUCT_INIT( List ) \
  1460. { \
  1461. List.pFirst = NULL; \
  1462. List.pLast = &List; \
  1463. }
  1464. #define DNS_LIST_STRUCT_ADD( List, pnew ) \
  1465. { \
  1466. *(PVOID*)(List.pLast) = (PVOID)pnew; \
  1467. List.pLast = (PVOID)pnew; \
  1468. }
  1469. #define IS_DNS_LIST_STRUCT_EMPTY( List ) \
  1470. ( List.pFirst == NULL )
  1471. //
  1472. // Record building (rralloc.c)
  1473. //
  1474. PDNS_RECORD
  1475. WINAPI
  1476. Dns_AllocateRecord(
  1477. IN WORD wBufferLength
  1478. );
  1479. VOID
  1480. WINAPI
  1481. Dns_RecordFree(
  1482. IN OUT PDNS_RECORD pRecord
  1483. );
  1484. #if 1
  1485. // Old BS with flag -- kill when all fixed up
  1486. VOID
  1487. WINAPI
  1488. Dns_RecordListFreeEx(
  1489. IN OUT PDNS_RECORD pRRList,
  1490. IN BOOL fFreeOwner
  1491. );
  1492. #define Dns_RecordListFree(p, f) Dns_RecordListFreeEx(p, f)
  1493. #else // new version
  1494. VOID
  1495. WINAPI
  1496. Dns_RecordListFree(
  1497. IN OUT PDNS_RECORD pRRList
  1498. );
  1499. #endif
  1500. PDNS_RECORD
  1501. Dns_RecordSetDetach(
  1502. IN OUT PDNS_RECORD pRRList
  1503. );
  1504. PDNS_RECORD
  1505. WINAPI
  1506. Dns_RecordListAppend(
  1507. IN OUT PDNS_RECORD pHeadList,
  1508. IN PDNS_RECORD pTailList
  1509. );
  1510. DWORD
  1511. Dns_RecordListCount(
  1512. IN PDNS_RECORD pRRList,
  1513. IN WORD wType
  1514. );
  1515. //
  1516. // Record build from data strings (rrbuild.c)
  1517. //
  1518. PDNS_RECORD
  1519. Dns_RecordBuild_A(
  1520. IN OUT PDNS_RRSET pRRSet,
  1521. IN PSTR pszOwner,
  1522. IN WORD wType,
  1523. IN BOOL fAdd,
  1524. IN UCHAR Section,
  1525. IN INT Argc,
  1526. IN PCHAR * Argv
  1527. );
  1528. PDNS_RECORD
  1529. Dns_RecordBuild_W(
  1530. IN OUT PDNS_RRSET pRRSet,
  1531. IN PWSTR pszOwner,
  1532. IN WORD wType,
  1533. IN BOOL fAdd,
  1534. IN UCHAR Section,
  1535. IN INT Argc,
  1536. IN PWCHAR * Argv
  1537. );
  1538. //
  1539. // Record set manipulation
  1540. //
  1541. //
  1542. // Record Compare
  1543. //
  1544. // Note: these routines will NOT do proper unicode compare, unless
  1545. // records have the fUnicode flag set.
  1546. //
  1547. BOOL
  1548. WINAPI
  1549. Dns_RecordCompare(
  1550. IN PDNS_RECORD pRecord1,
  1551. IN PDNS_RECORD pRecord2
  1552. );
  1553. BOOL
  1554. WINAPI
  1555. Dns_RecordSetCompare(
  1556. IN OUT PDNS_RECORD pRR1,
  1557. IN OUT PDNS_RECORD pRR2,
  1558. OUT PDNS_RECORD * ppDiff1, OPTIONAL
  1559. OUT PDNS_RECORD * ppDiff2 OPTIONAL
  1560. );
  1561. typedef enum _DnsSetCompareResult
  1562. {
  1563. DnsSetCompareError = (-1),
  1564. DnsSetCompareIdentical,
  1565. DnsSetCompareNoOverlap,
  1566. DnsSetCompareOneSubsetOfTwo,
  1567. DnsSetCompareTwoSubsetOfOne,
  1568. DnsSetCompareIntersection
  1569. }
  1570. DNS_SET_COMPARE_RESULT;
  1571. DNS_SET_COMPARE_RESULT
  1572. WINAPI
  1573. Dns_RecordSetCompareEx(
  1574. IN OUT PDNS_RECORD pRR1,
  1575. IN OUT PDNS_RECORD pRR2,
  1576. OUT PDNS_RECORD * ppDiff1, OPTIONAL
  1577. OUT PDNS_RECORD * ppDiff2 OPTIONAL
  1578. );
  1579. BOOL
  1580. WINAPI
  1581. Dns_RecordSetCompareForIntersection(
  1582. IN OUT PDNS_RECORD pRR1,
  1583. IN OUT PDNS_RECORD pRR2
  1584. );
  1585. //
  1586. // Record set prioritization (rrsort.c)
  1587. //
  1588. BOOL
  1589. Dns_CompareIpAddresses(
  1590. IN IP_ADDRESS addr1,
  1591. IN IP_ADDRESS addr2,
  1592. IN IP_ADDRESS subnetMask
  1593. );
  1594. //
  1595. // DNS Name compare
  1596. //
  1597. BOOL
  1598. Dns_NameCompare_A(
  1599. IN PCSTR pName1,
  1600. IN PCSTR pName2
  1601. );
  1602. BOOL
  1603. Dns_NameCompare_W(
  1604. IN PCWSTR pName1,
  1605. IN PCWSTR pName2
  1606. );
  1607. BOOL
  1608. Dns_NameCompare_UTF8(
  1609. IN PCSTR pName1,
  1610. IN PCSTR pName2
  1611. );
  1612. //#define Dns_NameCompare(pName1, pName2) Dns_NameCompare_UTF8((pName1),(pName2))
  1613. //#define Dns_NameCompare_U(pName1, pName2) Dns_NameCompare_UTF8((pName1),(pName2))
  1614. BOOL
  1615. Dns_NameComparePrivate(
  1616. IN PCSTR pName1,
  1617. IN PCSTR pName2,
  1618. IN DNS_CHARSET CharSet
  1619. );
  1620. //
  1621. // Advanced name comparison
  1622. // Includes hierarchial name relationship.
  1623. //
  1624. DNS_NAME_COMPARE_STATUS
  1625. Dns_NameCompareEx(
  1626. IN LPCSTR pszNameLeft,
  1627. IN LPCSTR pszNameRight,
  1628. IN DWORD dwReserved,
  1629. IN DNS_CHARSET CharSet
  1630. );
  1631. //
  1632. // Record Copy
  1633. //
  1634. PDNS_RECORD
  1635. WINAPI
  1636. Dns_RecordCopyEx(
  1637. IN PDNS_RECORD pRecord,
  1638. IN DNS_CHARSET CharSetIn,
  1639. IN DNS_CHARSET CharSetOut
  1640. );
  1641. //
  1642. // RR Set copy
  1643. //
  1644. PDNS_RECORD
  1645. WINAPI
  1646. Dns_RecordSetCopyEx(
  1647. IN PDNS_RECORD pRR,
  1648. IN DNS_CHARSET CharSetIn,
  1649. IN DNS_CHARSET CharSetOut
  1650. );
  1651. //
  1652. // Record \ type routines
  1653. //
  1654. //
  1655. // Resource record type\name mapping table
  1656. //
  1657. typedef struct
  1658. {
  1659. PCHAR pszTypeName; // type string (used in database files)
  1660. WORD wType; // type in host byte order
  1661. }
  1662. TYPE_NAME_TABLE;
  1663. extern TYPE_NAME_TABLE TypeTable[];
  1664. //
  1665. // Max record name length, allows upcasing of incoming labels
  1666. // to optimize comparisons
  1667. //
  1668. #define MAX_RECORD_NAME_LENGTH (8)
  1669. //
  1670. // Record type specific sizes
  1671. //
  1672. #define WKS_MAX_PORT (1024) // max well known service port
  1673. #define WKS_MAX_BITMASK_LENGTH (128) // 1024bits / 8bits/byte
  1674. #define SIZEOF_A6_ADDRESS_SUFFIX_LENGTH 16
  1675. #define SIZEOF_SOA_FIXED_DATA (5 * sizeof(DWORD))
  1676. #define SIZEOF_MX_FIXED_DATA (sizeof(WORD))
  1677. #define SIZEOF_WKS_FIXED_DATA (SIZEOF_IP_ADDRESS + sizeof(BYTE))
  1678. #define SIZEOF_KEY_FIXED_DATA (sizeof(DWORD))
  1679. #define SIZEOF_SIG_FIXED_DATA (4 * sizeof(DWORD) + sizeof(WORD))
  1680. #define SIZEOF_NXT_FIXED_DATA (0)
  1681. #define SIZEOF_LOC_FIXED_DATA (4 * sizeof(DWORD))
  1682. #define SIZEOF_SRV_FIXED_DATA (3 * sizeof(WORD))
  1683. #define SIZEOF_A6_FIXED_DATA (1 + SIZEOF_A6_ADDRESS_SUFFIX_LENGTH)
  1684. #define SIZEOF_TKEY_FIXED_DATA (2 * sizeof(DWORD) + 4 * sizeof(WORD))
  1685. #define SIZEOF_TSIG_PRE_SIG_FIXED_DATA (2 * sizeof(DWORD) + sizeof(WORD))
  1686. #define SIZEOF_TSIG_POST_SIG_FIXED_DATA (3 * sizeof(WORD))
  1687. #define SIZEOF_TSIG_FIXED_DATA (2 * sizeof(DWORD) + 4 * sizeof(WORD))
  1688. #define SIZEOF_WINS_FIXED_DATA (4 * sizeof(DWORD))
  1689. #define SIZEOF_NBSTAT_FIXED_DATA (3 * sizeof(DWORD))
  1690. //
  1691. // Record type routines
  1692. // These ones are of possible public interest and exposed in dnsapi.dll
  1693. //
  1694. BOOL
  1695. _fastcall
  1696. Dns_IsAMailboxType(
  1697. IN WORD wType
  1698. );
  1699. WORD
  1700. Dns_RecordTypeForName(
  1701. IN PCHAR pszName,
  1702. IN INT cchNameLength
  1703. );
  1704. BOOL
  1705. Dns_WriteStringForType_A(
  1706. OUT PCHAR pBuffer,
  1707. IN WORD wType
  1708. );
  1709. BOOL
  1710. Dns_WriteStringForType_W(
  1711. OUT PWCHAR pBuffer,
  1712. IN WORD wType
  1713. );
  1714. PCHAR
  1715. Dns_RecordStringForType(
  1716. IN WORD wType
  1717. );
  1718. PCHAR
  1719. Dns_RecordStringForWritableType(
  1720. IN WORD wType
  1721. );
  1722. //
  1723. // Record type specific stuff
  1724. //
  1725. BOOL
  1726. Dns_IsStringCountValidForTextType(
  1727. IN WORD wType,
  1728. IN WORD StringCount
  1729. );
  1730. //
  1731. // ATMA conversions
  1732. //
  1733. DWORD
  1734. Dns_AtmaAddressLengthForAddressString(
  1735. IN PCHAR pchString,
  1736. IN DWORD dwStringLength
  1737. );
  1738. DNS_STATUS
  1739. Dns_AtmaStringToAddress(
  1740. OUT PBYTE pAddress,
  1741. IN OUT PDWORD pdwAddrLength,
  1742. IN PCHAR pchString,
  1743. IN DWORD dwStringLength
  1744. );
  1745. PCHAR
  1746. Dns_AtmaAddressToString(
  1747. OUT PCHAR pchString,
  1748. IN UCHAR AddrType,
  1749. IN PBYTE pAddress,
  1750. IN DWORD dwAddrLength
  1751. );
  1752. //
  1753. // DNSSEC SIG and KEY routines
  1754. //
  1755. // Max key is 4096 bit giving 512 byte length.
  1756. //
  1757. // Max string representation is actually 33% larger as each three byte (24bit)
  1758. // block contains four base64 characters.
  1759. #define DNS_MAX_KEY_LENGTH (512)
  1760. #define DNS_MAX_KEY_STRING_LENGTH (685)
  1761. WORD
  1762. Dns_KeyRecordFlagForString(
  1763. IN PCHAR pchName,
  1764. IN INT cchNameLength
  1765. );
  1766. PCHAR
  1767. Dns_KeyRecordFlagString(
  1768. IN DWORD dwFlag,
  1769. IN OUT PCHAR pchFlag
  1770. );
  1771. UCHAR
  1772. Dns_KeyRecordProtocolForString(
  1773. IN PCHAR pchName,
  1774. IN INT cchNameLength
  1775. );
  1776. PCHAR
  1777. Dns_GetKeyProtocolString(
  1778. IN UCHAR uchProtocol
  1779. );
  1780. UCHAR
  1781. Dns_SecurityAlgorithmForString(
  1782. IN PCHAR pchName,
  1783. IN INT cchNameLength
  1784. );
  1785. PCHAR
  1786. Dns_GetDnssecAlgorithmString(
  1787. IN UCHAR uchAlgorithm
  1788. );
  1789. UCHAR
  1790. Dns_SecurityBase64CharToBits(
  1791. IN CHAR ch64
  1792. );
  1793. DNS_STATUS
  1794. Dns_SecurityBase64StringToKey(
  1795. OUT PBYTE pKey,
  1796. OUT PDWORD pKeyLength,
  1797. IN PCHAR pchString,
  1798. IN DWORD cchLength
  1799. );
  1800. PCHAR
  1801. Dns_SecurityKeyToBase64String(
  1802. IN PBYTE pKey,
  1803. IN DWORD KeyLength,
  1804. OUT PCHAR pchBuffer
  1805. );
  1806. LONG
  1807. Dns_ParseSigTime(
  1808. IN PCHAR pchString,
  1809. IN INT cchLength
  1810. );
  1811. PCHAR
  1812. Dns_SigTimeString(
  1813. IN LONG SigTime,
  1814. OUT PCHAR pchBuffer
  1815. );
  1816. //
  1817. // WINS \ WINS-R types detection
  1818. //
  1819. #define IS_WINS_TYPE(type) (((type) & 0xfffc) == 0xff00)
  1820. //
  1821. // MS WINS mapping flags
  1822. //
  1823. // return on invalid WINS flag
  1824. #define DNS_WINS_FLAG_ERROR (-1)
  1825. // max length of WINS flags
  1826. // pass buffer at least this big
  1827. #define WINS_FLAG_MAX_LENGTH (80)
  1828. DWORD
  1829. Dns_WinsRecordFlagForString(
  1830. IN PCHAR pchName,
  1831. IN INT cchNameLength
  1832. );
  1833. PCHAR
  1834. Dns_WinsRecordFlagString(
  1835. IN DWORD dwFlag,
  1836. IN OUT PCHAR pchFlag
  1837. );
  1838. //
  1839. // must sit here until PDNS_RECORD defined in public dns.h header
  1840. //
  1841. DNS_STATUS
  1842. Dns_RecordWriteFileString(
  1843. IN PDNS_RECORD pRecord,
  1844. IN PSTR pszZoneName,
  1845. IN DWORD dwDefaultTtl OPTIONAL
  1846. );
  1847. //
  1848. // IP Address to\from string utilities (straddr.c)
  1849. //
  1850. //
  1851. // String to Address
  1852. //
  1853. BOOL
  1854. Dns_Ip4StringToAddress_W(
  1855. OUT PIP4_ADDRESS pIp4Addr,
  1856. IN PCWSTR pwString
  1857. );
  1858. BOOL
  1859. Dns_Ip4StringToAddress_A(
  1860. OUT PIP4_ADDRESS pIp4Addr,
  1861. IN PCSTR pString
  1862. );
  1863. BOOL
  1864. Dns_Ip6StringToAddress_A(
  1865. OUT PIP6_ADDRESS pIp6Addr,
  1866. IN PCSTR pString
  1867. );
  1868. BOOL
  1869. Dns_Ip6StringToAddress_W(
  1870. OUT PIP6_ADDRESS pIp6Addr,
  1871. IN PCWSTR pwString
  1872. );
  1873. //
  1874. // Combined IP4\IP6 string to address
  1875. //
  1876. BOOL
  1877. Dns_StringToAddress_W(
  1878. OUT PCHAR pAddrBuf,
  1879. IN OUT PDWORD pBufLength,
  1880. IN PCWSTR pString,
  1881. IN OUT PDWORD pAddrFamily
  1882. );
  1883. BOOL
  1884. Dns_StringToAddress_A(
  1885. OUT PCHAR pAddrBuf,
  1886. IN OUT PDWORD pBufLength,
  1887. IN PCSTR pString,
  1888. IN OUT PDWORD pAddrFamily
  1889. );
  1890. //
  1891. // Address to string
  1892. //
  1893. PWCHAR
  1894. Dns_Ip6AddressToString_W(
  1895. OUT PWCHAR pwString,
  1896. IN PIP6_ADDRESS pIp6Addr
  1897. );
  1898. PCHAR
  1899. Dns_Ip6AddressToString_A(
  1900. OUT PCHAR pchString,
  1901. IN PIP6_ADDRESS pIp6Addr
  1902. );
  1903. PWCHAR
  1904. Dns_Ip4AddressToString_W(
  1905. OUT PWCHAR pwString,
  1906. IN PIP4_ADDRESS pIp4Addr
  1907. );
  1908. PCHAR
  1909. Dns_Ip4AddressToString_A(
  1910. OUT PCHAR pString,
  1911. IN PIP4_ADDRESS pIp4Addr
  1912. );
  1913. //
  1914. // Address to string -- combined
  1915. //
  1916. PCHAR
  1917. Dns_AddressToString_A(
  1918. OUT PCHAR pchString,
  1919. IN OUT PDWORD pStringLength,
  1920. IN PBYTE pAddr,
  1921. IN DWORD AddrLength,
  1922. IN DWORD AddrFamily
  1923. );
  1924. //
  1925. // Reverse lookup address-to-name IP4
  1926. //
  1927. PCHAR
  1928. Dns_Ip4AddressToReverseName_A(
  1929. OUT PCHAR pBuffer,
  1930. IN IP4_ADDRESS IpAddr
  1931. );
  1932. PWCHAR
  1933. Dns_Ip4AddressToReverseName_W(
  1934. OUT PWCHAR pBuffer,
  1935. IN IP4_ADDRESS IpAddr
  1936. );
  1937. PCHAR
  1938. Dns_Ip4AddressToReverseNameAlloc_A(
  1939. IN IP4_ADDRESS IpAddr
  1940. );
  1941. PWCHAR
  1942. Dns_Ip4AddressToReverseNameAlloc_W(
  1943. IN IP4_ADDRESS IpAddr
  1944. );
  1945. //
  1946. // Reverse lookup address-to-name IP6
  1947. //
  1948. PCHAR
  1949. Dns_Ip6AddressToReverseName_A(
  1950. OUT PCHAR pBuffer,
  1951. IN IP6_ADDRESS Ip6Addr
  1952. );
  1953. PWCHAR
  1954. Dns_Ip6AddressToReverseName_W(
  1955. OUT PWCHAR pBuffer,
  1956. IN IP6_ADDRESS Ip6Addr
  1957. );
  1958. PCHAR
  1959. Dns_Ip6AddressToReverseNameAlloc_A(
  1960. IN IP6_ADDRESS Ip6Addr
  1961. );
  1962. PWCHAR
  1963. Dns_Ip6AddressToReverseNameAlloc_W(
  1964. IN IP6_ADDRESS Ip6Addr
  1965. );
  1966. //
  1967. // Reverse lookup name-to-address
  1968. //
  1969. BOOL
  1970. Dns_Ip4ReverseNameToAddress_A(
  1971. OUT PIP4_ADDRESS pIp4Addr,
  1972. IN PCSTR pszName
  1973. );
  1974. BOOL
  1975. Dns_Ip4ReverseNameToAddress_W(
  1976. OUT PIP4_ADDRESS pIp4Addr,
  1977. IN PCWSTR pwsName
  1978. );
  1979. BOOL
  1980. Dns_Ip6ReverseNameToAddress_A(
  1981. OUT PIP6_ADDRESS pIp6Addr,
  1982. IN PCSTR pszName
  1983. );
  1984. BOOL
  1985. Dns_Ip6ReverseNameToAddress_W(
  1986. OUT PIP6_ADDRESS pIp6Addr,
  1987. IN PCWSTR pwsName
  1988. );
  1989. //
  1990. // Combined IP4\IP6 reverse lookup name-to-address
  1991. //
  1992. BOOL
  1993. Dns_ReverseNameToAddress_W(
  1994. OUT PCHAR pAddrBuf,
  1995. IN OUT PDWORD pBufLength,
  1996. IN PCWSTR pString,
  1997. IN OUT PDWORD pAddrFamily
  1998. );
  1999. BOOL
  2000. Dns_ReverseNameToAddress_A(
  2001. OUT PCHAR pAddrBuf,
  2002. IN OUT PDWORD pBufLength,
  2003. IN PCSTR pString,
  2004. IN OUT PDWORD pAddrFamily
  2005. );
  2006. //
  2007. // String utilities (string.c)
  2008. //
  2009. // Note some of these require memory allocation, see note
  2010. // on memory allocation below.
  2011. //
  2012. // Flags are defined in dnsapi.h
  2013. //
  2014. //#define DNS_ALLOW_RFC_NAMES_ONLY (0)
  2015. //#define DNS_ALLOW_NONRFC_NAMES (0x00000001)
  2016. //#define DNS_ALLOW_MULTIBYTE_NAMES (0x00000002)
  2017. //#define DNS_ALLOW_ALL_NAMES (0x00000003)
  2018. //
  2019. // Unicode name buffer length.
  2020. // Non-type specific routines below take buffer counts in bytes.
  2021. // Unicode buffers of max name length have twice the bytes.
  2022. //
  2023. #define DNS_MAX_NAME_BUFFER_LENGTH_UNICODE (2 * DNS_MAX_NAME_BUFFER_LENGTH)
  2024. //
  2025. // Macros to simplify UTF8 conversions
  2026. //
  2027. // UTF8 is simply a representation of unicode that maps one-to-one
  2028. // for the ASCII space.
  2029. // Unicode UTF8
  2030. // ------- ----
  2031. // < 0x80 (128) -> use low byte (one-to-one mapping)
  2032. // < 0x07ff -> two chars
  2033. // > 0x07ff -> three chars
  2034. //
  2035. #define UTF8_1ST_OF_2 0xc0 // 110x xxxx
  2036. #define UTF8_1ST_OF_3 0xe0 // 1110 xxxx
  2037. #define UTF8_TRAIL 0x80 // 10xx xxxx
  2038. #define UTF8_2_MAX 0x07ff // max unicode character representable in
  2039. // in two byte UTF8
  2040. //
  2041. // Explicitly UTF8 string
  2042. //
  2043. typedef PSTR PU8STR;
  2044. PSTR
  2045. Dns_CreateStringCopy(
  2046. IN PCHAR pchString,
  2047. IN DWORD cchString
  2048. );
  2049. DWORD
  2050. Dns_GetBufferLengthForStringCopy(
  2051. IN PCHAR pchString,
  2052. IN DWORD cchString,
  2053. IN DNS_CHARSET CharSetIn,
  2054. IN DNS_CHARSET CharSetOut
  2055. );
  2056. DWORD
  2057. Dns_StringCopy(
  2058. OUT PBYTE pBuffer,
  2059. IN OUT PDWORD pdwBufLength,
  2060. IN PCHAR pchString,
  2061. IN DWORD cchString,
  2062. IN DNS_CHARSET CharSetIn,
  2063. IN DNS_CHARSET CharSetOut
  2064. );
  2065. PVOID
  2066. Dns_StringCopyAllocate(
  2067. IN PCHAR pchString,
  2068. IN DWORD cchString,
  2069. IN DNS_CHARSET CharSetIn,
  2070. IN DNS_CHARSET CharSetOut
  2071. );
  2072. #define Dns_StringCopyAllocate_W( p, c ) \
  2073. ( (PWCHAR) Dns_StringCopyAllocate( \
  2074. (PCHAR) (p), \
  2075. (c), \
  2076. DnsCharSetUnicode, \
  2077. DnsCharSetUnicode ) )
  2078. #define Dns_StringCopyAllocate_A( p, c ) \
  2079. ( (PCHAR) Dns_StringCopyAllocate( \
  2080. (p), \
  2081. (c), \
  2082. DnsCharSetUtf8, \
  2083. DnsCharSetUtf8 ) )
  2084. PSTR
  2085. Dns_CreateStringCopy_A(
  2086. IN PCSTR pwsString
  2087. );
  2088. PWSTR
  2089. Dns_CreateStringCopy_W(
  2090. IN PCWSTR pwsString
  2091. );
  2092. PWSTR
  2093. Dns_CreateConcatenatedString_W(
  2094. IN PCWSTR * pStringArray
  2095. );
  2096. PWSTR
  2097. Dns_GetResourceString(
  2098. IN DWORD dwStringId,
  2099. IN PWSTR pwszBuffer,
  2100. IN DWORD cbBuffer
  2101. );
  2102. INT
  2103. wcsicmp_ThatWorks(
  2104. IN PWSTR pString1,
  2105. IN PWSTR pString2
  2106. );
  2107. //
  2108. // Special DNS name string functions
  2109. //
  2110. #define Dns_GetBufferLengthForNameCopy(a,b,c,d)\
  2111. Dns_GetBufferLengthForStringCopy((a),(b),(c),(d))
  2112. #define Dns_NameCopy(a,b,c,d,e,f) \
  2113. Dns_StringCopy(a,b,c,d,e,f)
  2114. #define Dns_NameCopyAllocate(a,b,c,d) \
  2115. Dns_StringCopyAllocate(a,b,c,d)
  2116. //
  2117. // Name validation (string.c)
  2118. //
  2119. DNS_STATUS
  2120. Dns_ValidateName_UTF8(
  2121. IN LPCSTR pszName,
  2122. IN DNS_NAME_FORMAT Format
  2123. );
  2124. DNS_STATUS
  2125. Dns_ValidateName_W(
  2126. IN LPCWSTR pwszName,
  2127. IN DNS_NAME_FORMAT Format
  2128. );
  2129. DNS_STATUS
  2130. Dns_ValidateName_A(
  2131. IN LPCSTR pszName,
  2132. IN DNS_NAME_FORMAT Format
  2133. );
  2134. DNS_STATUS
  2135. Dns_ValidateDnsString_UTF8(
  2136. IN LPCSTR pszName
  2137. );
  2138. DNS_STATUS
  2139. Dns_ValidateDnsString_W(
  2140. IN LPCWSTR pszName
  2141. );
  2142. PSTR
  2143. Dns_CreateStandardDnsNameCopy(
  2144. IN PCHAR pchName,
  2145. IN DWORD cchName,
  2146. IN DWORD dwFlag
  2147. );
  2148. //
  2149. // UTF8 conversions (utf8.c)
  2150. //
  2151. DNS_STATUS
  2152. _fastcall
  2153. Dns_ValidateUtf8Byte(
  2154. IN BYTE chUtf8,
  2155. IN OUT PDWORD pdwTrailCount
  2156. );
  2157. DWORD
  2158. _fastcall
  2159. Dns_UnicodeToUtf8(
  2160. IN PWCHAR pwUnicode,
  2161. IN DWORD cchUnicode,
  2162. OUT PCHAR pchResult,
  2163. IN DWORD cchResult
  2164. );
  2165. DWORD
  2166. _fastcall
  2167. Dns_Utf8ToUnicode(
  2168. IN PCHAR pchUtf8,
  2169. IN DWORD cchUtf8,
  2170. OUT PWCHAR pwResult,
  2171. IN DWORD cwResult
  2172. );
  2173. DWORD
  2174. Dns_Utf8ToOrFromAnsi(
  2175. OUT PCHAR pchResult,
  2176. IN DWORD cchResult,
  2177. IN PCHAR pchIn,
  2178. IN DWORD cchIn,
  2179. IN DNS_CHARSET InCharSet,
  2180. IN DNS_CHARSET OutCharSet
  2181. );
  2182. DWORD
  2183. Dns_AnsiToUtf8(
  2184. IN PCHAR pchAnsi,
  2185. IN DWORD cchAnsi,
  2186. OUT PCHAR pchResult,
  2187. IN DWORD cchResult
  2188. );
  2189. DWORD
  2190. Dns_Utf8ToAnsi(
  2191. IN PCHAR pchUtf8,
  2192. IN DWORD cchUtf8,
  2193. OUT PCHAR pchResult,
  2194. IN DWORD cchResult
  2195. );
  2196. BOOL
  2197. _fastcall
  2198. Dns_IsStringAscii(
  2199. IN PSTR pszString
  2200. );
  2201. BOOL
  2202. _fastcall
  2203. Dns_IsStringAsciiEx(
  2204. IN PCHAR pchString,
  2205. IN DWORD cchString
  2206. );
  2207. BOOL
  2208. _fastcall
  2209. Dns_IsWideStringAscii(
  2210. IN PWSTR pwsString
  2211. );
  2212. //
  2213. // Resource record dispatch tables
  2214. //
  2215. // Resource record tables are indexed by type for standard types
  2216. // These define limits on tables.
  2217. //
  2218. // Currently indexing out to RR 40, so that we'll handle any new RR types
  2219. // out this far without interfering with WINS stuff.
  2220. //
  2221. #define MAX_SELF_INDEXED_TYPE (48)
  2222. //
  2223. // Mappings for non-self indexed types
  2224. //
  2225. // Note: these are presented here for information purposes only!
  2226. //
  2227. // Always call Dns_RecordTableIndexForType(wType) to get correct index.
  2228. //
  2229. #define TKEY_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 1)
  2230. #define TSIG_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 2)
  2231. #define WINS_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 3)
  2232. #define WINSR_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 4)
  2233. // End of actual record types.
  2234. // Query type indexes may extend beyond this index.
  2235. #define MAX_RECORD_TYPE_INDEX (MAX_SELF_INDEXED_TYPE + 4)
  2236. //
  2237. // Generic indexer for both regular and extended (non-self-indexing) types
  2238. //
  2239. #define INDEX_FOR_TYPE(type) Dns_RecordTableIndexForType(type)
  2240. //
  2241. // Type to index mapping
  2242. //
  2243. WORD
  2244. Dns_RecordTableIndexForType(
  2245. IN WORD wType
  2246. );
  2247. //
  2248. // Write record data to wire
  2249. //
  2250. typedef PCHAR (* RR_WRITE_FUNCTION)(
  2251. PDNS_RECORD,
  2252. PCHAR,
  2253. PCHAR );
  2254. extern RR_WRITE_FUNCTION RRWriteTable[];
  2255. //
  2256. // Read record data from wire
  2257. //
  2258. typedef PDNS_RECORD (* RR_READ_FUNCTION)(
  2259. PDNS_RECORD,
  2260. DNS_CHARSET,
  2261. PCHAR,
  2262. PCHAR,
  2263. PCHAR );
  2264. extern RR_READ_FUNCTION RRReadTable[];
  2265. //
  2266. // Proto type TSIG read from wire function
  2267. //
  2268. PDNS_RECORD
  2269. TsigRecordRead(
  2270. IN OUT PDNS_RECORD pRR,
  2271. IN DNS_CHARSET OutCharSet,
  2272. IN OUT PCHAR pchStart,
  2273. IN PCHAR pchData,
  2274. IN PCHAR pchEnd
  2275. );
  2276. PDNS_RECORD
  2277. TkeyRecordRead(
  2278. IN OUT PDNS_RECORD pRR,
  2279. IN DNS_CHARSET OutCharSet,
  2280. IN OUT PCHAR pchStart,
  2281. IN PCHAR pchData,
  2282. IN PCHAR pchEnd
  2283. );
  2284. //
  2285. // Copy record
  2286. //
  2287. typedef PDNS_RECORD (* RR_COPY_FUNCTION)(
  2288. PDNS_RECORD,
  2289. DNS_CHARSET,
  2290. DNS_CHARSET );
  2291. extern RR_COPY_FUNCTION RRCopyTable[];
  2292. //
  2293. // Compare record data
  2294. //
  2295. typedef BOOL (* RR_COMPARE_FUNCTION)(
  2296. PDNS_RECORD,
  2297. PDNS_RECORD );
  2298. extern RR_COMPARE_FUNCTION RRCompareTable[];
  2299. //
  2300. // Generic print routine
  2301. //
  2302. // All our print routines will take the real print routine
  2303. // as a parameter. This routine must have "sprintf-like"
  2304. // or "fprintf-like" semantics. In other words a context,
  2305. // format and variable number of arguments.
  2306. //
  2307. // Note the context argument is effectively a PVOID --
  2308. // different routines will have different contexts. The
  2309. // explicit definition is to enforce strong type checking
  2310. // so a call without a context is caught on compile.
  2311. //
  2312. typedef struct _DnsPrintContext
  2313. {
  2314. PVOID pvDummy;
  2315. DWORD Dummy;
  2316. }
  2317. PRINT_CONTEXT, *PPRINT_CONTEXT;
  2318. typedef VOID (* PRINT_ROUTINE)(
  2319. PPRINT_CONTEXT,
  2320. CHAR*,
  2321. ... );
  2322. //
  2323. // Print record
  2324. //
  2325. typedef VOID (* RR_PRINT_FUNCTION)(
  2326. PRINT_ROUTINE,
  2327. PPRINT_CONTEXT,
  2328. PDNS_RECORD );
  2329. extern RR_PRINT_FUNCTION RRPrintTable[];
  2330. //
  2331. // Build from argc\argv data strings
  2332. //
  2333. typedef PDNS_RECORD (* RR_BUILD_FUNCTION)(
  2334. DWORD,
  2335. PCHAR * );
  2336. extern RR_BUILD_FUNCTION RRBuildTable[];
  2337. typedef PDNS_RECORD (* RR_BUILD_FUNCTION_W)(
  2338. DWORD,
  2339. PWCHAR * );
  2340. extern RR_BUILD_FUNCTION_W RRBuildTableW[];
  2341. //
  2342. // RnR utilities
  2343. //
  2344. DWORD
  2345. Dns_RnrLupFlagForString(
  2346. IN PCHAR pchName,
  2347. IN INT cchNameLength
  2348. );
  2349. PCHAR
  2350. Dns_GetRnrLupFlagString(
  2351. IN DWORD dwFlag
  2352. );
  2353. DWORD
  2354. Dns_RnrNameSpaceIdForString(
  2355. IN PCHAR pchName,
  2356. IN INT cchNameLength
  2357. );
  2358. PCHAR
  2359. Dns_GetRnrNameSpaceIdString(
  2360. IN DWORD dwFlag
  2361. );
  2362. //
  2363. // Hostent utilities
  2364. //
  2365. BOOL
  2366. Hostent_IsSupportedAddrType(
  2367. IN WORD wType
  2368. );
  2369. DWORD
  2370. Hostent_Size(
  2371. IN PHOSTENT pHostent,
  2372. IN DNS_CHARSET CharSetExisting,
  2373. IN DNS_CHARSET CharSetTarget,
  2374. IN PDWORD pAliasCount,
  2375. IN PDWORD pAddrCount
  2376. );
  2377. PHOSTENT
  2378. Hostent_Copy(
  2379. IN OUT PBYTE * ppBuffer,
  2380. IN OUT PINT pBufferSize,
  2381. OUT PINT pHostentSize,
  2382. IN PHOSTENT pHostent,
  2383. IN DNS_CHARSET CharSetIn,
  2384. IN DNS_CHARSET CharSetTarget,
  2385. IN BOOL fOffsets,
  2386. IN BOOL fAlloc
  2387. );
  2388. DWORD
  2389. Hostent_WriteIp4Addrs(
  2390. IN OUT PHOSTENT pHostent,
  2391. OUT PCHAR pAddrBuf,
  2392. IN DWORD MaxBufCount,
  2393. IN PIP4_ADDRESS Ip4Array,
  2394. IN DWORD ArrayCount,
  2395. IN BOOL fScreenZero
  2396. );
  2397. DWORD
  2398. Hostent_WriteLocalIp4Array(
  2399. IN OUT PHOSTENT pHostent,
  2400. OUT PCHAR pAddrBuf,
  2401. IN DWORD MaxBufCount,
  2402. IN PIP_ARRAY pIpArray
  2403. );
  2404. BOOL
  2405. Hostent_IsAddressInHostent(
  2406. IN OUT PHOSTENT pHostent,
  2407. IN PCHAR pAddr,
  2408. IN DWORD AddrLength,
  2409. IN INT Family OPTIONAL
  2410. );
  2411. BOOL
  2412. Hostent_IsIp4AddressInHostent(
  2413. IN OUT PHOSTENT pHostent,
  2414. IN IP4_ADDRESS Ip4Addr
  2415. );
  2416. //
  2417. // Hostent Object
  2418. //
  2419. typedef struct _HostentBlob
  2420. {
  2421. PHOSTENT pHostent;
  2422. // flags
  2423. BOOL fAllocatedBlob;
  2424. BOOL fAllocatedBuf;
  2425. // buffer allocated
  2426. PCHAR pBuffer;
  2427. DWORD BufferLength;
  2428. DWORD AvailLength;
  2429. PCHAR pAvailBuffer;
  2430. // buffer in build
  2431. PCHAR pCurrent;
  2432. DWORD BytesLeft;
  2433. // sizing info
  2434. DWORD MaxAliasCount;
  2435. DWORD MaxAddrCount;
  2436. // hostent building
  2437. DWORD AliasCount;
  2438. DWORD AddrCount;
  2439. BOOL fWroteName;
  2440. DNS_CHARSET CharSet;
  2441. BOOL fUnicode;
  2442. }
  2443. HOSTENT_BLOB, *PHOSTENT_BLOB;
  2444. typedef struct _HostentInitRequest
  2445. {
  2446. INT AddrFamily;
  2447. WORD wType;
  2448. DWORD AddrCount;
  2449. BOOL fUnicode;
  2450. DNS_CHARSET CharSet;
  2451. DWORD NameLength;
  2452. PBYTE pName;
  2453. DWORD AliasCount;
  2454. DWORD AliasNameLength;
  2455. }
  2456. HOSTENT_INIT, *PHOSTENT_INIT;
  2457. DNS_STATUS
  2458. HostentBlob_Create(
  2459. IN OUT PHOSTENT_BLOB * ppBlob,
  2460. IN PHOSTENT_INIT pReq
  2461. );
  2462. PHOSTENT_BLOB
  2463. HostentBlob_CreateAttachExisting(
  2464. IN PHOSTENT pHostent,
  2465. IN BOOL fUnicode
  2466. );
  2467. VOID
  2468. HostentBlob_Free(
  2469. IN OUT PHOSTENT_BLOB pBlob
  2470. );
  2471. DNS_STATUS
  2472. HostentBlob_WriteAddress(
  2473. IN OUT PHOSTENT_BLOB pBlob,
  2474. IN PVOID pAddress,
  2475. IN DWORD AddrSize,
  2476. IN DWORD AddrType
  2477. );
  2478. DNS_STATUS
  2479. HostentBlob_WriteAddressArray(
  2480. IN OUT PHOSTENT_BLOB pBlob,
  2481. IN PVOID pAddrArray,
  2482. IN DWORD AddrCount,
  2483. IN DWORD AddrSize,
  2484. IN DWORD AddrType
  2485. );
  2486. DNS_STATUS
  2487. HostentBlob_WriteNameOrAlias(
  2488. IN OUT PHOSTENT_BLOB pBlob,
  2489. IN PSTR pszName,
  2490. IN BOOL fAlias,
  2491. IN BOOL fUnicode
  2492. );
  2493. DNS_STATUS
  2494. HostentBlob_WriteRecords(
  2495. IN OUT PHOSTENT_BLOB pBlob,
  2496. IN PDNS_RECORD pRecords,
  2497. IN BOOL fWriteName
  2498. );
  2499. // Special hostents
  2500. PHOSTENT_BLOB
  2501. Hostent_Localhost(
  2502. IN INT AddrFamily
  2503. );
  2504. DNS_STATUS
  2505. HostentBlob_CreateFromIpArray(
  2506. IN OUT PHOSTENT_BLOB * ppBlob,
  2507. IN INT AddrFamily,
  2508. IN INT AddrSize,
  2509. IN INT AddrCount,
  2510. IN PCHAR pArray,
  2511. IN PSTR pName,
  2512. IN BOOL fUnicode
  2513. );
  2514. DNS_STATUS
  2515. HostentBlob_CreateLocal(
  2516. IN OUT PHOSTENT_BLOB * ppBlob,
  2517. IN INT AddrFamily,
  2518. IN BOOL fLoopback,
  2519. IN BOOL fZero,
  2520. IN BOOL fHostnameOnly
  2521. );
  2522. // Query for hostent
  2523. PHOSTENT_BLOB
  2524. HostentBlob_Query(
  2525. IN PWSTR pwsName,
  2526. IN WORD wType,
  2527. IN DWORD Flags,
  2528. IN OUT PVOID * ppMsg, OPTIONAL
  2529. IN INT AddrFamily OPTIONAL
  2530. );
  2531. //
  2532. // Memory allocation
  2533. //
  2534. // Some DNS library functions -- including the IP array and string utils
  2535. // -- allocate memory. This memory allocation defaults to routines that
  2536. // use LocalAlloc, LocalReAlloc, LocalFree. If you desire alternative
  2537. // memory allocation mechanisms, use this function to override the DNS
  2538. // library defaults. All memory allocated by the DNS library, should
  2539. // then be freed by the corresponding function.
  2540. //
  2541. typedef PVOID (* DNSLIB_ALLOC_FUNCTION)();
  2542. typedef PVOID (* DNSLIB_REALLOC_FUNCTION)();
  2543. typedef VOID (* DNSLIB_FREE_FUNCTION)();
  2544. VOID
  2545. Dns_LibHeapReset(
  2546. IN DNSLIB_ALLOC_FUNCTION pAlloc,
  2547. IN DNSLIB_REALLOC_FUNCTION pRealloc,
  2548. IN DNSLIB_FREE_FUNCTION pFree
  2549. );
  2550. //
  2551. // These routines call the currently registered allocation functions
  2552. // whether default or reset through Dns_ApiHeapReset()
  2553. //
  2554. PVOID
  2555. Dns_Alloc(
  2556. IN INT iSize
  2557. );
  2558. PVOID
  2559. Dns_AllocZero(
  2560. IN INT iSize
  2561. );
  2562. PVOID
  2563. Dns_Realloc(
  2564. IN OUT PVOID pMem,
  2565. IN INT iSize
  2566. );
  2567. VOID
  2568. Dns_Free(
  2569. IN OUT PVOID pMem
  2570. );
  2571. PVOID
  2572. Dns_AllocMemCopy(
  2573. IN PVOID pMem,
  2574. IN INT iSize
  2575. );
  2576. //
  2577. // Print routines (print.c)
  2578. //
  2579. // Print routines below use any printf() like function to print.
  2580. // this is typedef that function must match.
  2581. //
  2582. //
  2583. // Print Locking
  2584. //
  2585. VOID
  2586. DnsPrint_InitLocking(
  2587. IN PCRITICAL_SECTION pLock
  2588. );
  2589. VOID
  2590. DnsPrint_Lock(
  2591. VOID
  2592. );
  2593. VOID
  2594. DnsPrint_Unlock(
  2595. VOID
  2596. );
  2597. #define Dns_PrintInitLocking(a) DnsPrint_InitLocking(a)
  2598. #define Dns_PrintLock() DnsPrint_Lock()
  2599. #define Dns_PrintUnlock() DnsPrint_Unlock()
  2600. //
  2601. // Print routines for general types and structures
  2602. //
  2603. VOID
  2604. DnsPrint_String(
  2605. IN PRINT_ROUTINE PrintRoutine,
  2606. IN OUT PPRINT_CONTEXT pContext,
  2607. IN PSTR pszHeader, OPTIONAL
  2608. IN PSTR pszString,
  2609. IN BOOL fUnicode,
  2610. IN PSTR pszTrailer OPTIONAL
  2611. );
  2612. VOID
  2613. DnsPrint_StringCharSet(
  2614. IN PRINT_ROUTINE PrintRoutine,
  2615. IN OUT PPRINT_CONTEXT pContext,
  2616. IN PSTR pszHeader, OPTIONAL
  2617. IN PSTR pszString,
  2618. IN DNS_CHARSET CharSet,
  2619. IN PSTR pszTrailer OPTIONAL
  2620. );
  2621. VOID
  2622. DnsPrint_Utf8StringBytes(
  2623. IN PRINT_ROUTINE PrintRoutine,
  2624. IN OUT PPRINT_CONTEXT pContext,
  2625. IN PSTR pszHeader,
  2626. IN PCHAR pUtf8,
  2627. IN DWORD Length
  2628. );
  2629. VOID
  2630. DnsPrint_UnicodeStringBytes(
  2631. IN PRINT_ROUTINE PrintRoutine,
  2632. IN OUT PPRINT_CONTEXT pContext,
  2633. IN PSTR pszHeader,
  2634. IN PWCHAR pUnicode,
  2635. IN DWORD Length
  2636. );
  2637. VOID
  2638. DnsPrint_StringArray(
  2639. IN PRINT_ROUTINE PrintRoutine,
  2640. IN OUT PPRINT_CONTEXT pContext,
  2641. IN PSTR pszHeader,
  2642. IN PSTR * StringArray,
  2643. IN DWORD Count, OPTIONAL
  2644. IN BOOL fUnicode
  2645. );
  2646. VOID
  2647. DnsPrint_Argv(
  2648. IN PRINT_ROUTINE PrintRoutine,
  2649. IN OUT PPRINT_CONTEXT pContext,
  2650. IN PSTR pszHeader,
  2651. IN CHAR ** Argv,
  2652. IN DWORD Argc, OPTIONAL
  2653. IN BOOL fUnicode
  2654. );
  2655. VOID
  2656. DnsPrint_DwordArray(
  2657. IN PRINT_ROUTINE PrintRoutine,
  2658. IN OUT PPRINT_CONTEXT pContext,
  2659. IN PSTR pszHeader,
  2660. IN PSTR pszName,
  2661. IN DWORD dwCount,
  2662. IN PDWORD adwArray
  2663. );
  2664. VOID
  2665. DnsPrint_IpAddressArray(
  2666. IN PRINT_ROUTINE PrintRoutine,
  2667. IN OUT PPRINT_CONTEXT pContext,
  2668. IN PSTR pszHeader,
  2669. IN PSTR pszName,
  2670. IN DWORD dwIpAddrCount,
  2671. IN PIP_ADDRESS pIpAddrs
  2672. );
  2673. VOID
  2674. DnsPrint_IpArray(
  2675. IN PRINT_ROUTINE PrintRoutine,
  2676. IN OUT PPRINT_CONTEXT pContext,
  2677. IN PSTR pszHeader,
  2678. IN PSTR pszName,
  2679. IN PIP_ARRAY pIpArray
  2680. );
  2681. VOID
  2682. DnsPrint_Ip6Address(
  2683. IN PRINT_ROUTINE PrintRoutine,
  2684. IN OUT PPRINT_CONTEXT pContext,
  2685. IN PSTR pszHeader,
  2686. IN PIP6_ADDRESS pIp6Address,
  2687. IN PSTR pszTrailer
  2688. );
  2689. VOID
  2690. DnsPrint_Guid(
  2691. IN PRINT_ROUTINE PrintRoutine,
  2692. IN OUT PPRINT_CONTEXT pContext,
  2693. IN PSTR pszHeader,
  2694. IN PGUID pGuid
  2695. );
  2696. //
  2697. // Winsock \ RnR types and structures
  2698. //
  2699. VOID
  2700. DnsPrint_FdSet(
  2701. IN PRINT_ROUTINE PrintRoutine,
  2702. IN OUT PPRINT_CONTEXT pContext,
  2703. IN PSTR pszHeader,
  2704. IN struct fd_set * pFdSet
  2705. );
  2706. VOID
  2707. DnsPrint_Sockaddr(
  2708. IN PRINT_ROUTINE PrintRoutine,
  2709. IN OUT PPRINT_CONTEXT pContext,
  2710. IN PSTR pszHeader,
  2711. IN DWORD Indent,
  2712. IN PSOCKADDR pSockaddr,
  2713. IN INT iSockaddrLength
  2714. );
  2715. #ifdef _WS2TCPIP_H_
  2716. VOID
  2717. DnsPrint_AddrInfo(
  2718. IN PRINT_ROUTINE PrintRoutine,
  2719. IN OUT PPRINT_CONTEXT pContext,
  2720. IN PSTR pszHeader,
  2721. IN DWORD Indent,
  2722. IN PADDRINFO pAddrInfo
  2723. );
  2724. VOID
  2725. DnsPrint_AddrInfoList(
  2726. IN PRINT_ROUTINE PrintRoutine,
  2727. IN OUT PPRINT_CONTEXT pContext,
  2728. IN PSTR pszHeader,
  2729. IN DWORD Indent,
  2730. IN PADDRINFO pAddrInfo
  2731. );
  2732. #endif
  2733. #ifdef _WINSOCK2API_
  2734. VOID
  2735. DnsPrint_SocketAddress(
  2736. IN PRINT_ROUTINE PrintRoutine,
  2737. IN OUT PPRINT_CONTEXT pContext,
  2738. IN PSTR pszHeader,
  2739. IN DWORD Indent,
  2740. IN PSOCKET_ADDRESS pSocketAddress
  2741. );
  2742. VOID
  2743. DnsPrint_CsAddr(
  2744. IN PRINT_ROUTINE PrintRoutine,
  2745. IN OUT PPRINT_CONTEXT pContext,
  2746. IN PSTR pszHeader,
  2747. IN DWORD Indent,
  2748. IN PCSADDR_INFO pCsAddrInfo
  2749. );
  2750. VOID
  2751. DnsPrint_AfProtocolsArray(
  2752. IN PRINT_ROUTINE PrintRoutine,
  2753. IN OUT PPRINT_CONTEXT pContext,
  2754. IN PSTR pszHeader,
  2755. IN PAFPROTOCOLS pProtocolArray,
  2756. IN DWORD ProtocolCount
  2757. );
  2758. VOID
  2759. DnsPrint_WsaQuerySet(
  2760. IN PRINT_ROUTINE PrintRoutine,
  2761. IN OUT PPRINT_CONTEXT pContext,
  2762. IN PSTR pszHeader,
  2763. IN LPWSAQUERYSET pQuerySet,
  2764. IN BOOL fUnicode
  2765. );
  2766. VOID
  2767. DnsPrint_WsaNsClassInfo(
  2768. IN PRINT_ROUTINE PrintRoutine,
  2769. IN OUT PPRINT_CONTEXT pContext,
  2770. IN PSTR pszHeader,
  2771. IN PWSANSCLASSINFO pInfo,
  2772. IN BOOL fUnicode
  2773. );
  2774. VOID
  2775. DnsPrint_WsaServiceClassInfo(
  2776. IN PRINT_ROUTINE PrintRoutine,
  2777. IN OUT PPRINT_CONTEXT pContext,
  2778. IN PSTR pszHeader,
  2779. IN LPWSASERVICECLASSINFO pInfo,
  2780. IN BOOL fUnicode
  2781. );
  2782. #endif
  2783. VOID
  2784. DnsPrint_Hostent(
  2785. IN PRINT_ROUTINE PrintRoutine,
  2786. IN OUT PPRINT_CONTEXT pContext,
  2787. IN PSTR pszHeader,
  2788. IN PHOSTENT pHostent,
  2789. IN BOOL fUnicode
  2790. );
  2791. //
  2792. // Print routines for DNS types and structures
  2793. //
  2794. VOID
  2795. DnsPrint_Message(
  2796. IN PRINT_ROUTINE PrintRoutine,
  2797. IN OUT PPRINT_CONTEXT pContext,
  2798. IN PSTR pszHeader,
  2799. IN PDNS_MSG_BUF pMsg
  2800. );
  2801. VOID
  2802. DnsPrint_MessageNoContext(
  2803. IN PRINT_ROUTINE PrintRoutine,
  2804. IN OUT PPRINT_CONTEXT pContext,
  2805. IN PSTR pszHeader,
  2806. IN PDNS_HEADER pMsgHead,
  2807. IN WORD wLength
  2808. );
  2809. INT
  2810. DnsPrint_PacketName(
  2811. IN PRINT_ROUTINE PrintRoutine,
  2812. IN OUT PPRINT_CONTEXT pContext,
  2813. IN PSTR pszHeader, OPTIONAL
  2814. IN PBYTE pMsgName,
  2815. IN PDNS_HEADER pMsgHead, OPTIONAL
  2816. IN PBYTE pMsgEnd, OPTIONAL
  2817. IN PSTR pszTrailer OPTIONAL
  2818. );
  2819. INT
  2820. DnsPrint_PacketRecord(
  2821. IN PRINT_ROUTINE PrintRoutine,
  2822. IN OUT PPRINT_CONTEXT pContext,
  2823. IN PSTR pszHeader,
  2824. IN PDNS_WIRE_RECORD pMsgRR,
  2825. IN PDNS_HEADER pMsgHead, OPTIONAL
  2826. IN PBYTE pMsgEnd OPTIONAL
  2827. );
  2828. VOID
  2829. DnsPrint_ParsedRecord(
  2830. IN PRINT_ROUTINE PrintRoutine,
  2831. IN OUT PPRINT_CONTEXT pContext,
  2832. IN PSTR pszHeader,
  2833. IN PDNS_PARSED_RR pParsedRR
  2834. );
  2835. VOID
  2836. DnsPrint_RawOctets(
  2837. IN PRINT_ROUTINE PrintRoutine,
  2838. IN OUT PPRINT_CONTEXT pContext,
  2839. IN PSTR pszHeader,
  2840. IN PSTR pszLineHeader,
  2841. IN PCHAR pchData,
  2842. IN DWORD dwLength
  2843. );
  2844. VOID
  2845. DnsPrint_ParsedMessage(
  2846. IN PRINT_ROUTINE PrintRoutine,
  2847. IN OUT PPRINT_CONTEXT pContext,
  2848. IN PSTR pszHeader,
  2849. IN PDNS_PARSED_MESSAGE pParsed
  2850. );
  2851. VOID
  2852. DnsPrint_HostentBlob(
  2853. IN PRINT_ROUTINE PrintRoutine,
  2854. IN OUT PPRINT_CONTEXT pContext,
  2855. IN PSTR pszHeader,
  2856. IN PHOSTENT_BLOB pBlob
  2857. );
  2858. //
  2859. // Print to string
  2860. //
  2861. #define GUID_STRING_BUFFER_LENGTH (80)
  2862. DWORD
  2863. DnsStringPrint_Guid(
  2864. OUT PCHAR pBuffer,
  2865. IN PGUID pGuid
  2866. );
  2867. DWORD
  2868. DnsStringPrint_RawOctets(
  2869. OUT PCHAR pBuffer,
  2870. IN PCHAR pchData,
  2871. IN DWORD dwLength,
  2872. IN PSTR pszLineHeader,
  2873. IN DWORD dwLineLength
  2874. );
  2875. //
  2876. // Print related utilities
  2877. //
  2878. INT
  2879. Dns_WriteFormattedSystemTimeToBuffer(
  2880. OUT PCHAR pBuffer,
  2881. IN PSYSTEMTIME pSystemTime
  2882. );
  2883. INT
  2884. Dns_WritePacketNameToBuffer(
  2885. OUT PCHAR pBuffer,
  2886. OUT PCHAR * ppBufferOut,
  2887. IN PBYTE pMsgName,
  2888. IN PDNS_HEADER pMsgHead, OPTIONAL
  2889. IN PBYTE pMsgEnd OPTIONAL
  2890. );
  2891. PCHAR
  2892. Dns_ResponseCodeString(
  2893. IN INT ResponseCode
  2894. );
  2895. PCHAR
  2896. Dns_ResponseCodeExplanationString(
  2897. IN INT ResponseCode
  2898. );
  2899. PCHAR
  2900. Dns_KeyFlagString(
  2901. IN OUT PCHAR pszBuff,
  2902. IN WORD flags
  2903. );
  2904. PCHAR
  2905. Dns_OpcodeString(
  2906. IN INT Opcode
  2907. );
  2908. CHAR
  2909. Dns_OpcodeCharacter(
  2910. IN INT Opcode
  2911. );
  2912. PCHAR
  2913. Dns_SectionNameString(
  2914. IN INT iSection,
  2915. IN INT iOpcode
  2916. );
  2917. //
  2918. // Record printing (rrprint.c)
  2919. //
  2920. VOID
  2921. DnsPrint_Record(
  2922. IN PRINT_ROUTINE PrintRoutine,
  2923. IN OUT PPRINT_CONTEXT pContext,
  2924. IN PSTR pszHeader,
  2925. IN PDNS_RECORD pRecord,
  2926. IN PDNS_RECORD pPreviousRecord OPTIONAL
  2927. );
  2928. VOID
  2929. DnsPrint_RecordSet(
  2930. IN PRINT_ROUTINE PrintRoutine,
  2931. IN OUT PPRINT_CONTEXT pContext,
  2932. IN PSTR pszHeader,
  2933. IN PDNS_RECORD pRecord
  2934. );
  2935. //
  2936. // Macros to get correct string type (utf8\unicode) for printing.
  2937. //
  2938. // Empty string for simple switching of UTF-8/Unicode print
  2939. extern DWORD DnsEmptyString;
  2940. #define pDnsEmptyString ( (PSTR) &DnsEmptyString )
  2941. #define pDnsEmptyWideString ( (PWSTR) &DnsEmptyString )
  2942. #define DNSSTRING_UTF8( fUnicode, String ) \
  2943. ( (fUnicode) ? pDnsEmptyString : (PSTR)(String) )
  2944. #define DNSSTRING_ANSI( fUnicode, String ) \
  2945. ( (fUnicode) ? pDnsEmptyString : (PSTR)(String) )
  2946. #define DNSSTRING_WIDE( fUnicode, String ) \
  2947. ( (fUnicode) ? (PWSTR)(String) : pDnsEmptyWideString )
  2948. #define RECSTRING_UTF8( pRR, String ) \
  2949. DNSSTRING_UTF8( IS_UNICODE_RECORD(pRR), (String) )
  2950. #define RECSTRING_WIDE( pRR, String ) \
  2951. DNSSTRING_WIDE( IS_UNICODE_RECORD(pRR), (String) )
  2952. #define PRINT_STRING_WIDE_CHARSET( String, CharSet ) \
  2953. ( ((CharSet)==DnsCharSetUnicode) ? (PWSTR)(String) : pDnsEmptyWideString )
  2954. #define PRINT_STRING_ANSI_CHARSET( String, CharSet ) \
  2955. ( ((CharSet)==DnsCharSetUnicode) ? pDnsEmptyString : (PSTR)(String) )
  2956. //
  2957. // Debugging
  2958. //
  2959. // Debug routines.
  2960. //
  2961. VOID
  2962. Dns_StartDebugEx(
  2963. IN DWORD DebugFlag,
  2964. IN PSTR pszFlagFile,
  2965. IN OUT PDWORD pdwExternalFlag,
  2966. IN PSTR pszLogFile,
  2967. IN DWORD WrapSize,
  2968. IN BOOL fUseGlobalFile,
  2969. IN BOOL fUseGlobalFlag,
  2970. IN BOOL fSetGlobals
  2971. );
  2972. VOID
  2973. Dns_StartDebug(
  2974. IN DWORD DebugFlag,
  2975. IN PSTR pszFlagFile,
  2976. IN OUT PDWORD pdwExternalFlag,
  2977. IN PSTR pszLogFile,
  2978. IN DWORD WrapSize
  2979. );
  2980. VOID
  2981. Dns_EndDebug(
  2982. VOID
  2983. );
  2984. VOID
  2985. Dns_Assert(
  2986. IN PSTR pszFile,
  2987. IN INT LineNo,
  2988. IN PSTR pszExpr
  2989. );
  2990. VOID
  2991. DnsDbg_PrintfToDebugger(
  2992. IN PSTR Format,
  2993. ...
  2994. );
  2995. VOID
  2996. DnsDbg_Printf(
  2997. IN PSTR Format,
  2998. ...
  2999. );
  3000. VOID
  3001. DnsDbg_PrintRoutine(
  3002. IN OUT PPRINT_CONTEXT pContext,
  3003. IN PSTR Format,
  3004. ...
  3005. );
  3006. VOID
  3007. DnsDbg_Flush(
  3008. VOID
  3009. );
  3010. VOID
  3011. DnsDbg_WrapLogFile(
  3012. VOID
  3013. );
  3014. VOID
  3015. DnsDbg_CSEnter(
  3016. IN PCRITICAL_SECTION pLock,
  3017. IN PSTR pszLockName,
  3018. IN PSTR pszFile,
  3019. IN INT LineNo
  3020. );
  3021. VOID
  3022. DnsDbg_CSLeave(
  3023. IN PCRITICAL_SECTION pLock,
  3024. IN PSTR pszLockName,
  3025. IN PSTR pszFile,
  3026. IN INT LineNo
  3027. );
  3028. //
  3029. // Debug flag test
  3030. //
  3031. // We make the test against a pointer here which allows library
  3032. // client application to point at a flag that may be dynamically
  3033. // reset.
  3034. //
  3035. extern PDWORD pDnsDebugFlag;
  3036. #define IS_DNSDBG_ON(flag) (*pDnsDebugFlag & DNS_DBG_ ## flag)
  3037. //
  3038. // Debugging Bit Flags
  3039. //
  3040. // These flags control gross output and are the same for all users
  3041. //
  3042. #define DNS_DBG_BREAKPOINTS 0x00000001
  3043. #define DNS_DBG_DEBUGGER 0x00000002
  3044. #define DNS_DBG_FILE 0x00000004
  3045. #define DNS_DBG_EVENTLOG 0x00000008
  3046. #define DNS_DBG_EXCEPT 0x00000008
  3047. #define DNS_DBG_TIMESTAMP 0x10000000
  3048. #define DNS_DBG_CONSOLE 0x20000000
  3049. #define DNS_DBG_START_BREAK 0x40000000
  3050. #define DNS_DBG_FLUSH 0x80000000
  3051. #define DNS_DBG_ANY 0xffffffff
  3052. #define DNS_DBG_ALL 0xffffffff
  3053. #define DNS_DBG_OFF (0x0)
  3054. //
  3055. // Flags specific to library
  3056. //
  3057. #define DNS_DBG_IPARRAY 0x00000020
  3058. #define DNS_DBG_INIT 0x00000040
  3059. #define DNS_DBG_REGISTRY 0x00000040
  3060. #define DNS_DBG_SOCKET 0x00000040
  3061. #define DNS_DBG_WRITE 0x00000080
  3062. #define DNS_DBG_READ 0x00000080
  3063. #define DNS_DBG_RPC 0x00000100
  3064. #define DNS_DBG_STUB 0x00000100
  3065. #define DNS_DBG_RECV 0x00000200
  3066. #define DNS_DBG_SEND 0x00000400
  3067. #define DNS_DBG_TCP 0x00000800
  3068. #define DNS_DBG_TRACE 0x00001000
  3069. #define DNS_DBG_HOSTENT 0x00001000
  3070. #define DNS_DBG_UPDATE 0x00002000
  3071. #define DNS_DBG_SECURITY 0x00004000
  3072. #define DNS_DBG_QUERY 0x00008000
  3073. #define DNS_DBG_HEAP 0x00010000
  3074. #define DNS_DBG_HEAPDBG 0x00020000
  3075. #define DNS_DBG_NETINFO 0x00040000
  3076. #define DNS_DBG_RNR 0x00080000
  3077. //
  3078. // High output detail debugging
  3079. //
  3080. #define DNS_DBG_RECURSE2 0x00100000
  3081. #define DNS_DBG_UPDATE2 0x00200000
  3082. #define DNS_DBG_SECURITY2 0x00400000
  3083. #define DNS_DBG_RPC2 0x01000000
  3084. #define DNS_DBG_STUB2 0x01000000
  3085. #define DNS_DBG_INIT2 0x01000000
  3086. #define DNS_DBG_NETINFO2 0x01000000
  3087. #define DNS_DBG_PARSE2 0x01000000
  3088. #define DNS_DBG_LOOKUP2 0x02000000
  3089. #define DNS_DBG_WRITE2 0x04000000
  3090. #define DNS_DBG_READ2 0x04000000
  3091. #define DNS_DBG_LOCK 0x08000000
  3092. #define DNS_DBG_LOCKS 0x08000000
  3093. #define DNS_DBG_STRING 0x10000000
  3094. #define DNS_DBG_HEAP2 0x10000000
  3095. #define DNS_DBG_HEAP_CHECK 0x10000000
  3096. //
  3097. // Debug macros
  3098. //
  3099. // Macros that include debug code in debug versions only,
  3100. // these macro are NULL for retail versions.
  3101. //
  3102. #if DBG
  3103. #define STATIC
  3104. #define DNS_PRINT(_a_) ( DnsDbg_Printf _a_ )
  3105. #define DnsPrintfPtrToFunc DnsDbg_PrintRoutine
  3106. #define IF_DNSDBG(flag) if ( IS_DNSDBG_ON(flag) )
  3107. #define ELSE_IF_DNSDBG(flag) else if ( IS_DNSDBG_ON(flag) )
  3108. #define ELSE else
  3109. #define DNSDBG(flag, _printlist_) \
  3110. IF_DNSDBG( flag ) \
  3111. { \
  3112. ( DnsDbg_Printf _printlist_ ); \
  3113. }
  3114. // protect debug prints with print lock
  3115. #define DnsDbg_Lock() DnsPrint_Lock()
  3116. #define DnsDbg_Unlock() DnsPrint_Unlock()
  3117. //
  3118. // Probe
  3119. //
  3120. #define PROBE(p) (*p)
  3121. //
  3122. // Assert Macros
  3123. //
  3124. #define DNS_ASSERT( expr ) \
  3125. { \
  3126. if ( !(expr) ) \
  3127. { \
  3128. Dns_Assert( __FILE__, __LINE__, # expr ); \
  3129. } \
  3130. }
  3131. #define TEST_ASSERT( expr ) DNS_ASSERT( expr )
  3132. #define FAIL( msg ) \
  3133. { \
  3134. DNS_PRINT(( "FAILURE: %s\n", msg )); \
  3135. DNS_ASSERT( FALSE ); \
  3136. }
  3137. //
  3138. // Asserts on trailing else
  3139. //
  3140. #define ELSE_ASSERT( expr ) \
  3141. else \
  3142. { \
  3143. DNS_ASSERT( expr ); \
  3144. }
  3145. #define ELSE_ASSERT_FALSE \
  3146. else \
  3147. { \
  3148. DNS_ASSERT( FALSE );\
  3149. }
  3150. #define ELSE_FAIL( msg ) \
  3151. else \
  3152. { \
  3153. FAIL( msg ); \
  3154. }
  3155. //
  3156. // Assert and print message
  3157. //
  3158. #define DNS_MSG_ASSERT( pMsg, expr ) \
  3159. { \
  3160. if ( !(expr) ) \
  3161. { \
  3162. debug_MessageBuffer( "FAILED MESSAGE:", (pMsg) ); \
  3163. Dns_Assert( __FILE__, __LINE__, # expr ); \
  3164. } \
  3165. }
  3166. //
  3167. // Debug types and structures
  3168. //
  3169. #define DnsPR DnsDbg_PrintRoutine
  3170. #define DnsDbg_String(a,b,c,d) DnsPrint_String(DnsPR,NULL,a,b,c,d)
  3171. #define DnsDbg_UnicodeStringBytes(a,b,c) DnsPrint_UnicodeStringBytes(DnsPR,NULL,a,b,c)
  3172. #define DnsDbg_Utf8StringBytes(a,b,c) DnsPrint_Utf8StringBytes(DnsPR,NULL,a,b,c)
  3173. #define DnsDbg_StringArray(a,b,c,d) DnsPrint_StringArray(DnsPR,NULL,a,b,c,d)
  3174. #define DnsDbg_Argv(a,b,c,d) DnsPrint_Argv(DnsPR,NULL,a,b,c,d)
  3175. #define DnsDbg_DwordArray(a,b,c,d) DnsPrint_DwordArray(DnsPR,NULL,a,b,c,d)
  3176. #define DnsDbg_IpAddressArray(a,b,c,d) DnsPrint_IpAddressArray(DnsPR,NULL,a,b,c,d)
  3177. #define DnsDbg_IpArray(a,b,c) DnsPrint_IpArray(DnsPR,NULL,a,b,c)
  3178. #define DnsDbg_Ip6Address(a,b,c) DnsPrint_Ip6Address(DnsPR,NULL,a,b,c)
  3179. #define DnsDbg_Guid(a,b) DnsPrint_Guid(DnsPR,NULL,a,b)
  3180. #define DnsDbg_FdSet(a,b) DnsPrint_FdSet(DnsPR,NULL,a,b)
  3181. #define DnsDbg_Sockaddr(a,b,c) DnsPrint_Sockaddr(DnsPR,NULL,a,0,b,c)
  3182. #define DnsDbg_SocketAddress(a,b) DnsPrint_SocketAddress(DnsPR,NULL,a,0,b)
  3183. #define DnsDbg_CsAddr(a,b) DnsPrint_CsAddr(DnsPR,NULL,a,0,b)
  3184. #define DnsDbg_AfProtocolsArray(a,b,c) DnsPrint_AfProtocolsArray(DnsPR,NULL,a,b,c)
  3185. #define DnsDbg_WsaQuerySet(a,b,c) DnsPrint_WsaQuerySet(DnsPR,NULL,a,b,c)
  3186. #define DnsDbg_WsaNsClassInfo(a,b,c) DnsPrint_WsaNsClassInfo(DnsPR,NULL,a,b,c)
  3187. #define DnsDbg_WsaServiceClassInfo(a,b,c) DnsPrint_WsaServiceClassInfo(DnsPR,NULL,a,b,c)
  3188. #define DnsDbg_Hostent(a,b,c) DnsPrint_Hostent(DnsPR,NULL,a,b,c)
  3189. #define DnsDbg_AddrInfo(a,b) DnsPrint_AddrInfo(DnsPR,NULL,a,0,b)
  3190. #define DnsDbg_HostentBlob(a,b) DnsPrint_HostentBlob(DnsPR,NULL,a,b)
  3191. #define DnsDbg_DnsMessage(a,b) DnsPrint_DnsMessage(DnsPR,NULL,a,b)
  3192. #define DnsDbg_Message(a,b) DnsPrint_Message(DnsPR,NULL,a,b)
  3193. #define DnsDbg_MessageNoContext(a,b,c) DnsPrint_MessageNoContext(DnsPR,NULL,a,b,c)
  3194. #define DnsDbg_Compression(a,b) DnsPrint_Compression(DnsPR,NULL,a,b)
  3195. #define DnsDbg_PacketRecord(a,b,c,d) DnsPrint_PacketRecord(DnsPR,NULL,a,b,c,d)
  3196. #define DnsDbg_PacketName(a,b,c,d,e) DnsPrint_PacketName(DnsPR,NULL,a,b,c,d,e)
  3197. #define DnsDbg_ParsedMessage(a,b) DnsPrint_ParsedMessage(DnsPR,NULL,(a),(b))
  3198. #define DnsDbg_RawOctets(a,b,c,d) DnsPrint_RawOctets(DnsPR,NULL,a,b,c,d)
  3199. #define DnsDbg_Record(a,b) DnsPrint_Record(DnsPR,NULL,a,b,NULL)
  3200. #define DnsDbg_RecordSet(a,b) DnsPrint_RecordSet(DnsPR,NULL,a,b)
  3201. // backcompat special on sockaddr
  3202. #define DnsDbg_SockaddrIn(a,b,c) DnsPrint_Sockaddr(DnsPR,NULL,a,0,(PSOCKADDR)b,c)
  3203. //
  3204. // Non-Debug
  3205. //
  3206. #else
  3207. #define STATIC static
  3208. //
  3209. // Define away debugging operations
  3210. //
  3211. #define IF_DNSDBG(a) if (0)
  3212. #define ELSE_IF_DNSDBG(a) if (0)
  3213. #define ELSE if (0)
  3214. #define DNSDBG(flag, _printlist_)
  3215. #define DNS_PRINT(_printlist_)
  3216. #define DnsDbg_Lock()
  3217. #define DnsDbg_Unlock()
  3218. #define DnsDbg_CSEnter(a,b,c,d)
  3219. #define DnsDbg_CSLeave(a,b,c,d)
  3220. #define DnsDbg_String(a,b,c,d)
  3221. #define DnsDbg_UnicodeStringBytes(a,b,c)
  3222. #define DnsDbg_Utf8StringBytes(a,b,c)
  3223. #define DnsDbg_DwordArray(a,b,c,d)
  3224. #define DnsDbg_StringArray(a,b,c,d)
  3225. #define DnsDbg_Argv(a,b,c,d)
  3226. #define DnsDbg_IpAddressArray(a,b,c,d)
  3227. #define DnsDbg_IpArray(a,b,c)
  3228. #define DnsDbg_Ip6Address(a,b,c)
  3229. #define DnsDbg_Guid(a,b)
  3230. #define DnsDbg_FdSet(a,b)
  3231. #define DnsDbg_Sockaddr(a,b,c)
  3232. #define DnsDbg_SocketAddress(a,b)
  3233. #define DnsDbg_CsAddr(a,b)
  3234. #define DnsDbg_AfProtocolsArray(a,b,c)
  3235. #define DnsDbg_WsaQuerySet(a,b,c)
  3236. #define DnsDbg_WsaNsClassInfo(a,b,c)
  3237. #define DnsDbg_WsaServiceClassInfo(a,b,c)
  3238. #define DnsDbg_Hostent(a,b,c)
  3239. #define DnsDbg_AddrInfo(a,b)
  3240. #define DnsDbg_HostentBlob(a,b)
  3241. #define DnsDbg_DnsMessage(a,b)
  3242. #define DnsDbg_Message(a,b)
  3243. #define DnsDbg_MessageNoContext(a,b,c)
  3244. #define DnsDbg_Compression(a,b)
  3245. #define DnsDbg_PacketRecord(a,b,c,d)
  3246. #define DnsDbg_PacketName(a,b,c,d,e)
  3247. #define DnsDbg_ParsedMessage(a,b)
  3248. #define DnsDbg_RawOctets(a,b,c,d)
  3249. #define DnsDbg_Record(a,b)
  3250. #define DnsDbg_RecordSet(a,b)
  3251. // backcompat special on sockaddr
  3252. #define DnsDbg_SockaddrIn(a,b,c)
  3253. //
  3254. // Handle complilation of DnsPrintf used as passed parameter to
  3255. // print routines
  3256. //
  3257. #define DnsPrintfPtrToFunc printf
  3258. //
  3259. // Eliminate ASSERTs in retail product
  3260. //
  3261. #define DNS_ASSERT( expr )
  3262. #define TEST_ASSERT( expr )
  3263. #define ELSE_ASSERT( expr )
  3264. #define ELSE_ASSERT_FALSE
  3265. #define DNS_MSG_ASSERT( expr, pMsg )
  3266. #define FAIL( msg )
  3267. #define ELSE_FAIL( msg )
  3268. #define PROBE(p)
  3269. #endif // non-DBG
  3270. #ifdef __cplusplus
  3271. }
  3272. #endif // __cplusplus
  3273. #endif // _DNSLIB_INCLUDED_