Leaked source code of windows server 2003
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.

391 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. resolver.h
  5. Abstract:
  6. Definitions etc. for Berkeley resolver
  7. Author:
  8. Richard L Firth (rfirth) 15-Jun-1996
  9. Revision History:
  10. 15-Jun-1996 rfirth
  11. Created
  12. --*/
  13. //
  14. // includes
  15. //
  16. #include <nameser.h>
  17. #include <resolv.h>
  18. //
  19. // manifests
  20. //
  21. #if PACKETSZ > 1024
  22. #define MAXPACKET PACKETSZ
  23. #else
  24. #define MAXPACKET 1024
  25. #endif
  26. #define DBG_RESOLVER DBG_SOCKETS
  27. #define DBG_VXD_IO DBG_SOCKETS
  28. #define DLL_PRINT(x) DEBUG_PRINT(SOCKETS, INFO, x)
  29. #define WS_PRINT(x) DEBUG_PRINT(SOCKETS, INFO, x)
  30. #define WS_ASSERT INET_ASSERT
  31. #define DLL_ASSERT INET_ASSERT
  32. //
  33. // macros
  34. //
  35. #ifndef unix
  36. #define bcopy(s, d, c) memcpy((u_char *)(d), (u_char *)(s), (c))
  37. #define bzero(d, l) memset((d), '\0', (l))
  38. #endif /* unix */
  39. #define bcmp(s1, s2, l) memcmp((s1), (s2), (l))
  40. #define IS_DGRAM_SOCK(type) (((type) == SOCK_DGRAM) || ((type) == SOCK_RAW))
  41. //
  42. // types
  43. //
  44. typedef union {
  45. HEADER hdr;
  46. unsigned char buf[MAXPACKET];
  47. } querybuf;
  48. typedef union {
  49. long al;
  50. char ac;
  51. } align;
  52. //extern char VTCPPARM[];
  53. //extern char NTCPPARM[];
  54. //extern char TCPPARM[];
  55. //extern char TTCPPARM[];
  56. #ifndef unix
  57. typedef long daddr_t;
  58. typedef char FAR * caddr_t;
  59. struct iovec {
  60. caddr_t iov_base;
  61. int iov_len;
  62. };
  63. struct uio {
  64. struct iovec *uio_iov;
  65. int uio_iovcnt;
  66. int uio_offset;
  67. int uio_segflg;
  68. int uio_resid;
  69. };
  70. enum uio_rw { UIO_READ, UIO_WRITE };
  71. #endif /* unix */
  72. /*
  73. * Segment flag values (should be enum).
  74. */
  75. #define UIO_USERSPACE 0 /* from user data space */
  76. #define UIO_SYSSPACE 1 /* from system space */
  77. #define UIO_USERISPACE 2 /* from user I space */
  78. #define MAXALIASES 35
  79. #define MAXADDRS 35
  80. #define HOSTDB_SIZE (_MAX_PATH + 7) // 7 == strlen("\\hosts") + 1
  81. #define PROTODB_SIZE (_MAX_PATH + 10)
  82. #define SERVDB_SIZE (_MAX_PATH + 10)
  83. typedef struct _WINSOCK_TLS_DATA {
  84. char * GETHOST_h_addr_ptrs[MAXADDRS + 1];
  85. struct hostent GETHOST_host;
  86. char * GETHOST_host_aliases[MAXALIASES];
  87. char GETHOST_hostbuf[BUFSIZ + 1];
  88. //struct in_addr GETHOST_host_addr;
  89. //char GETHOST_HOSTDB[HOSTDB_SIZE];
  90. //FILE *GETHOST_hostf;
  91. //char GETHOST_hostaddr[MAXADDRS];
  92. //char *GETHOST_host_addrs[2];
  93. //int GETHOST_stayopen;
  94. //char GETPROTO_PROTODB[PROTODB_SIZE];
  95. //FILE *GETPROTO_protof;
  96. //char GETPROTO_line[BUFSIZ+1];
  97. //struct protoent GETPROTO_proto;
  98. //char *GETPROTO_proto_aliases[MAXALIASES];
  99. //int GETPROTO_stayopen;
  100. //char GETSERV_SERVDB[SERVDB_SIZE];
  101. //FILE *GETSERV_servf;
  102. //char GETSERV_line[BUFSIZ+1];
  103. //struct servent GETSERV_serv;
  104. //char *GETSERV_serv_aliases[MAXALIASES];
  105. //int GETSERV_stayopen;
  106. struct state R_INIT__res;
  107. //char INTOA_Buffer[18];
  108. //CSOCKET * DnrSocketHandle;
  109. //BOOLEAN IsBlocking;
  110. BOOLEAN IoCancelled;
  111. //BOOLEAN ProcessingGetXByY;
  112. BOOLEAN GetXByYCancelled;
  113. //BOOLEAN EnableWinsNameResolution;
  114. //BOOLEAN DisableWinsNameResolution;
  115. //SOCKET SocketHandle;
  116. //PBLOCKING_HOOK BlockingHook;
  117. //HANDLE EventHandle;
  118. //ULONG CreateOptions;
  119. INT DnrErrorCode;
  120. //#if DBG
  121. // ULONG IndentLevel;
  122. //#endif
  123. } WINSOCK_TLS_DATA, * LPWINSOCK_TLS_DATA;
  124. //extern DWORD SockTlsSlot;
  125. //#define ACCESS_THREAD_DATA(a, file) \
  126. // (((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))-> \
  127. // ## file ## _ ## a )
  128. #define ACCESS_THREAD_DATA(a, file) (lpResolverInfo->file ## _ ## a)
  129. #define _h_addr_ptrs ACCESS_THREAD_DATA(h_addr_ptrs, GETHOST)
  130. #define _host ACCESS_THREAD_DATA(host, GETHOST)
  131. #define _host_aliases ACCESS_THREAD_DATA(host_aliases, GETHOST)
  132. #define _hostbuf ACCESS_THREAD_DATA(hostbuf, GETHOST)
  133. #define _host_addr ACCESS_THREAD_DATA(host_addr, GETHOST)
  134. //#define HOSTDB ACCESS_THREAD_DATA(HOSTDB, GETHOST)
  135. //#define hostf ACCESS_THREAD_DATA(hostf, GETHOST)
  136. //#define hostaddr ACCESS_THREAD_DATA(hostaddr, GETHOST)
  137. //#define host_addrs ACCESS_THREAD_DATA(host_addrs, GETHOST)
  138. //#define stayopen ACCESS_THREAD_DATA(stayopen, GETHOST)
  139. #define _res ACCESS_THREAD_DATA( _res, R_INIT )
  140. //#define SockThreadProcessingGetXByY lpResolverInfo->ProcessingGetXByY
  141. #define SockThreadGetXByYCancelled lpResolverInfo->GetXByYCancelled
  142. #define SockDnrSocket lpResolverInfo->DnrSocketHandle
  143. #define SockThreadDnrErrorCode lpResolverInfo->DnrErrorCode
  144. //#define SockThreadIsBlocking \
  145. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->IsBlocking )
  146. //
  147. //#define SockThreadIoCancelled \
  148. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->IoCancelled )
  149. //
  150. //#define SockThreadProcessingGetXByY \
  151. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->ProcessingGetXByY )
  152. //
  153. //#define SockThreadGetXByYCancelled \
  154. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->GetXByYCancelled )
  155. //
  156. //#define SockThreadSocketHandle \
  157. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->SocketHandle )
  158. //
  159. //#define SockThreadBlockingHook \
  160. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->BlockingHook )
  161. //
  162. //#define SockThreadEvent \
  163. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->EventHandle )
  164. //
  165. //#define SockDnrSocket \
  166. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->DnrSocketHandle )
  167. //
  168. //#define SockEnableWinsNameResolution \
  169. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->EnableWinsNameResolution )
  170. //
  171. //#define SockDisableWinsNameResolution \
  172. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->DisableWinsNameResolution )
  173. //
  174. //#define SockCreateOptions \
  175. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->CreateOptions )
  176. //
  177. //#define SockThreadDnrErrorCode \
  178. // ( ((LPWINSOCK_TLS_DATA)TlsGetValue( SockTlsSlot ))->DnrErrorCode )
  179. #define LPSOCK_THREAD LPWINSOCK_TLS_DATA
  180. #define GET_THREAD_DATA(p) p = InternetGetResolverInfo()
  181. //#define I_SetLastError SetLastError
  182. #define DllAllocMem(n) ALLOCATE_MEMORY(LMEM_FIXED, n)
  183. #define DllFreeMem FREE_MEMORY
  184. //
  185. // well-known DHCP VxD ID (from netvxd.h)
  186. //
  187. #define VDHCP_Device_ID 0x049A
  188. //
  189. // prototypes
  190. //
  191. int
  192. dn_expand(
  193. IN unsigned char *msg,
  194. IN unsigned char *eomorig,
  195. IN unsigned char *comp_dn,
  196. OUT unsigned char *exp_dn,
  197. IN int length
  198. );
  199. static
  200. int
  201. dn_find(
  202. unsigned char *exp_dn,
  203. unsigned char *msg,
  204. unsigned char **dnptrs,
  205. unsigned char **lastdnptr
  206. );
  207. int
  208. dn_skipname(
  209. unsigned char *comp_dn,
  210. unsigned char *eom
  211. );
  212. void
  213. fp_query(
  214. char *msg,
  215. FILE *file
  216. );
  217. //int
  218. //gethostname(
  219. // OUT char *name,
  220. // IN int namelen
  221. // );
  222. void
  223. p_query(
  224. char *msg
  225. );
  226. extern
  227. void
  228. putshort(
  229. u_short s,
  230. u_char *msgp
  231. );
  232. void
  233. putlong(
  234. u_long l,
  235. u_char *msgp
  236. );
  237. void
  238. _res_close(
  239. void
  240. );
  241. //DWORD
  242. //sendv(
  243. // CSOCKET * s, /* socket descriptor */
  244. // struct iovec *iov, /* array of vectors */
  245. // int iovcnt /* size of array */
  246. // );
  247. //int
  248. //strcasecmp(
  249. // char *s1,
  250. // char *s2
  251. // );
  252. //
  253. //int
  254. //strncasecmp(
  255. // char *s1,
  256. // char *s2,
  257. // int n
  258. // );
  259. //
  260. //struct hostent *
  261. //myhostent (
  262. // void
  263. // );
  264. //
  265. //struct hostent *
  266. //localhostent (
  267. // void
  268. // );
  269. //
  270. //struct hostent *
  271. //dnshostent (
  272. // void
  273. // );
  274. //
  275. //BOOL
  276. //querydnsaddrs (
  277. // IN LPDWORD *Array,
  278. // IN PVOID Buffer
  279. // );
  280. //
  281. //DWORD
  282. //BytesInHostent (
  283. // PHOSTENT Hostent
  284. // );
  285. //
  286. //DWORD
  287. //CopyHostentToBuffer (
  288. // char FAR *Buffer,
  289. // int BufferLength,
  290. // PHOSTENT Hostent
  291. // );
  292. //
  293. //struct hostent *
  294. //_gethtbyname (
  295. // IN char *name
  296. // );
  297. BOOL
  298. OkToUseInternetAsyncGetHostByName(
  299. VOID
  300. );
  301. LPHOSTENT
  302. InternetAsyncGetHostByName(
  303. IN LPSTR lpszHostName,
  304. OUT LPDWORD lpdwTtl
  305. );
  306. LPWINSOCK_TLS_DATA
  307. InternetGetResolverInfo(
  308. VOID
  309. );
  310. LPHOSTENT
  311. getanswer(
  312. OUT querybuf *answer,
  313. OUT int *ttl,
  314. IN int anslen,
  315. IN int iquery
  316. );
  317. //ULONG
  318. //SockNbtResolveName (
  319. // IN PCHAR Name
  320. // );
  321. //PHOSTENT
  322. //QueryHostentCache (
  323. // IN LPSTR Name OPTIONAL,
  324. // IN DWORD IpAddress OPTIONAL
  325. // );
  326. //FILE *
  327. //SockOpenNetworkDataBase(
  328. // IN char *Database,
  329. // OUT char *Pathname,
  330. // IN int PathnameLen,
  331. // IN char *OpenFlags
  332. // );
  333. //