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.

258 lines
6.2 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. VOID
  26. CallBack (
  27. DWORD dwStatus,
  28. LPVOID pvData
  29. );
  30. INT __cdecl
  31. main (int argc, char *argv[])
  32. {
  33. DWORD dwRes;
  34. DWORD iter;
  35. BOOL fRegisterForwards = FALSE;
  36. DWORD dwOperation = DYNDNS_ADD_ENTRY;
  37. DWORD StartPart1, StartPart2, StartPart3, StartPart4;
  38. DWORD EndPart1, EndPart2, EndPart3, EndPart4;
  39. DWORD StartIPReversed, EndIPReversed;
  40. REGISTER_HOST_ENTRY HostAddr;
  41. LPSTR lpTemp = NULL;
  42. LPSTR pszDomainName = NULL;
  43. LPSTR pszAddressStart = NULL;
  44. LPSTR pszAddressEnd = NULL;
  45. CHAR c;
  46. if ( argc < 4 )
  47. {
  48. printf( "\nUsage: dhcpreg <DNS Domain Name> <IP Address Range> [/f /d]\n" );
  49. printf( "\nWhere:\n" );
  50. printf( " DNS Domain Name - ntdev.microsoft.com\n" );
  51. printf( " IP Address Range - 1.2.0.0 1.2.50.255\n" );
  52. printf( " Options:\n" );
  53. printf( " /f - Register forward addresses\n" );
  54. printf( " /d - Delete registered records\n" );
  55. return(-1);
  56. }
  57. pszDomainName = argv[1];
  58. pszAddressStart = argv[2];
  59. pszAddressEnd = argv[3];
  60. if ( argc > 4 )
  61. {
  62. if ( !strcmp( argv[4], "/f" ) )
  63. fRegisterForwards = TRUE;
  64. else if ( !strcmp( argv[4], "/d" ) )
  65. dwOperation = DYNDNS_DELETE_ENTRY;
  66. if ( argc > 5 )
  67. {
  68. if ( !strcmp( argv[5], "/f" ) )
  69. fRegisterForwards = TRUE;
  70. else if ( !strcmp( argv[5], "/d" ) )
  71. dwOperation = DYNDNS_DELETE_ENTRY;
  72. }
  73. }
  74. lpTemp = strtok( pszAddressStart, "." );
  75. StartPart1 = atoi( lpTemp );
  76. lpTemp = strtok( NULL, "." );
  77. StartPart2 = atoi( lpTemp );
  78. lpTemp = strtok( NULL, "." );
  79. StartPart3 = atoi( lpTemp );
  80. lpTemp = strtok( NULL, "." );
  81. StartPart4 = atoi( lpTemp );
  82. lpTemp = strtok( pszAddressEnd, "." );
  83. EndPart1 = atoi( lpTemp );
  84. lpTemp = strtok( NULL, "." );
  85. EndPart2 = atoi( lpTemp );
  86. lpTemp = strtok( NULL, "." );
  87. EndPart3 = atoi( lpTemp );
  88. lpTemp = strtok( NULL, "." );
  89. EndPart4 = atoi( lpTemp );
  90. if ( dwOperation == DYNDNS_DELETE_ENTRY )
  91. {
  92. printf( "\nDeregistering DNS records with:\n" );
  93. printf( "Domain Name: %s\n", pszDomainName );
  94. printf( "Address range: %d.%d.%d.%d to %d.%d.%d.%d\n",
  95. StartPart1, StartPart2, StartPart3, StartPart4,
  96. EndPart1, EndPart2, EndPart3, EndPart4 );
  97. printf( "Register forwards: %s\n", fRegisterForwards ? "TRUE" : "FALSE" );
  98. }
  99. else
  100. {
  101. printf( "\nRegistering DNS records with:\n" );
  102. printf( "Domain Name: %s\n", pszDomainName );
  103. printf( "Address range: %d.%d.%d.%d to %d.%d.%d.%d\n",
  104. StartPart1, StartPart2, StartPart3, StartPart4,
  105. EndPart1, EndPart2, EndPart3, EndPart4 );
  106. printf( "Register forwards: %s\n", fRegisterForwards ? "TRUE" : "FALSE" );
  107. }
  108. StartIPReversed = (DWORD)(StartPart4) + (DWORD)(StartPart3 << 8) +
  109. (DWORD)(StartPart2 << 16) + (DWORD)(StartPart1 << 24);
  110. EndIPReversed = (DWORD)(EndPart4) + (DWORD)(EndPart3 << 8) +
  111. (DWORD)(EndPart2 << 16) + (DWORD)(EndPart1 << 24);
  112. //
  113. // set up stuff for registration
  114. //
  115. dwRes = DnsDhcpSrvRegisterInit();
  116. if ( dwRes )
  117. printf("Init failed with %x\n", dwRes);
  118. for ( iter = StartIPReversed; iter < EndIPReversed; iter++ )
  119. {
  120. CHAR szName[260];
  121. DWORD IP = iter;
  122. BYTE Temp;
  123. DWORD dwFlags = 0;
  124. LPSTR pszAddr = LocalAlloc( LPTR, 20 );
  125. Temp = ((LPBYTE)&IP)[3];
  126. ((LPBYTE)&IP)[3] = ((LPBYTE)&IP)[0];
  127. ((LPBYTE)&IP)[0] = Temp;
  128. Temp = ((LPBYTE)&IP)[2];
  129. ((LPBYTE)&IP)[2] = ((LPBYTE)&IP)[1];
  130. ((LPBYTE)&IP)[1] = Temp;
  131. if ( dwOperation == DYNDNS_DELETE_ENTRY )
  132. printf( "\nDeregistering DNS record for:\n" );
  133. else
  134. printf( "\nRegistering DNS record for:\n" );
  135. if ( pszAddr )
  136. {
  137. sprintf( pszAddr, "%d.%d.%d.%d",
  138. ((LPBYTE)&IP)[0],
  139. ((LPBYTE)&IP)[1],
  140. ((LPBYTE)&IP)[2],
  141. ((LPBYTE)&IP)[3] );
  142. }
  143. sprintf( szName, "%d-%d-%d-%d.%s",
  144. ((LPBYTE)&IP)[0],
  145. ((LPBYTE)&IP)[1],
  146. ((LPBYTE)&IP)[2],
  147. ((LPBYTE)&IP)[3],
  148. pszDomainName );
  149. if ( pszAddr )
  150. printf( "Address: %s\n", pszAddr );
  151. printf( "Name: %s\n", szName );
  152. HostAddr.dwOptions = REGISTER_HOST_PTR;
  153. HostAddr.Addr.ipAddr = IP;
  154. if ( fRegisterForwards )
  155. dwFlags = DYNDNS_REG_FORWARD;
  156. dwFlags |= dwOperation;
  157. dwRes = DnsDhcpSrvRegisterHostName_A (
  158. HostAddr,
  159. szName,
  160. 600, //10 mins of Time to live
  161. dwFlags,
  162. (DHCP_CALLBACK_FN)&CallBack,
  163. (PVOID) pszAddr
  164. );
  165. if ( dwRes )
  166. printf("Host Name registration failed with %x\n", dwRes);
  167. Sleep( 1000 );
  168. }
  169. c = getchar();
  170. dwRes = DnsDhcpSrvRegisterTerm();
  171. if ( dwRes )
  172. printf("Termination failed with %x\n", dwRes);
  173. c = getchar();
  174. error:
  175. return(1);
  176. }
  177. VOID
  178. CallBack (
  179. DWORD dwStatus,
  180. LPVOID pvData
  181. )
  182. {
  183. //
  184. // callback functionality testing
  185. //
  186. LPSTR pszData = (LPSTR)pvData;
  187. printf("Registration of %s returned with Error Code %x \n", pszData,
  188. dwStatus );
  189. LocalFree(pszData);
  190. }