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.

344 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. adddom.c
  5. Abstract:
  6. Domain Name System (DNS) Server
  7. Test Code for adding a Zone
  8. Author:
  9. Ram Viswanathan (ramv) 14th March 1997
  10. Revision History:
  11. Ram Viswanathan (ramv) 14th March 1997 Created
  12. 5th May 1997 Added Callback function testing
  13. --*/
  14. #include <windows.h>
  15. //
  16. // ********* CRunTime Includes
  17. //
  18. #include <stdlib.h>
  19. #include <limits.h>
  20. #include <io.h>
  21. #include <stdio.h>
  22. #include "dns.h"
  23. #include "dnsapi.h"
  24. #include "dnslib.h"
  25. INT __cdecl
  26. main (int argc, char *argv[])
  27. {
  28. DWORD dwRes;
  29. LPSTR pszMapFile = NULL;
  30. INT i;
  31. BOOL fDownLevel =FALSE;
  32. DWORD dwOperation = DYNDNS_ADD_ENTRY;
  33. LPSTR lpTemp = NULL;
  34. DWORD Part1, Part2, Part3, Part4;
  35. FILE *fp = NULL;
  36. CHAR szInputString[MAX_PATH];
  37. CHAR szAddr[20];
  38. LPSTR pszAddr = NULL;
  39. CHAR szName[50];
  40. CHAR c;
  41. DWORD dwFlags = 0;
  42. char seps[]=" ,\t\n";
  43. CHAR AdapterName[50];
  44. CHAR HostName[50];
  45. CHAR DomainName[50];
  46. INT ipAddrCount;
  47. REGISTER_HOST_ENTRY HostAddrs[5];
  48. char *token;
  49. //
  50. // 1st argument is a/d (for add or delete)
  51. // 2nd argument is f/n (register forwards/not register forwards)
  52. // 3rd argument is filename
  53. // Note that no optional parameters are set
  54. //
  55. if (argc != 2){
  56. printf("Usage is %s filename \n", argv[0]);
  57. exit(-1);
  58. }
  59. pszMapFile = argv[1];
  60. //
  61. // set up stuff for registration
  62. //
  63. dwRes = DnsAsyncRegisterInit(NULL);
  64. if (dwRes){
  65. printf("Init failed with %x\n", dwRes);
  66. }
  67. if (!(fp = fopen (pszMapFile, "r+"))){
  68. printf(" Could not open map file %s \n", pszMapFile);
  69. }
  70. while (fgets (szInputString, MAX_PATH, fp) != NULL){
  71. //
  72. // parse the input string
  73. //
  74. token = strtok(szInputString, seps);
  75. strcpy (AdapterName, token);
  76. token =strtok(NULL, seps);
  77. strcpy (HostName, token);
  78. token =strtok(NULL, seps);
  79. strcpy (DomainName, token);
  80. ipAddrCount = 0;
  81. token =strtok(NULL, seps);
  82. while ( token != NULL){
  83. strcpy (szAddr, token);
  84. lpTemp = strtok( szAddr, "." );
  85. Part1 = atoi( lpTemp );
  86. lpTemp = strtok( NULL, "." );
  87. Part2 = atoi( lpTemp );
  88. lpTemp = strtok( NULL, "." );
  89. Part3 = atoi( lpTemp );
  90. lpTemp = strtok( NULL, "." );
  91. Part4 = atoi( lpTemp );
  92. printf( "\nRegistering DNS record for:\n" );
  93. printf("AdapterName = %s\n", AdapterName);
  94. printf("HostName = %s\n", HostName);
  95. printf("DomainName = %s\n", DomainName);
  96. printf( "Address: %d.%d.%d.%d\n", Part1, Part2, Part3, Part4 );
  97. HostAddrs[ipAddrCount].dwOptions = REGISTER_HOST_PTR;
  98. HostAddrs[ipAddrCount].Addr.ipAddr = (DWORD)(Part1) + (DWORD)(Part2 << 8) +
  99. (DWORD)(Part3 << 16) + (DWORD)(Part4 << 24);
  100. ipAddrCount++;
  101. token =strtok(NULL, seps);
  102. }
  103. dwRes = DnsAsyncRegisterHostAddrs_A (
  104. AdapterName,
  105. HostName,
  106. HostAddrs,
  107. ipAddrCount,
  108. NULL,
  109. 0,
  110. DomainName,
  111. NULL,
  112. 40,
  113. 0
  114. );
  115. if (dwRes){
  116. printf("Host Name registration failed with %x\n", dwRes);
  117. }
  118. }
  119. fclose(fp);
  120. printf("Hit Enter to do the ipconfig /release now! \n");
  121. c = getchar();
  122. //
  123. // do the releases now
  124. //
  125. if (!(fp = fopen (pszMapFile, "r+"))){
  126. printf(" Could not open map file %s \n", pszMapFile);
  127. }
  128. while (fgets (szInputString, MAX_PATH, fp) != NULL){
  129. //
  130. // parse the input string
  131. //
  132. token = strtok(szInputString, seps);
  133. strcpy (AdapterName, token);
  134. token =strtok(NULL, seps);
  135. strcpy (HostName, token);
  136. token =strtok(NULL, seps);
  137. strcpy (DomainName, token);
  138. ipAddrCount = 0;
  139. token =strtok(NULL, seps);
  140. while ( token != NULL){
  141. strcpy (szAddr, token);
  142. lpTemp = strtok( szAddr, "." );
  143. Part1 = atoi( lpTemp );
  144. lpTemp = strtok( NULL, "." );
  145. Part2 = atoi( lpTemp );
  146. lpTemp = strtok( NULL, "." );
  147. Part3 = atoi( lpTemp );
  148. lpTemp = strtok( NULL, "." );
  149. Part4 = atoi( lpTemp );
  150. printf( "\nRegistering DNS record for:\n" );
  151. printf("AdapterName = %s\n", AdapterName);
  152. printf("HostName = %s\n", HostName);
  153. printf("DomainName = %s\n", DomainName);
  154. printf( "Address: %d.%d.%d.%d\n", Part1, Part2, Part3, Part4 );
  155. HostAddrs[ipAddrCount].dwOptions = REGISTER_HOST_PTR;
  156. HostAddrs[ipAddrCount].Addr.ipAddr = (DWORD)(Part1) + (DWORD)(Part2 << 8) +
  157. (DWORD)(Part3 << 16) + (DWORD)(Part4 << 24);
  158. ipAddrCount++;
  159. token =strtok(NULL, seps);
  160. }
  161. dwRes = DnsAsyncRegisterHostAddrs_A (
  162. AdapterName,
  163. HostName,
  164. HostAddrs,
  165. ipAddrCount,
  166. NULL,
  167. 0,
  168. DomainName,
  169. NULL,
  170. 40,
  171. DYNDNS_DEL_ENTRY
  172. );
  173. if (dwRes){
  174. printf("Host Name registration failed with %x\n", dwRes);
  175. }
  176. }
  177. fclose(fp);
  178. printf("Hit Enter to do the ipconfig /renew now! \n");
  179. c = getchar();
  180. if (!(fp = fopen (pszMapFile, "r+"))){
  181. printf(" Could not open map file %s \n", pszMapFile);
  182. }
  183. while (fgets (szInputString, MAX_PATH, fp) != NULL){
  184. //
  185. // parse the input string
  186. //
  187. token = strtok(szInputString, seps);
  188. strcpy (AdapterName, token);
  189. token =strtok(NULL, seps);
  190. strcpy (HostName, token);
  191. token =strtok(NULL, seps);
  192. strcpy (DomainName, token);
  193. ipAddrCount = 0;
  194. token =strtok(NULL, seps);
  195. while ( token != NULL){
  196. strcpy (szAddr, token);
  197. lpTemp = strtok( szAddr, "." );
  198. Part1 = atoi( lpTemp );
  199. lpTemp = strtok( NULL, "." );
  200. Part2 = atoi( lpTemp );
  201. lpTemp = strtok( NULL, "." );
  202. Part3 = atoi( lpTemp );
  203. lpTemp = strtok( NULL, "." );
  204. Part4 = atoi( lpTemp );
  205. printf( "\nRegistering DNS record for:\n" );
  206. printf("AdapterName = %s\n", AdapterName);
  207. printf("HostName = %s\n", HostName);
  208. printf("DomainName = %s\n", DomainName);
  209. printf( "Address: %d.%d.%d.%d\n", Part1, Part2, Part3, Part4 );
  210. HostAddrs[ipAddrCount].dwOptions = REGISTER_HOST_PTR;
  211. HostAddrs[ipAddrCount].Addr.ipAddr = (DWORD)(Part1) + (DWORD)(Part2 << 8) +
  212. (DWORD)(Part3 << 16) + (DWORD)(Part4 << 24);
  213. ipAddrCount++;
  214. token =strtok(NULL, seps);
  215. }
  216. dwRes = DnsAsyncRegisterHostAddrs_A (
  217. AdapterName,
  218. HostName,
  219. HostAddrs,
  220. ipAddrCount,
  221. NULL,
  222. 0,
  223. DomainName,
  224. NULL,
  225. 40,
  226. 0
  227. );
  228. if (dwRes){
  229. printf("Host Name registration failed with %x\n", dwRes);
  230. }
  231. }
  232. fclose(fp);
  233. c = getchar();
  234. dwRes = DnsAsyncRegisterTerm();
  235. if (dwRes){
  236. printf("Termination failed with %x\n", dwRes);
  237. }
  238. c = getchar();
  239. error:
  240. return(1);
  241. }