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.

2821 lines
73 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. testapis.c
  5. Abstract:
  6. This file contains program to test all DHCP APIs.
  7. Author:
  8. Madan Appiah (madana) 15-Sep-1993
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <winsock.h>
  18. #include <dhcp.h>
  19. #include <dhcpapi.h>
  20. #include <dhcplib.h>
  21. #include <stdio.h>
  22. #include <ctype.h>
  23. #include <wchar.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include <time.h>
  27. #define OPTION_DATA_NUM_ELEMENT 4
  28. #define RANDOM_STRING_MAX_LEN 16
  29. #define RANDOM_BINARY_DATA_MAX_LEN 32
  30. #define SCRATCH_BUFFER_SIZE 4096 // 4K
  31. #define SCRATCH_SMALL_BUFFER_SIZE 64
  32. #define CREATE_MAX_OPTION_VALUES 10
  33. #define NUM_KNOWN_OPTIONS 8
  34. #define CLIENT_COUNT 40
  35. BYTE GlobalScratchBuffer[SCRATCH_BUFFER_SIZE];
  36. LPBYTE GlobalScratchBufferEnd =
  37. GlobalScratchBuffer + SCRATCH_BUFFER_SIZE;
  38. LPWSTR GlobalServerIpAddress;
  39. #if DBG
  40. VOID
  41. DhcpPrintRoutine(
  42. IN DWORD DebugFlag,
  43. IN LPSTR Format,
  44. ...
  45. )
  46. {
  47. #define MAX_PRINTF_LEN 1024 // Arbitrary.
  48. va_list arglist;
  49. char OutputBuffer[MAX_PRINTF_LEN];
  50. ULONG length = 0;
  51. //
  52. // Put a the information requested by the caller onto the line
  53. //
  54. va_start(arglist, Format);
  55. length += (ULONG) vsprintf(&OutputBuffer[length], Format, arglist);
  56. va_end(arglist);
  57. DhcpAssert(length <= MAX_PRINTF_LEN);
  58. //
  59. // Output to the debug terminal,
  60. //
  61. printf( "%s", OutputBuffer);
  62. }
  63. #endif // DBG
  64. BYTE
  65. RandN( // return random numbers from 0 to n-1 (max 0xFF)
  66. BYTE n // range 0 - 0xFF
  67. )
  68. {
  69. return( (BYTE)(rand() % n) );
  70. }
  71. BYTE
  72. RandByte( // return 0 - 0xFF
  73. VOID
  74. )
  75. {
  76. return( (BYTE)rand() );
  77. }
  78. WORD
  79. RandWord( // return 0 - 0xFFFF
  80. VOID
  81. )
  82. {
  83. return((WORD)(((WORD)RandByte() << 8) | (WORD)RandByte()));
  84. }
  85. DWORD
  86. RandDWord( // return 0 - 0xFFFFFFFF
  87. VOID
  88. )
  89. {
  90. return(((DWORD)RandWord() << 16) | (DWORD)RandWord());
  91. }
  92. DWORD_DWORD
  93. RandDWordDword(
  94. VOID
  95. )
  96. {
  97. DWORD_DWORD Lg;
  98. Lg.DWord1 = RandDWord();
  99. Lg.DWord2 = RandDWord();
  100. return(Lg);
  101. }
  102. LPWSTR
  103. RandString(
  104. LPWSTR BufferPtr,
  105. DWORD *Length
  106. )
  107. {
  108. BYTE i;
  109. LPWSTR BPtr = BufferPtr;
  110. *Length = RandN( RANDOM_STRING_MAX_LEN );
  111. for( i = 0; i < *Length; i++) {
  112. *BPtr++ = L'A' + RandN(26);
  113. }
  114. *BPtr++ = L'\0'; // terminate
  115. *Length += 1;
  116. return( BufferPtr );
  117. }
  118. VOID
  119. RandBinaryData(
  120. LPDHCP_BINARY_DATA BinaryData
  121. )
  122. {
  123. DWORD Length = 0;
  124. DWORD i;
  125. LPBYTE DataPtr;
  126. //
  127. // generate a HW address, atlease 6 bytes long.
  128. //
  129. while (Length < 6 ) {
  130. Length = (DWORD)RandN( RANDOM_BINARY_DATA_MAX_LEN );
  131. }
  132. BinaryData->DataLength = Length;
  133. DataPtr = BinaryData->Data;
  134. for( i = 0; i < Length; i++) {
  135. *DataPtr++ = RandByte();
  136. }
  137. }
  138. VOID
  139. CreateOptionValue(
  140. DHCP_OPTION_ID OptionID,
  141. LPDHCP_OPTION_DATA OptionData
  142. )
  143. {
  144. DWORD i;
  145. DHCP_OPTION_DATA_TYPE OptionType;
  146. LPBYTE DataPtr;
  147. DWORD NumElements;
  148. NumElements =
  149. OptionData->NumElements = RandN(OPTION_DATA_NUM_ELEMENT);
  150. OptionData->Elements= (LPDHCP_OPTION_DATA_ELEMENT)GlobalScratchBuffer;
  151. OptionType = (DHCP_OPTION_DATA_TYPE)
  152. (OptionID % (DhcpEncapsulatedDataOption + 1));
  153. DataPtr = GlobalScratchBuffer +
  154. NumElements * sizeof( DHCP_OPTION_DATA_ELEMENT );
  155. for( i = 0; i < NumElements; i++) {
  156. OptionData->Elements[i].OptionType = OptionType;
  157. switch( OptionType ) {
  158. case DhcpByteOption:
  159. OptionData->Elements[i].Element.ByteOption = RandByte();
  160. break;
  161. case DhcpWordOption:
  162. OptionData->Elements[i].Element.WordOption = RandWord();
  163. break;
  164. case DhcpDWordOption:
  165. OptionData->Elements[i].Element.DWordOption = RandDWord();
  166. break;
  167. case DhcpDWordDWordOption:
  168. OptionData->Elements[i].Element.DWordDWordOption =
  169. RandDWordDword();
  170. break;
  171. case DhcpIpAddressOption:
  172. OptionData->Elements[i].Element.IpAddressOption = RandDWord();
  173. break;
  174. case DhcpStringDataOption: {
  175. DWORD Length;
  176. OptionData->Elements[i].Element.StringDataOption =
  177. RandString( (LPWSTR)DataPtr, &Length );
  178. DataPtr += (Length * sizeof(WCHAR));
  179. break;
  180. }
  181. case DhcpBinaryDataOption:
  182. case DhcpEncapsulatedDataOption:
  183. OptionData->Elements[i].Element.BinaryDataOption.Data = DataPtr;
  184. RandBinaryData(
  185. &OptionData->Elements[i].Element.BinaryDataOption );
  186. DataPtr +=
  187. OptionData->Elements[i].Element.BinaryDataOption.DataLength;
  188. break;
  189. default:
  190. printf("CreateOptionValue: Unknown OptionType \n");
  191. break;
  192. }
  193. DhcpAssert( DataPtr < GlobalScratchBufferEnd );
  194. }
  195. }
  196. VOID
  197. CreateOptionValue1(
  198. DHCP_OPTION_ID OptionID,
  199. LPDHCP_OPTION_DATA OptionData,
  200. LPBYTE ScratchBuffer
  201. )
  202. {
  203. DWORD i;
  204. DHCP_OPTION_DATA_TYPE OptionType;
  205. LPBYTE DataPtr;
  206. DWORD NumElements;
  207. NumElements =
  208. OptionData->NumElements = RandN(OPTION_DATA_NUM_ELEMENT);
  209. OptionData->Elements= (LPDHCP_OPTION_DATA_ELEMENT)ScratchBuffer;
  210. OptionType = (DHCP_OPTION_DATA_TYPE)
  211. (OptionID % (DhcpEncapsulatedDataOption + 1));
  212. DataPtr = ScratchBuffer +
  213. NumElements * sizeof( DHCP_OPTION_DATA_ELEMENT );
  214. for( i = 0; i < NumElements; i++) {
  215. OptionData->Elements[i].OptionType = OptionType;
  216. switch( OptionType ) {
  217. case DhcpByteOption:
  218. OptionData->Elements[i].Element.ByteOption = RandByte();
  219. break;
  220. case DhcpWordOption:
  221. OptionData->Elements[i].Element.WordOption = RandWord();
  222. break;
  223. case DhcpDWordOption:
  224. OptionData->Elements[i].Element.DWordOption = RandDWord();
  225. break;
  226. case DhcpDWordDWordOption:
  227. OptionData->Elements[i].Element.DWordDWordOption =
  228. RandDWordDword();
  229. break;
  230. case DhcpIpAddressOption:
  231. OptionData->Elements[i].Element.IpAddressOption = RandDWord();
  232. break;
  233. case DhcpStringDataOption: {
  234. DWORD Length;
  235. OptionData->Elements[i].Element.StringDataOption =
  236. RandString( (LPWSTR)DataPtr, &Length );
  237. DataPtr += (Length * sizeof(WCHAR));
  238. break;
  239. }
  240. case DhcpBinaryDataOption:
  241. case DhcpEncapsulatedDataOption:
  242. OptionData->Elements[i].Element.BinaryDataOption.Data = DataPtr;
  243. RandBinaryData(
  244. &OptionData->Elements[i].Element.BinaryDataOption );
  245. DataPtr +=
  246. OptionData->Elements[i].Element.BinaryDataOption.DataLength;
  247. break;
  248. default:
  249. printf("CreateOptionValue: Unknown OptionType \n");
  250. break;
  251. }
  252. DhcpAssert( DataPtr < (ScratchBuffer + SCRATCH_BUFFER_SIZE) );
  253. }
  254. }
  255. VOID
  256. PrintOptionValue(
  257. LPDHCP_OPTION_DATA OptionValue
  258. )
  259. {
  260. DWORD NumElements;
  261. DHCP_OPTION_DATA_TYPE OptionType;
  262. DWORD i;
  263. printf("Option Value : \n");
  264. NumElements = OptionValue->NumElements;
  265. printf("\tNumber of Option Elements = %ld\n", NumElements );
  266. if( NumElements == 0 ) {
  267. return;
  268. }
  269. OptionType = OptionValue->Elements[0].OptionType;
  270. printf("\tOption Elements Type = " );
  271. switch( OptionType ) {
  272. case DhcpByteOption:
  273. printf("DhcpByteOption\n");
  274. break;
  275. case DhcpWordOption:
  276. printf("DhcpWordOption\n");
  277. break;
  278. case DhcpDWordOption:
  279. printf("DhcpDWordOption\n");
  280. break;
  281. case DhcpDWordDWordOption:
  282. printf("DhcpDWordDWordOption\n");
  283. break;
  284. case DhcpIpAddressOption:
  285. printf("DhcpIpAddressOption\n");
  286. break;
  287. case DhcpStringDataOption:
  288. printf("DhcpStringDataOption\n");
  289. break;
  290. case DhcpBinaryDataOption:
  291. printf("DhcpBinaryDataOption\n");
  292. break;
  293. case DhcpEncapsulatedDataOption:
  294. printf("DhcpEncapsulatedDataOption\n");
  295. break;
  296. default:
  297. printf("Unknown\n");
  298. return;
  299. }
  300. for( i = 0; i < OptionValue->NumElements; i++ ) {
  301. DhcpAssert( OptionType == OptionValue->Elements[i].OptionType );
  302. printf("Option Element %ld value = ", i );
  303. switch( OptionType ) {
  304. case DhcpByteOption:
  305. printf("%lx.\n", (DWORD)
  306. OptionValue->Elements[i].Element.ByteOption );
  307. break;
  308. case DhcpWordOption:
  309. printf("%lx.\n", (DWORD)
  310. OptionValue->Elements[i].Element.WordOption );
  311. break;
  312. case DhcpDWordOption:
  313. printf("%lx.\n",
  314. OptionValue->Elements[i].Element.DWordOption );
  315. break;
  316. case DhcpDWordDWordOption:
  317. printf("%lx, %lx.\n",
  318. OptionValue->Elements[i].Element.DWordDWordOption.DWord1,
  319. OptionValue->Elements[i].Element.DWordDWordOption.DWord2 );
  320. break;
  321. case DhcpIpAddressOption:
  322. printf("%lx.\n",
  323. OptionValue->Elements[i].Element.IpAddressOption );
  324. break;
  325. case DhcpStringDataOption:
  326. printf("%ws.\n",
  327. OptionValue->Elements[i].Element.StringDataOption );
  328. break;
  329. case DhcpBinaryDataOption:
  330. case DhcpEncapsulatedDataOption: {
  331. DWORD j;
  332. DWORD Length;
  333. Length = OptionValue->Elements[i].Element.BinaryDataOption.DataLength;
  334. for( j = 0; j < Length; j++ ) {
  335. printf("%2lx ",
  336. OptionValue->Elements[i].Element.BinaryDataOption.Data[j] );
  337. }
  338. printf(".\n");
  339. break;
  340. }
  341. default:
  342. printf("PrintOptionValue: Unknown OptionType.\n");
  343. break;
  344. }
  345. }
  346. }
  347. VOID
  348. PrintOptionInfo(
  349. LPDHCP_OPTION OptionInfo
  350. )
  351. {
  352. printf( "Option Info : \n");
  353. printf( "\tOptionId : %ld \n", (DWORD)OptionInfo->OptionID );
  354. printf( "\tOptionName : %ws \n", (DWORD)OptionInfo->OptionName );
  355. printf( "\tOptionComment : %ws \n", (DWORD)OptionInfo->OptionComment );
  356. PrintOptionValue( &OptionInfo->DefaultValue );
  357. printf( "\tOptionType : %ld \n", (DWORD)OptionInfo->OptionType );
  358. }
  359. VOID
  360. TestPrintSubnetEnumInfo(
  361. LPDHCP_SUBNET_ELEMENT_INFO_ARRAY EnumInfo
  362. )
  363. {
  364. DWORD i;
  365. LPDHCP_SUBNET_ELEMENT_DATA Element;
  366. printf("Subnet Enum Info : \n");
  367. printf("Number of Elements returned = %ld\n\n",
  368. EnumInfo->NumElements);
  369. for( i = 0, Element = EnumInfo->Elements;
  370. i < EnumInfo->NumElements;
  371. i++, Element++ ) {
  372. printf("\tElement %ld : \n", i);
  373. switch( Element->ElementType ) {
  374. case DhcpIpRanges:
  375. printf("\tElement Type : DhcpIpRanges\n");
  376. printf("\tStartAddress : %s\n",
  377. DhcpIpAddressToDottedString(
  378. Element->Element.IpRange->StartAddress));
  379. printf("\tEndAddress : %s\n",
  380. DhcpIpAddressToDottedString(
  381. Element->Element.IpRange->EndAddress));
  382. break;
  383. case DhcpSecondaryHosts:
  384. printf("\tElement Type : DhcpSecondaryHosts\n");
  385. printf("\tIpaddress : %s\n",
  386. DhcpIpAddressToDottedString(
  387. Element->Element.SecondaryHost->IpAddress));
  388. printf("\tNetBiosName : %ws \n",
  389. Element->Element.SecondaryHost->NetBiosName);
  390. printf("\tHostName : %ws\n",
  391. Element->Element.SecondaryHost->HostName);
  392. break;
  393. case DhcpReservedIps:
  394. printf("\tElement Type : DhcpReservedIps\n");
  395. printf("\tReservedIpAddress : %s\n",
  396. DhcpIpAddressToDottedString(
  397. Element->Element.ReservedIp->ReservedIpAddress)) ;
  398. break;
  399. case DhcpExcludedIpRanges:
  400. printf("\tElement Type : DhcpExcludedIpRanges\n");
  401. printf("\tStartAddress : %s\n",
  402. DhcpIpAddressToDottedString(
  403. Element->Element.ExcludeIpRange->StartAddress));
  404. printf("\tEndAddress : %s\n",
  405. DhcpIpAddressToDottedString(
  406. Element->Element.ExcludeIpRange->EndAddress));
  407. break;
  408. case DhcpIpUsedClusters:
  409. printf("\tElement Type : DhcpIpUsedClusters\n");
  410. default:
  411. printf("\tElement Type : Unknown\n");
  412. break;
  413. }
  414. }
  415. }
  416. VOID
  417. TestPrintSubnetInfo(
  418. LPDHCP_SUBNET_INFO SubnetInfo
  419. )
  420. {
  421. //
  422. // print subnet info.
  423. //
  424. printf("Subnet Info: \n");
  425. printf("\tSubnetAddress = %s\n",
  426. DhcpIpAddressToDottedString(SubnetInfo->SubnetAddress));
  427. printf("\tSubnetMask = %s\n",
  428. DhcpIpAddressToDottedString(SubnetInfo->SubnetMask));
  429. printf("\tSubnetName = %ws\n", SubnetInfo->SubnetName);
  430. printf("\tSubnetComment = %ws\n", SubnetInfo->SubnetComment);
  431. printf("\tPrimaryHost IpAddress = %s\n",
  432. DhcpIpAddressToDottedString(SubnetInfo->PrimaryHost.IpAddress));
  433. printf("\tPrimaryHost NetBiosName = %ws\n",
  434. SubnetInfo->PrimaryHost.NetBiosName);
  435. printf("\tPrimaryHost HostName = %ws\n",
  436. SubnetInfo->PrimaryHost.HostName);
  437. printf("\tSubnetState = %d\n", SubnetInfo->SubnetState);
  438. }
  439. DWORD
  440. TestDhcpCreateSubnet(
  441. LPSTR SubnetAddress,
  442. DHCP_IP_MASK SubnetMask,
  443. LPWSTR SubnetName,
  444. LPWSTR SubnetComment,
  445. LPSTR PrimaryHostIpAddr,
  446. LPWSTR PrimaryHostName,
  447. LPWSTR PrimaryNBName,
  448. DWORD SubnetState
  449. )
  450. {
  451. DWORD Error;
  452. DHCP_SUBNET_INFO SubnetInfo;
  453. SubnetInfo.SubnetAddress = DhcpDottedStringToIpAddress(SubnetAddress);
  454. SubnetInfo.SubnetMask = SubnetMask;
  455. SubnetInfo.SubnetName = SubnetName;
  456. SubnetInfo.SubnetComment = SubnetComment;
  457. SubnetInfo.PrimaryHost.IpAddress =
  458. DhcpDottedStringToIpAddress(PrimaryHostIpAddr);
  459. SubnetInfo.PrimaryHost.NetBiosName = PrimaryHostName;
  460. SubnetInfo.PrimaryHost.HostName = PrimaryNBName;
  461. SubnetInfo.SubnetState = SubnetState;
  462. Error = DhcpCreateSubnet(
  463. GlobalServerIpAddress,
  464. SubnetInfo.SubnetAddress,
  465. &SubnetInfo );
  466. return( Error );
  467. }
  468. DWORD
  469. TestDhcpDeleteSubnet(
  470. LPSTR SubnetAddress
  471. )
  472. {
  473. return( DhcpDeleteSubnet(
  474. GlobalServerIpAddress,
  475. DhcpDottedStringToIpAddress(SubnetAddress),
  476. DhcpNoForce ) );
  477. }
  478. DWORD
  479. Test1DhcpDeleteSubnet(
  480. LPSTR SubnetAddress
  481. )
  482. {
  483. return( DhcpDeleteSubnet(
  484. GlobalServerIpAddress,
  485. DhcpDottedStringToIpAddress(SubnetAddress),
  486. DhcpFullForce ) );
  487. }
  488. DWORD
  489. Test1DhcpCreateSubnet(
  490. LPSTR SubnetAddress
  491. )
  492. {
  493. return( DhcpDeleteSubnet(
  494. GlobalServerIpAddress,
  495. DhcpDottedStringToIpAddress(SubnetAddress),
  496. DhcpFullForce ) );
  497. }
  498. DWORD
  499. TestDhcpSetSubnetInfo(
  500. LPSTR SubnetAddress,
  501. DHCP_IP_MASK SubnetMask,
  502. LPWSTR SubnetName,
  503. LPWSTR SubnetComment,
  504. LPSTR PrimaryHostIpAddr,
  505. LPWSTR PrimaryHostName,
  506. LPWSTR PrimaryNBName,
  507. DWORD SubnetState
  508. )
  509. {
  510. DWORD Error;
  511. DHCP_SUBNET_INFO SubnetInfo;
  512. SubnetInfo.SubnetAddress = DhcpDottedStringToIpAddress(SubnetAddress);
  513. SubnetInfo.SubnetMask = SubnetMask;
  514. SubnetInfo.SubnetName = SubnetName;
  515. SubnetInfo.SubnetComment = SubnetComment;
  516. SubnetInfo.PrimaryHost.IpAddress =
  517. DhcpDottedStringToIpAddress(PrimaryHostIpAddr);
  518. SubnetInfo.PrimaryHost.NetBiosName = PrimaryNBName;
  519. SubnetInfo.PrimaryHost.HostName = PrimaryHostName;
  520. SubnetInfo.SubnetState = SubnetState;
  521. Error = DhcpSetSubnetInfo(
  522. GlobalServerIpAddress,
  523. SubnetInfo.SubnetAddress,
  524. &SubnetInfo );
  525. return( Error );
  526. }
  527. DWORD
  528. Test1DhcpSetSubnetInfo(
  529. LPDHCP_SUBNET_INFO SubnetInfo
  530. )
  531. {
  532. DWORD Error;
  533. Error = DhcpSetSubnetInfo(
  534. GlobalServerIpAddress,
  535. SubnetInfo->SubnetAddress,
  536. SubnetInfo );
  537. return( Error );
  538. }
  539. DWORD
  540. TestDhcpGetSubnetInfo(
  541. LPSTR SubnetAddress,
  542. LPDHCP_SUBNET_INFO *SubnetInfo
  543. )
  544. {
  545. DWORD Error;
  546. Error = DhcpGetSubnetInfo(
  547. GlobalServerIpAddress,
  548. DhcpDottedStringToIpAddress(SubnetAddress),
  549. SubnetInfo );
  550. return( Error );
  551. }
  552. DWORD
  553. TestAddSubnetIpRange(
  554. LPSTR SubnetAddressString,
  555. LPSTR IpRangeStartString,
  556. LPSTR IpRangeEndString
  557. )
  558. {
  559. DWORD Error;
  560. DHCP_IP_RANGE IpRange;
  561. DHCP_SUBNET_ELEMENT_DATA Element;
  562. IpRange.StartAddress = DhcpDottedStringToIpAddress(IpRangeStartString);
  563. IpRange.EndAddress = DhcpDottedStringToIpAddress(IpRangeEndString);
  564. Element.ElementType = DhcpIpRanges;
  565. Element.Element.IpRange = &IpRange;
  566. Error = DhcpAddSubnetElement(
  567. GlobalServerIpAddress,
  568. DhcpDottedStringToIpAddress(SubnetAddressString),
  569. &Element );
  570. return( Error );
  571. }
  572. DWORD
  573. TestAddSubnetIpRange1(
  574. LPSTR SubnetAddressString,
  575. DHCP_IP_MASK SubnetMask
  576. )
  577. {
  578. DWORD Error;
  579. DHCP_IP_RANGE IpRange;
  580. DHCP_SUBNET_ELEMENT_DATA Element;
  581. IpRange.StartAddress = DhcpDottedStringToIpAddress(SubnetAddressString);
  582. IpRange.StartAddress = IpRange.StartAddress & SubnetMask;
  583. IpRange.EndAddress = IpRange.StartAddress | ~SubnetMask;
  584. Element.ElementType = DhcpIpRanges;
  585. Element.Element.IpRange = &IpRange;
  586. Error = DhcpAddSubnetElement(
  587. GlobalServerIpAddress,
  588. IpRange.StartAddress,
  589. &Element );
  590. return( Error );
  591. }
  592. DWORD
  593. TestRemoveSubnetIpRange(
  594. LPSTR SubnetAddressString,
  595. LPSTR IpRangeStartString,
  596. LPSTR IpRangeEndString
  597. )
  598. {
  599. DWORD Error;
  600. DHCP_IP_RANGE IpRange;
  601. DHCP_SUBNET_ELEMENT_DATA Element;
  602. IpRange.StartAddress = DhcpDottedStringToIpAddress(IpRangeStartString);
  603. IpRange.EndAddress = DhcpDottedStringToIpAddress(IpRangeEndString);
  604. Element.ElementType = DhcpIpRanges;
  605. Element.Element.IpRange = &IpRange;
  606. Error = DhcpRemoveSubnetElement(
  607. GlobalServerIpAddress,
  608. DhcpDottedStringToIpAddress(SubnetAddressString),
  609. &Element,
  610. DhcpNoForce );
  611. return( Error );
  612. }
  613. DWORD
  614. TestAddSecondaryHost(
  615. LPSTR SubnetAddressString,
  616. LPSTR HostIpAddressString,
  617. LPWSTR NetBiosName,
  618. LPWSTR HostName
  619. )
  620. {
  621. DWORD Error;
  622. DHCP_HOST_INFO HostInfo;
  623. DHCP_SUBNET_ELEMENT_DATA Element;
  624. HostInfo.IpAddress = DhcpDottedStringToIpAddress(HostIpAddressString);
  625. HostInfo.NetBiosName = NetBiosName;
  626. HostInfo.HostName = HostName;
  627. Element.ElementType = DhcpSecondaryHosts;
  628. Element.Element.SecondaryHost = &HostInfo;
  629. Error = DhcpAddSubnetElement(
  630. GlobalServerIpAddress,
  631. DhcpDottedStringToIpAddress(SubnetAddressString),
  632. &Element );
  633. return( Error );
  634. }
  635. DWORD
  636. TestRemoveSecondaryHost(
  637. LPSTR SubnetAddressString,
  638. LPSTR HostIpAddressString
  639. )
  640. {
  641. DWORD Error;
  642. DHCP_HOST_INFO HostInfo;
  643. DHCP_SUBNET_ELEMENT_DATA Element;
  644. HostInfo.IpAddress = DhcpDottedStringToIpAddress(HostIpAddressString);
  645. HostInfo.NetBiosName = NULL;
  646. HostInfo.HostName = NULL;
  647. Element.ElementType = DhcpSecondaryHosts;
  648. Element.Element.SecondaryHost = &HostInfo;
  649. Error = DhcpRemoveSubnetElement(
  650. GlobalServerIpAddress,
  651. DhcpDottedStringToIpAddress(SubnetAddressString),
  652. &Element,
  653. DhcpNoForce );
  654. return( Error );
  655. }
  656. DWORD
  657. TestAddExcludeSubnetIpRange(
  658. LPSTR SubnetAddressString,
  659. LPSTR IpRangeStartString,
  660. LPSTR IpRangeEndString
  661. )
  662. {
  663. DWORD Error;
  664. DHCP_IP_RANGE ExcludeIpRange;
  665. DHCP_SUBNET_ELEMENT_DATA Element;
  666. ExcludeIpRange.StartAddress =
  667. DhcpDottedStringToIpAddress(IpRangeStartString);
  668. ExcludeIpRange.EndAddress =
  669. DhcpDottedStringToIpAddress(IpRangeEndString);
  670. Element.ElementType = DhcpExcludedIpRanges;
  671. Element.Element.ExcludeIpRange = &ExcludeIpRange;
  672. Error = DhcpAddSubnetElement(
  673. GlobalServerIpAddress,
  674. DhcpDottedStringToIpAddress(SubnetAddressString),
  675. &Element );
  676. return( Error );
  677. }
  678. DWORD
  679. TestRemoveExcludeSubnetIpRange(
  680. LPSTR SubnetAddressString,
  681. LPSTR IpRangeStartString,
  682. LPSTR IpRangeEndString
  683. )
  684. {
  685. DWORD Error;
  686. DHCP_IP_RANGE ExcludeIpRange;
  687. DHCP_SUBNET_ELEMENT_DATA Element;
  688. ExcludeIpRange.StartAddress =
  689. DhcpDottedStringToIpAddress(IpRangeStartString);
  690. ExcludeIpRange.EndAddress =
  691. DhcpDottedStringToIpAddress(IpRangeEndString);
  692. Element.ElementType = DhcpExcludedIpRanges;
  693. Element.Element.ExcludeIpRange = &ExcludeIpRange;
  694. Error = DhcpRemoveSubnetElement(
  695. GlobalServerIpAddress,
  696. DhcpDottedStringToIpAddress(SubnetAddressString),
  697. &Element,
  698. DhcpNoForce );
  699. return( Error );
  700. }
  701. DWORD
  702. TestAddReserveIpAddress(
  703. LPSTR SubnetAddressString,
  704. LPSTR ReserveIpAddressString,
  705. LPSTR ClientUIDString
  706. )
  707. {
  708. DWORD Error;
  709. DHCP_IP_RESERVATION ReserveIpInfo;
  710. DHCP_CLIENT_UID ClientUID;
  711. DHCP_SUBNET_ELEMENT_DATA Element;
  712. ClientUID.DataLength = strlen(ClientUIDString) + 1;
  713. ClientUID.Data = ClientUIDString;
  714. ReserveIpInfo.ReservedIpAddress =
  715. DhcpDottedStringToIpAddress(ReserveIpAddressString);
  716. ReserveIpInfo.ReservedForClient = &ClientUID;
  717. Element.ElementType = DhcpReservedIps;
  718. Element.Element.ReservedIp = &ReserveIpInfo;
  719. Error = DhcpAddSubnetElement(
  720. GlobalServerIpAddress,
  721. DhcpDottedStringToIpAddress(SubnetAddressString),
  722. &Element );
  723. return( Error );
  724. }
  725. DWORD
  726. TestRemoveReserveIpAddress(
  727. LPSTR SubnetAddressString,
  728. LPSTR ReserveIpAddressString
  729. )
  730. {
  731. DWORD Error;
  732. DHCP_IP_RESERVATION ReserveIpInfo;
  733. DHCP_SUBNET_ELEMENT_DATA Element;
  734. ReserveIpInfo.ReservedIpAddress =
  735. DhcpDottedStringToIpAddress(ReserveIpAddressString);
  736. ReserveIpInfo.ReservedForClient = NULL;
  737. Element.ElementType = DhcpReservedIps;
  738. Element.Element.ReservedIp = &ReserveIpInfo;
  739. Error = DhcpRemoveSubnetElement(
  740. GlobalServerIpAddress,
  741. DhcpDottedStringToIpAddress(SubnetAddressString),
  742. &Element,
  743. DhcpNoForce );
  744. return( Error );
  745. }
  746. DWORD
  747. TestDhcpEnumSubnetElements(
  748. LPSTR SubnetAddressString,
  749. DHCP_SUBNET_ELEMENT_TYPE EnumElementType,
  750. LPDHCP_SUBNET_ELEMENT_INFO_ARRAY *EnumElementInfo
  751. )
  752. {
  753. DWORD Error;
  754. DHCP_RESUME_HANDLE ResumeHandle = 0;
  755. DWORD ElementsRead;
  756. DWORD ElementsTotal;
  757. Error = DhcpEnumSubnetElements(
  758. GlobalServerIpAddress,
  759. DhcpDottedStringToIpAddress(SubnetAddressString),
  760. EnumElementType,
  761. &ResumeHandle,
  762. 0xFFFFFFFF,
  763. EnumElementInfo,
  764. &ElementsRead,
  765. &ElementsTotal
  766. );
  767. return( Error );
  768. }
  769. DWORD
  770. Test1DhcpEnumSubnetElements(
  771. LPSTR SubnetAddressString,
  772. DHCP_SUBNET_ELEMENT_TYPE EnumElementType,
  773. DWORD SmallBufferSize
  774. )
  775. {
  776. DWORD Error;
  777. LPDHCP_SUBNET_ELEMENT_INFO_ARRAY EnumElementInfo = NULL;
  778. DHCP_RESUME_HANDLE ResumeHandle = 0;
  779. DWORD ElementsRead;
  780. DWORD ElementsTotal;
  781. Error = ERROR_MORE_DATA;
  782. while (Error == ERROR_MORE_DATA) {
  783. Error = DhcpEnumSubnetElements(
  784. GlobalServerIpAddress,
  785. DhcpDottedStringToIpAddress(SubnetAddressString),
  786. EnumElementType,
  787. &ResumeHandle,
  788. SmallBufferSize,
  789. &EnumElementInfo,
  790. &ElementsRead,
  791. &ElementsTotal
  792. );
  793. printf("DhcpEnumSubnetElements(%s) result = %ld.\n",
  794. SubnetAddressString, Error );
  795. if( (Error == ERROR_SUCCESS) ||
  796. (Error == ERROR_MORE_DATA) ) {
  797. printf("Elements Read = %ld\n", ElementsRead);
  798. printf("Elements Total = %ld\n", ElementsTotal);
  799. TestPrintSubnetEnumInfo( EnumElementInfo );
  800. DhcpRpcFreeMemory( EnumElementInfo );
  801. EnumElementInfo = NULL;
  802. }
  803. }
  804. return( Error );
  805. }
  806. DWORD
  807. TestDhcpCreateOption(
  808. VOID
  809. )
  810. {
  811. DWORD Error;
  812. DWORD ReturnError = ERROR_SUCCESS;
  813. DHCP_OPTION_ID OptionID;
  814. DHCP_OPTION OptionInfo;
  815. WCHAR NameBuffer[SCRATCH_SMALL_BUFFER_SIZE];
  816. LPWSTR NameAppend;
  817. WCHAR CommentBuffer[SCRATCH_SMALL_BUFFER_SIZE];
  818. LPWSTR CommentAppend;
  819. WCHAR IDKey[SCRATCH_SMALL_BUFFER_SIZE];
  820. DWORD i;
  821. wcscpy( NameBuffer, L"OptionName ");
  822. NameAppend = NameBuffer + wcslen(NameBuffer);
  823. wcscpy( CommentBuffer, L"OptionComment ");
  824. CommentAppend = CommentBuffer + wcslen(CommentBuffer);
  825. for( i = 0; i <= NUM_KNOWN_OPTIONS ; i++ ) {
  826. OptionID = RandByte();
  827. DhcpRegOptionIdToKey( OptionID, IDKey );
  828. OptionInfo.OptionID = OptionID;
  829. wcscpy( NameAppend, IDKey);
  830. OptionInfo.OptionName = NameBuffer;
  831. wcscpy( CommentAppend, IDKey);
  832. OptionInfo.OptionComment = CommentBuffer;
  833. OptionInfo.DefaultValue;
  834. CreateOptionValue( OptionID, &OptionInfo.DefaultValue );
  835. OptionInfo.OptionType = DhcpArrayTypeOption;
  836. Error = DhcpCreateOption(
  837. GlobalServerIpAddress,
  838. OptionID,
  839. &OptionInfo );
  840. if( Error != ERROR_SUCCESS ) {
  841. printf("DhcpCreateOption failed to add %ld Option, %ld\n",
  842. (DWORD)OptionID, Error );
  843. ReturnError = Error;
  844. }
  845. else {
  846. printf("Option %ld successfully added.\n", (DWORD)OptionID );
  847. }
  848. }
  849. return( ReturnError );
  850. }
  851. DWORD
  852. TestDhcpSetOptionInfo(
  853. VOID
  854. )
  855. {
  856. DWORD Error;
  857. DWORD ReturnError = ERROR_SUCCESS;
  858. DHCP_OPTION_SCOPE_INFO ScopeInfo;
  859. LPDHCP_OPTION_VALUE_ARRAY OptionsArray;
  860. DHCP_RESUME_HANDLE ResumeHandle = 0;
  861. DWORD OptionsRead;
  862. DWORD OptionsTotal;
  863. DHCP_OPTION_ID OptionID;
  864. DHCP_OPTION OptionInfo;
  865. WCHAR NameBuffer[SCRATCH_SMALL_BUFFER_SIZE];
  866. LPWSTR NameAppend;
  867. WCHAR CommentBuffer[SCRATCH_SMALL_BUFFER_SIZE];
  868. LPWSTR CommentAppend;
  869. WCHAR IDKey[SCRATCH_SMALL_BUFFER_SIZE];
  870. wcscpy( NameBuffer, L"OptionName (NEW) ");
  871. NameAppend = NameBuffer + wcslen(NameBuffer);
  872. wcscpy( CommentBuffer, L"OptionComment (NEW) ");
  873. CommentAppend = CommentBuffer + wcslen(CommentBuffer);
  874. ScopeInfo.ScopeType = DhcpDefaultOptions;
  875. ScopeInfo.ScopeInfo.DefaultScopeInfo = NULL;
  876. Error = DhcpEnumOptionValues(
  877. GlobalServerIpAddress,
  878. &ScopeInfo,
  879. &ResumeHandle,
  880. 0xFFFFFFFF, // get all.
  881. &OptionsArray,
  882. &OptionsRead,
  883. &OptionsTotal );
  884. if( Error != ERROR_SUCCESS ) {
  885. printf("\tDhcpEnumOptionValues failed %ld\n", Error );
  886. ReturnError = Error;
  887. }
  888. else {
  889. DWORD i;
  890. LPDHCP_OPTION_VALUE Options;
  891. DWORD NumOptions;
  892. printf("\tDhcpEnumOptionValues successfully returned.\n");
  893. Options = OptionsArray->Values;
  894. NumOptions = OptionsArray->NumElements;
  895. for( i = 0; i < NumOptions; i++, Options++ ) {
  896. OptionID = Options->OptionID;
  897. DhcpRegOptionIdToKey( OptionID, IDKey );
  898. OptionInfo.OptionID = OptionID;
  899. wcscpy( NameAppend, IDKey);
  900. OptionInfo.OptionName = NameBuffer;
  901. wcscpy( CommentAppend, IDKey);
  902. OptionInfo.OptionComment = CommentBuffer;
  903. OptionID = Options->OptionID;
  904. CreateOptionValue( OptionID, &OptionInfo.DefaultValue );
  905. Error = DhcpSetOptionInfo(
  906. GlobalServerIpAddress,
  907. OptionID,
  908. &OptionInfo );
  909. if( Error != ERROR_SUCCESS ) {
  910. printf("DhcpSetOptionInfo failed to set %ld Option, %ld\n",
  911. (DWORD)OptionID, Error );
  912. ReturnError = Error;
  913. }
  914. else {
  915. printf("Option %ld successfully set.\n", (DWORD)OptionID );
  916. }
  917. }
  918. DhcpRpcFreeMemory( OptionsArray );
  919. OptionsArray = NULL;
  920. }
  921. return( ReturnError );
  922. }
  923. DWORD
  924. TestDhcpGetOptionInfo(
  925. VOID
  926. )
  927. {
  928. DWORD Error;
  929. DWORD ReturnError = ERROR_SUCCESS;
  930. DHCP_OPTION_SCOPE_INFO ScopeInfo;
  931. LPDHCP_OPTION_VALUE_ARRAY OptionsArray;
  932. DHCP_RESUME_HANDLE ResumeHandle = 0;
  933. DWORD OptionsRead;
  934. DWORD OptionsTotal;
  935. ScopeInfo.ScopeType = DhcpDefaultOptions;
  936. ScopeInfo.ScopeInfo.DefaultScopeInfo = NULL;
  937. Error = DhcpEnumOptionValues(
  938. GlobalServerIpAddress,
  939. &ScopeInfo,
  940. &ResumeHandle,
  941. 0xFFFFFFFF, // get all.
  942. &OptionsArray,
  943. &OptionsRead,
  944. &OptionsTotal );
  945. if( Error != ERROR_SUCCESS ) {
  946. printf("\tDhcpEnumOptionValues failed %ld\n", Error );
  947. }
  948. else {
  949. DWORD i;
  950. LPDHCP_OPTION_VALUE Options;
  951. DWORD NumOptions;
  952. LPDHCP_OPTION OptionInfo = NULL;
  953. DHCP_OPTION_ID OptionID;
  954. printf("\tDhcpEnumOptionValues successfully returned.\n");
  955. Options = OptionsArray->Values;
  956. NumOptions = OptionsArray->NumElements;
  957. for( i = 0; i < NumOptions; i++, Options++ ) {
  958. OptionID = Options->OptionID;
  959. Error = DhcpGetOptionInfo(
  960. GlobalServerIpAddress,
  961. OptionID,
  962. &OptionInfo );
  963. if( Error != ERROR_SUCCESS ) {
  964. printf("DhcpGetOptionInfo failed to retrieve %ld Option, %ld\n",
  965. (DWORD)OptionID, Error );
  966. ReturnError = Error;
  967. }
  968. else {
  969. printf("Option %ld successfully Retrived.\n", (DWORD)OptionID );
  970. PrintOptionInfo( OptionInfo );
  971. }
  972. if( OptionInfo != NULL ) {
  973. DhcpRpcFreeMemory( OptionInfo );
  974. OptionInfo = NULL;
  975. }
  976. }
  977. DhcpRpcFreeMemory( OptionsArray );
  978. OptionsArray = NULL;
  979. }
  980. return( ReturnError );
  981. }
  982. DWORD
  983. TestDhcpGetOptionInfo1(
  984. VOID
  985. )
  986. {
  987. DWORD Error;
  988. LPDHCP_OPTION_ARRAY OptionsArray;
  989. DHCP_RESUME_HANDLE ResumeHandle = 0;
  990. DWORD OptionsRead;
  991. DWORD OptionsTotal;
  992. printf("+++***********************************************+++" );
  993. Error = DhcpEnumOptions(
  994. GlobalServerIpAddress,
  995. &ResumeHandle,
  996. 0xFFFFFFFF, // get all.
  997. &OptionsArray,
  998. &OptionsRead,
  999. &OptionsTotal );
  1000. if( Error != ERROR_SUCCESS ) {
  1001. printf("\tDhcpEnumOptions failed %ld\n", Error );
  1002. }
  1003. else {
  1004. DWORD i;
  1005. LPDHCP_OPTION Options;
  1006. DWORD NumOptions;
  1007. printf("\tDhcpEnumOptions successfully returned.\n");
  1008. printf("\tOptionsRead = %ld.\n", OptionsRead);
  1009. printf("\tOptionsTotal = %ld.\n", OptionsTotal);
  1010. Options = OptionsArray->Options;
  1011. NumOptions = OptionsArray->NumElements;
  1012. for( i = 0; i < NumOptions; i++, Options++ ) {
  1013. PrintOptionInfo( Options );
  1014. }
  1015. DhcpRpcFreeMemory( OptionsArray );
  1016. OptionsArray = NULL;
  1017. }
  1018. printf("+++***********************************************+++" );
  1019. return( Error );
  1020. }
  1021. DWORD
  1022. TestDhcpRemoveOption(
  1023. VOID
  1024. )
  1025. {
  1026. DWORD Error;
  1027. DWORD ReturnError = ERROR_SUCCESS;
  1028. DHCP_OPTION_SCOPE_INFO ScopeInfo;
  1029. LPDHCP_OPTION_VALUE_ARRAY OptionsArray;
  1030. DHCP_RESUME_HANDLE ResumeHandle = 0;
  1031. DWORD OptionsRead;
  1032. DWORD OptionsTotal;
  1033. ScopeInfo.ScopeType = DhcpDefaultOptions;
  1034. ScopeInfo.ScopeInfo.DefaultScopeInfo = NULL;
  1035. Error = DhcpEnumOptionValues(
  1036. GlobalServerIpAddress,
  1037. &ScopeInfo,
  1038. &ResumeHandle,
  1039. 0xFFFFFFFF, // get all.
  1040. &OptionsArray,
  1041. &OptionsRead,
  1042. &OptionsTotal );
  1043. if( Error != ERROR_SUCCESS ) {
  1044. printf("\tDhcpEnumOptionValues failed %ld\n", Error );
  1045. ReturnError = Error;
  1046. }
  1047. else {
  1048. DWORD i;
  1049. LPDHCP_OPTION_VALUE Options;
  1050. DWORD NumOptions;
  1051. DHCP_OPTION_ID OptionID;
  1052. printf("\tDhcpEnumOptionValues successfully returned.\n");
  1053. Options = OptionsArray->Values;
  1054. NumOptions = OptionsArray->NumElements;
  1055. for( i = 0; i < NumOptions; i++, Options++ ) {
  1056. OptionID = Options->OptionID;
  1057. Error = DhcpRemoveOption(
  1058. GlobalServerIpAddress,
  1059. OptionID );
  1060. if( Error != ERROR_SUCCESS ) {
  1061. printf("DhcpRemoveOption failed to remove %ld Option, %ld\n",
  1062. (DWORD)OptionID, Error );
  1063. ReturnError = Error;
  1064. }
  1065. else {
  1066. printf("Option %ld successfully removed.\n",
  1067. (DWORD)OptionID );
  1068. }
  1069. }
  1070. DhcpRpcFreeMemory( OptionsArray );
  1071. OptionsArray = NULL;
  1072. }
  1073. return( ReturnError );
  1074. }
  1075. DWORD
  1076. TestDhcpSetOptionValue(
  1077. DHCP_OPTION_SCOPE_TYPE Scope,
  1078. LPSTR SubnetAddress,
  1079. LPSTR ReserveIpAddressString
  1080. )
  1081. {
  1082. DWORD Error;
  1083. DWORD i;
  1084. DWORD ReturnError = ERROR_SUCCESS;
  1085. DWORD NumGlobalOption;
  1086. DHCP_OPTION_DATA OptionValue;
  1087. DHCP_OPTION_ID OptionID;
  1088. DHCP_OPTION_SCOPE_INFO ScopeInfo;
  1089. NumGlobalOption = RandN(CREATE_MAX_OPTION_VALUES);
  1090. ScopeInfo.ScopeType = Scope;
  1091. switch( Scope ) {
  1092. case DhcpDefaultOptions:
  1093. printf("Setting Default Option.\n");
  1094. ScopeInfo.ScopeInfo.DefaultScopeInfo = NULL;
  1095. break;
  1096. case DhcpGlobalOptions:
  1097. printf("Setting Global Option.\n");
  1098. ScopeInfo.ScopeInfo.GlobalScopeInfo = NULL;
  1099. break;
  1100. case DhcpSubnetOptions:
  1101. printf("Setting Subnet Option.\n");
  1102. ScopeInfo.ScopeInfo.SubnetScopeInfo =
  1103. DhcpDottedStringToIpAddress(SubnetAddress);
  1104. break;
  1105. case DhcpReservedOptions:
  1106. printf("Setting Reserved Option.\n");
  1107. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpSubnetAddress =
  1108. DhcpDottedStringToIpAddress(SubnetAddress);
  1109. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpAddress =
  1110. DhcpDottedStringToIpAddress(ReserveIpAddressString);
  1111. break;
  1112. default:
  1113. printf("TestDhcpSetOptionValue: Unknown OptionType \n");
  1114. return(ERROR_INVALID_PARAMETER);
  1115. }
  1116. for( i = 0; i < NumGlobalOption; i++ ) {
  1117. OptionID = (DHCP_OPTION_ID) RandN(255);
  1118. CreateOptionValue( OptionID, &OptionValue );
  1119. Error = DhcpSetOptionValue(
  1120. GlobalServerIpAddress,
  1121. OptionID,
  1122. &ScopeInfo,
  1123. &OptionValue );
  1124. if( Error != ERROR_SUCCESS ) {
  1125. printf("\tDhcpSetOptionValue failed to set Option %ld, %ld\n",
  1126. (DWORD)OptionID, Error );
  1127. ReturnError = Error;
  1128. }
  1129. else {
  1130. printf("\tOption %ld successfully set.\n", (DWORD)OptionID);
  1131. }
  1132. }
  1133. return( ReturnError );
  1134. }
  1135. DWORD
  1136. TestDhcpSetOptionValue1(
  1137. DHCP_OPTION_SCOPE_TYPE Scope,
  1138. LPSTR SubnetAddress,
  1139. LPSTR ReserveIpAddressString
  1140. )
  1141. {
  1142. DWORD Error;
  1143. DWORD i;
  1144. DWORD NumGlobalOption;
  1145. DHCP_OPTION_VALUE_ARRAY OptionValues;
  1146. DHCP_OPTION_SCOPE_INFO ScopeInfo;
  1147. printf("---***********************************************---" );
  1148. NumGlobalOption = RandN(CREATE_MAX_OPTION_VALUES);
  1149. ScopeInfo.ScopeType = Scope;
  1150. OptionValues.NumElements = 0;
  1151. OptionValues.Values = NULL;
  1152. switch( Scope ) {
  1153. case DhcpDefaultOptions:
  1154. printf("Setting Default Option.\n");
  1155. ScopeInfo.ScopeInfo.DefaultScopeInfo = NULL;
  1156. break;
  1157. case DhcpGlobalOptions:
  1158. printf("Setting Global Option.\n");
  1159. ScopeInfo.ScopeInfo.GlobalScopeInfo = NULL;
  1160. break;
  1161. case DhcpSubnetOptions:
  1162. printf("Setting Subnet Option.\n");
  1163. ScopeInfo.ScopeInfo.SubnetScopeInfo =
  1164. DhcpDottedStringToIpAddress(SubnetAddress);
  1165. break;
  1166. case DhcpReservedOptions:
  1167. printf("Setting Reserved Option.\n");
  1168. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpSubnetAddress =
  1169. DhcpDottedStringToIpAddress(SubnetAddress);
  1170. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpAddress =
  1171. DhcpDottedStringToIpAddress(ReserveIpAddressString);
  1172. break;
  1173. default:
  1174. printf("TestDhcpSetOptionValue1: Unknown OptionType \n");
  1175. Error = ERROR_INVALID_PARAMETER;
  1176. goto Cleanup;
  1177. }
  1178. //
  1179. // allocate memory for option value array.
  1180. //
  1181. OptionValues.NumElements = NumGlobalOption;
  1182. OptionValues.Values = DhcpAllocateMemory(
  1183. sizeof(DHCP_OPTION_VALUE) *
  1184. NumGlobalOption );
  1185. if( OptionValues.Values == NULL ) {
  1186. Error = ERROR_NOT_ENOUGH_MEMORY;
  1187. goto Cleanup;
  1188. }
  1189. for( i = 0; i < NumGlobalOption; i++ ) {
  1190. LPBYTE ScratchBuffer;
  1191. OptionValues.Values[i].OptionID = (DHCP_OPTION_ID) RandN(255);
  1192. ScratchBuffer = DhcpAllocateMemory( SCRATCH_BUFFER_SIZE );
  1193. if( ScratchBuffer == NULL ) {
  1194. Error = ERROR_NOT_ENOUGH_MEMORY;
  1195. goto Cleanup;
  1196. }
  1197. CreateOptionValue1(
  1198. OptionValues.Values[i].OptionID,
  1199. &OptionValues.Values[i].Value,
  1200. ScratchBuffer );
  1201. }
  1202. Error = DhcpSetOptionValues(
  1203. GlobalServerIpAddress,
  1204. &ScopeInfo,
  1205. &OptionValues );
  1206. if( Error != ERROR_SUCCESS ) {
  1207. printf("\tDhcpSetOptionValues failed, %ld\n", Error );
  1208. }
  1209. else {
  1210. printf("\tDhcpSetOptionValues successfully set.\n");
  1211. }
  1212. Cleanup:
  1213. if( OptionValues.Values != NULL ) {
  1214. for( i = 0; i < NumGlobalOption; i++ ) {
  1215. DhcpFreeMemory( OptionValues.Values[i].Value.Elements );
  1216. }
  1217. DhcpFreeMemory( OptionValues.Values );
  1218. }
  1219. printf("---***********************************************---" );
  1220. return( Error );
  1221. }
  1222. DWORD
  1223. TestDhcpGetOptionValue(
  1224. DHCP_OPTION_SCOPE_TYPE Scope,
  1225. LPSTR SubnetAddress,
  1226. LPSTR ReserveIpAddressString
  1227. )
  1228. {
  1229. DWORD Error;
  1230. DWORD i;
  1231. DWORD ReturnError = ERROR_SUCCESS;
  1232. LPDHCP_OPTION_VALUE OptionValue = NULL;
  1233. DHCP_OPTION_ID OptionID;
  1234. DHCP_OPTION_SCOPE_INFO ScopeInfo;
  1235. ScopeInfo.ScopeType = Scope;
  1236. switch( Scope ) {
  1237. case DhcpDefaultOptions:
  1238. printf("Getting Default Option.\n");
  1239. ScopeInfo.ScopeInfo.DefaultScopeInfo = NULL;
  1240. break;
  1241. case DhcpGlobalOptions:
  1242. printf("Getting Global Option.\n");
  1243. ScopeInfo.ScopeInfo.GlobalScopeInfo = NULL;
  1244. break;
  1245. case DhcpSubnetOptions:
  1246. printf("Getting Subnet Option.\n");
  1247. ScopeInfo.ScopeInfo.SubnetScopeInfo =
  1248. DhcpDottedStringToIpAddress(SubnetAddress);
  1249. break;
  1250. case DhcpReservedOptions:
  1251. printf("Getting Reserved Option.\n");
  1252. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpSubnetAddress =
  1253. DhcpDottedStringToIpAddress(SubnetAddress);
  1254. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpAddress =
  1255. DhcpDottedStringToIpAddress(ReserveIpAddressString);
  1256. break;
  1257. default:
  1258. printf("TestDhcpGetOptionValue: Unknown OptionType \n");
  1259. return(ERROR_INVALID_PARAMETER);
  1260. }
  1261. for( i = 0; i < 255; i++ ) {
  1262. OptionID = (DHCP_OPTION_ID) i;
  1263. Error = DhcpGetOptionValue(
  1264. GlobalServerIpAddress,
  1265. OptionID,
  1266. &ScopeInfo,
  1267. &OptionValue );
  1268. if( Error != ERROR_SUCCESS ) {
  1269. printf("\tDhcpGetOptionValue failed to get Option %ld, %ld\n",
  1270. (DWORD)OptionID, Error );
  1271. ReturnError = Error;
  1272. }
  1273. else {
  1274. printf("\tOption %ld successfully got.\n",
  1275. (DWORD)OptionValue->OptionID);
  1276. PrintOptionValue( &OptionValue->Value );
  1277. DhcpRpcFreeMemory( OptionValue );
  1278. OptionValue = NULL;
  1279. }
  1280. }
  1281. return( ReturnError );
  1282. }
  1283. DWORD
  1284. TestDhcpEnumOptionValues(
  1285. DHCP_OPTION_SCOPE_TYPE Scope,
  1286. LPSTR SubnetAddress,
  1287. LPSTR ReserveIpAddressString
  1288. )
  1289. {
  1290. DWORD Error;
  1291. DHCP_OPTION_SCOPE_INFO ScopeInfo;
  1292. LPDHCP_OPTION_VALUE_ARRAY OptionsArray;
  1293. DHCP_RESUME_HANDLE ResumeHandle = 0;
  1294. DWORD OptionsRead;
  1295. DWORD OptionsTotal;
  1296. ScopeInfo.ScopeType = Scope;
  1297. switch( Scope ) {
  1298. case DhcpDefaultOptions:
  1299. printf("Enum Default Option.\n");
  1300. ScopeInfo.ScopeInfo.DefaultScopeInfo = NULL;
  1301. break;
  1302. case DhcpGlobalOptions:
  1303. printf("Enum Global Option.\n");
  1304. ScopeInfo.ScopeInfo.GlobalScopeInfo = NULL;
  1305. break;
  1306. case DhcpSubnetOptions:
  1307. printf("Enum Subnet Option.\n");
  1308. ScopeInfo.ScopeInfo.SubnetScopeInfo =
  1309. DhcpDottedStringToIpAddress(SubnetAddress);
  1310. break;
  1311. case DhcpReservedOptions:
  1312. printf("Enum Reserved Option.\n");
  1313. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpSubnetAddress =
  1314. DhcpDottedStringToIpAddress(SubnetAddress);
  1315. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpAddress =
  1316. DhcpDottedStringToIpAddress(ReserveIpAddressString);
  1317. break;
  1318. default:
  1319. printf("TestDhcpEnumOptionValues: Unknown OptionType \n");
  1320. return(ERROR_INVALID_PARAMETER);
  1321. }
  1322. Error = DhcpEnumOptionValues(
  1323. GlobalServerIpAddress,
  1324. &ScopeInfo,
  1325. &ResumeHandle,
  1326. 0xFFFFFFFF, // get all.
  1327. &OptionsArray,
  1328. &OptionsRead,
  1329. &OptionsTotal );
  1330. if( Error != ERROR_SUCCESS ) {
  1331. printf("\tDhcpEnumOptionValues failed %ld\n", Error );
  1332. }
  1333. else {
  1334. DWORD i;
  1335. LPDHCP_OPTION_VALUE Options;
  1336. DWORD NumOptions;
  1337. printf("\tDhcpEnumOptionValues successfully returned.\n");
  1338. Options = OptionsArray->Values;
  1339. NumOptions = OptionsArray->NumElements;
  1340. for( i = 0; i < NumOptions; i++, Options++ ) {
  1341. printf("\tOptionID = %ld\n", (DWORD)Options->OptionID);
  1342. PrintOptionValue( &Options->Value );
  1343. }
  1344. DhcpRpcFreeMemory( OptionsArray );
  1345. OptionsArray = NULL;
  1346. }
  1347. return( Error );
  1348. }
  1349. DWORD
  1350. TestDhcpRemoveOptionValues(
  1351. DHCP_OPTION_SCOPE_TYPE Scope,
  1352. LPSTR SubnetAddress,
  1353. LPSTR ReserveIpAddressString
  1354. )
  1355. {
  1356. DWORD Error;
  1357. DHCP_OPTION_SCOPE_INFO ScopeInfo;
  1358. LPDHCP_OPTION_VALUE_ARRAY OptionsArray;
  1359. DHCP_RESUME_HANDLE ResumeHandle = 0;
  1360. DWORD OptionsRead;
  1361. DWORD OptionsTotal;
  1362. ScopeInfo.ScopeType = Scope;
  1363. switch( Scope ) {
  1364. case DhcpDefaultOptions:
  1365. printf("Removing Default Option.\n");
  1366. ScopeInfo.ScopeInfo.DefaultScopeInfo = NULL;
  1367. break;
  1368. case DhcpGlobalOptions:
  1369. printf("Removing Global Option.\n");
  1370. ScopeInfo.ScopeInfo.GlobalScopeInfo = NULL;
  1371. break;
  1372. case DhcpSubnetOptions:
  1373. printf("Removing Subnet Option.\n");
  1374. ScopeInfo.ScopeInfo.SubnetScopeInfo =
  1375. DhcpDottedStringToIpAddress(SubnetAddress);
  1376. break;
  1377. case DhcpReservedOptions:
  1378. printf("Removing Reserved Option.\n");
  1379. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpSubnetAddress =
  1380. DhcpDottedStringToIpAddress(SubnetAddress);
  1381. ScopeInfo.ScopeInfo.ReservedScopeInfo.ReservedIpAddress =
  1382. DhcpDottedStringToIpAddress(ReserveIpAddressString);
  1383. break;
  1384. default:
  1385. printf("TestDhcpRemoveOptionValues: Unknown OptionType \n");
  1386. return(ERROR_INVALID_PARAMETER);
  1387. }
  1388. Error = DhcpEnumOptionValues(
  1389. GlobalServerIpAddress,
  1390. &ScopeInfo,
  1391. &ResumeHandle,
  1392. 0xFFFFFFFF, // get all.
  1393. &OptionsArray,
  1394. &OptionsRead,
  1395. &OptionsTotal );
  1396. if( Error != ERROR_SUCCESS ) {
  1397. printf("\tDhcpEnumOptionValues failed %ld\n", Error );
  1398. }
  1399. else {
  1400. DWORD i;
  1401. LPDHCP_OPTION_VALUE Options;
  1402. DWORD NumOptions;
  1403. printf("\tDhcpEnumOptionValues successfully returned.\n");
  1404. Options = OptionsArray->Values;
  1405. NumOptions = OptionsArray->NumElements;
  1406. for( i = 0; i < NumOptions; i++, Options++ ) {
  1407. DWORD LocalError;
  1408. printf("\tRemoving OptionID = %ld\n", (DWORD)Options->OptionID);
  1409. LocalError = DhcpRemoveOptionValue(
  1410. GlobalServerIpAddress,
  1411. Options->OptionID,
  1412. &ScopeInfo );
  1413. if( LocalError != ERROR_SUCCESS ) {
  1414. printf("\tDhcpRemoveOptionValue failed %ld\n", LocalError );
  1415. }
  1416. }
  1417. DhcpRpcFreeMemory( OptionsArray );
  1418. OptionsArray = NULL;
  1419. }
  1420. return( Error );
  1421. }
  1422. DWORD
  1423. TestDhcpEnumSubnetClients(
  1424. DHCP_IP_ADDRESS SubnetAddress,
  1425. DHCP_RESUME_HANDLE *ResumeHandle,
  1426. DWORD PreferredMaximum,
  1427. LPDHCP_CLIENT_INFO_ARRAY *ClientInfo,
  1428. DWORD *ClientsRead,
  1429. DWORD *ClientsTotal
  1430. )
  1431. {
  1432. return( ERROR_CALL_NOT_IMPLEMENTED);
  1433. }
  1434. DWORD
  1435. TestDhcpGetClientOptions(
  1436. DHCP_IP_ADDRESS ClientIpAddress,
  1437. DHCP_IP_MASK ClientSubnetMask,
  1438. LPDHCP_OPTION_LIST *ClientOptions
  1439. )
  1440. {
  1441. return( ERROR_CALL_NOT_IMPLEMENTED);
  1442. }
  1443. VOID
  1444. TestDhcpSubnetAPIs(
  1445. VOID
  1446. )
  1447. {
  1448. DWORD Error;
  1449. LPDHCP_SUBNET_INFO SubnetInfo = NULL;
  1450. LPDHCP_SUBNET_ELEMENT_INFO_ARRAY EnumElementInfo = NULL;
  1451. //
  1452. // test DhcpCreateSubnet
  1453. //
  1454. Error = TestDhcpCreateSubnet(
  1455. "11.1.0.0",
  1456. 0xFFFF0000,
  1457. L"Subnet1",
  1458. L"Subnet1 Comment",
  1459. "11.1.1.1",
  1460. L"Subnet1PrimaryHostName",
  1461. L"Subnet1PrimaryNBName",
  1462. DhcpSubnetEnabled
  1463. );
  1464. printf("TestDhcpCreateSubnet(%s) result = %ld.\n", "11.1.0.0", Error );
  1465. Error = TestDhcpCreateSubnet(
  1466. "11.2.0.0",
  1467. 0xFFFF0000,
  1468. L"Subnet2",
  1469. L"Subnet2 Comment",
  1470. "11.2.1.1",
  1471. L"Subnet2PrimaryHostName",
  1472. L"Subnet2PrimaryNBName",
  1473. DhcpSubnetDisabled
  1474. );
  1475. printf("TestDhcpCreateSubnet(%s) result = %ld.\n", "11.2.0.0", Error );
  1476. Error = TestDhcpCreateSubnet(
  1477. "11.3.0.0",
  1478. 0xFFFF0000,
  1479. L"Subnet3",
  1480. L"Subnet3 Comment",
  1481. "11.3.1.1",
  1482. L"Subnet3PrimaryHostName",
  1483. L"Subnet3PrimaryNBName",
  1484. DhcpSubnetDisabled
  1485. );
  1486. printf("TestDhcpCreateSubnet(%s) result = %ld.\n", "11.3.0.0", Error );
  1487. Error = TestDhcpCreateSubnet(
  1488. "11.4.0.0",
  1489. 0xFFFF0000,
  1490. L"Subnet4",
  1491. L"Subnet4 Comment",
  1492. "11.4.1.1",
  1493. L"Subnet4PrimaryHostName",
  1494. L"Subnet4PrimaryNBName",
  1495. DhcpSubnetDisabled
  1496. );
  1497. printf("TestDhcpCreateSubnet(%s) result = %ld.\n", "11.4.0.0", Error );
  1498. Error = TestDhcpCreateSubnet(
  1499. "11.5.0.0",
  1500. 0xFFFF0000,
  1501. L"Subnet5",
  1502. L"Subnet5 Comment",
  1503. "11.5.1.1",
  1504. NULL,
  1505. NULL,
  1506. DhcpSubnetDisabled
  1507. );
  1508. printf("TestDhcpCreateSubnet(%s) result = %ld.\n", "11.5.0.0", Error );
  1509. Error = TestDhcpCreateSubnet(
  1510. "11.6.0.0",
  1511. 0xFFFF0000,
  1512. L"Subnet6",
  1513. NULL,
  1514. "11.6.1.1",
  1515. NULL,
  1516. NULL,
  1517. DhcpSubnetDisabled
  1518. );
  1519. printf("TestDhcpCreateSubnet(%s) result = %ld.\n", "11.6.0.0", Error );
  1520. //
  1521. // DhcpSetSubnetInfo
  1522. //
  1523. Error = TestDhcpSetSubnetInfo(
  1524. "11.5.0.0",
  1525. 0xFFFF0000,
  1526. L"Subnet5",
  1527. L"Subnet5 Comment",
  1528. "11.5.1.1",
  1529. L"Subnet5PrimaryHostName",
  1530. L"Subnet5PrimaryNBName",
  1531. DhcpSubnetDisabled
  1532. );
  1533. printf("TestDhcpSetSubnetInfo(%s) result = %ld.\n", "11.5.0.0", Error );
  1534. Error = TestDhcpSetSubnetInfo(
  1535. "11.6.0.0",
  1536. 0xFFFF0000,
  1537. L"Subnet6",
  1538. L"Subnet6 Comment",
  1539. "11.6.1.1",
  1540. NULL,
  1541. NULL,
  1542. DhcpSubnetDisabled
  1543. );
  1544. printf("TestDhcpSetSubnetInfo(%s) result = %ld.\n", "11.6.0.0", Error );
  1545. //
  1546. // DhcpGetSubnetInfo
  1547. //
  1548. Error = TestDhcpGetSubnetInfo(
  1549. "11.1.0.0",
  1550. &SubnetInfo
  1551. );
  1552. printf("TestDhcpGetSubnetInfo(%s) result = %ld.\n", "11.1.0.0", Error );
  1553. if( Error == ERROR_SUCCESS ) {
  1554. TestPrintSubnetInfo( SubnetInfo );
  1555. DhcpRpcFreeMemory( SubnetInfo );
  1556. SubnetInfo = NULL;
  1557. }
  1558. Error = TestDhcpGetSubnetInfo(
  1559. "11.3.0.0",
  1560. &SubnetInfo
  1561. );
  1562. printf("TestDhcpGetSubnetInfo(%s) result = %ld.\n", "11.3.0.0", Error );
  1563. if( Error == ERROR_SUCCESS ) {
  1564. TestPrintSubnetInfo( SubnetInfo );
  1565. DhcpRpcFreeMemory( SubnetInfo );
  1566. SubnetInfo = NULL;
  1567. }
  1568. Error = TestDhcpGetSubnetInfo(
  1569. "11.5.0.0",
  1570. &SubnetInfo
  1571. );
  1572. printf("TestDhcpGetSubnetInfo(%s) result = %ld.\n", "11.5.0.0", Error );
  1573. if( Error == ERROR_SUCCESS ) {
  1574. TestPrintSubnetInfo( SubnetInfo );
  1575. DhcpRpcFreeMemory( SubnetInfo );
  1576. SubnetInfo = NULL;
  1577. }
  1578. //
  1579. // DhcpGet/SetSubnetInfo
  1580. //
  1581. Error = TestDhcpGetSubnetInfo(
  1582. "11.6.0.0",
  1583. &SubnetInfo
  1584. );
  1585. printf("TestDhcpGetSubnetInfo(%s) result = %ld.\n", "11.6.0.0", Error );
  1586. if( Error == ERROR_SUCCESS ) {
  1587. TestPrintSubnetInfo( SubnetInfo );
  1588. //
  1589. // reset comment.
  1590. //
  1591. SubnetInfo->PrimaryHost.HostName = L"Subnet6PrimaryHostName";
  1592. SubnetInfo->PrimaryHost.NetBiosName = L"Subnet6PrimaryNBName";
  1593. Error = Test1DhcpSetSubnetInfo( SubnetInfo );
  1594. printf("TestDhcpSetSubnetInfo(%s) result = %ld.\n", "11.6.0.0", Error );
  1595. DhcpRpcFreeMemory( SubnetInfo );
  1596. SubnetInfo = NULL;
  1597. }
  1598. //
  1599. // add DHCP IP Ranges.
  1600. //
  1601. Error = TestAddSubnetIpRange( "11.1.0.0", "11.1.0.0", "11.1.0.255" );
  1602. printf("TestAddSubnetIpRange(%s) result = %ld.\n", "11.1.0.0", Error );
  1603. //
  1604. // add 2 DHCP IP Ranges.
  1605. //
  1606. Error = TestAddSubnetIpRange( "11.2.0.0", "11.2.1.0", "11.2.1.255" );
  1607. printf("TestAddSubnetIpRange(%s) result = %ld.\n", "11.2.0.0", Error );
  1608. Error = TestAddSubnetIpRange( "11.2.0.0", "11.2.2.0", "11.2.2.255" );
  1609. printf("TestAddSubnetIpRange(%s) result = %ld.\n", "11.2.0.0", Error );
  1610. //
  1611. // add secondary host.
  1612. //
  1613. Error = TestAddSecondaryHost(
  1614. "11.3.0.0", "11.3.11.129",
  1615. L"SecondaryNBName",
  1616. L"SecondaryHostName" );
  1617. printf("TestAddSecondaryHost(%s) result = %ld.\n", "11.3.0.0", Error );
  1618. //
  1619. // Add Reserve IpAddress
  1620. //
  1621. Error = TestAddReserveIpAddress(
  1622. "11.4.0.0", "11.4.111.222", "ReservedIp 11.4.111.222" );
  1623. printf("TestAddReserveIpAddress(%s) result = %ld.\n", "11.4.0.0",
  1624. Error );
  1625. //
  1626. // Add Exclude DHCP IP Ranges.
  1627. //
  1628. Error = TestAddExcludeSubnetIpRange(
  1629. "11.5.0.0",
  1630. "11.5.0.100",
  1631. "11.5.0.255" );
  1632. printf("TestAddExcludeSubnetIpRange(%s) result = %ld.\n",
  1633. "11.5.0.0",
  1634. Error );
  1635. //
  1636. // Exclude 2 DHCP IP Ranges.
  1637. //
  1638. Error = TestAddExcludeSubnetIpRange(
  1639. "11.6.0.0",
  1640. "11.6.3.200",
  1641. "11.6.3.255" );
  1642. printf("TestAddExcludeSubnetIpRange(%s) result = %ld.\n",
  1643. "11.6.0.0",
  1644. Error );
  1645. Error = TestAddExcludeSubnetIpRange(
  1646. "11.6.0.0",
  1647. "11.6.5.100",
  1648. "11.6.5.200" );
  1649. printf("TestAddExcludeSubnetIpRange(%s) result = %ld.\n",
  1650. "11.6.0.0",
  1651. Error );
  1652. //
  1653. // test subnet enum
  1654. //
  1655. Error = TestDhcpEnumSubnetElements(
  1656. "11.2.0.0",
  1657. DhcpIpRanges,
  1658. &EnumElementInfo );
  1659. printf("TestDhcpEnumSubnetElements(%s) result = %ld.\n", "11.2.0.0", Error );
  1660. if( Error == ERROR_SUCCESS ) {
  1661. TestPrintSubnetEnumInfo( EnumElementInfo );
  1662. DhcpRpcFreeMemory( EnumElementInfo );
  1663. EnumElementInfo = NULL;
  1664. }
  1665. Error = TestDhcpEnumSubnetElements(
  1666. "11.3.0.0",
  1667. DhcpSecondaryHosts,
  1668. &EnumElementInfo);
  1669. printf("TestDhcpEnumSubnetElements(%s) result = %ld.\n", "11.3.0.0", Error );
  1670. if( Error == ERROR_SUCCESS ) {
  1671. TestPrintSubnetEnumInfo( EnumElementInfo );
  1672. DhcpRpcFreeMemory( EnumElementInfo );
  1673. EnumElementInfo = NULL;
  1674. }
  1675. Error = TestDhcpEnumSubnetElements(
  1676. "11.4.0.0",
  1677. DhcpReservedIps,
  1678. &EnumElementInfo);
  1679. printf("TestDhcpEnumSubnetElements(%s) result = %ld.\n",
  1680. "11.4.0.0",
  1681. Error );
  1682. Error = TestDhcpEnumSubnetElements(
  1683. "11.6.0.0",
  1684. DhcpExcludedIpRanges,
  1685. &EnumElementInfo);
  1686. printf("TestDhcpEnumSubnetElements(%s) result = %ld.\n",
  1687. "11.6.0.0",
  1688. Error );
  1689. Error = Test1DhcpEnumSubnetElements(
  1690. "11.6.0.0",
  1691. DhcpExcludedIpRanges,
  1692. 32 ); // small buffer
  1693. printf("Test1DhcpEnumSubnetElements(%s) result = %ld.\n",
  1694. "11.6.0.0", Error );
  1695. }
  1696. VOID
  1697. TestDhcpOptionAPIs(
  1698. VOID
  1699. )
  1700. {
  1701. DWORD Error;
  1702. Error = TestDhcpCreateOption();
  1703. if( Error != ERROR_SUCCESS) {
  1704. printf("TestDhcpCreateOption failed, %ld.\n", Error );
  1705. }
  1706. Error = TestDhcpGetOptionInfo();
  1707. if( Error != ERROR_SUCCESS) {
  1708. printf("TestDhcpGetOptionInfo failed, %ld.\n", Error );
  1709. }
  1710. Error = TestDhcpGetOptionInfo1();
  1711. if( Error != ERROR_SUCCESS) {
  1712. printf("TestDhcpGetOptionInfo1 failed, %ld.\n", Error );
  1713. }
  1714. Error = TestDhcpSetOptionInfo();
  1715. if( Error != ERROR_SUCCESS) {
  1716. printf("TestDhcpSetOptionInfo failed, %ld.\n", Error );
  1717. }
  1718. Error = TestDhcpGetOptionInfo();
  1719. if( Error != ERROR_SUCCESS) {
  1720. printf("TestDhcpGetOptionInfo failed, %ld.\n", Error );
  1721. }
  1722. Error = TestDhcpSetOptionValue(
  1723. DhcpDefaultOptions,
  1724. NULL,
  1725. NULL );
  1726. if( Error != ERROR_SUCCESS) {
  1727. printf("TestDhcpSetOptionValue failed, %ld.\n", Error );
  1728. }
  1729. Error = TestDhcpEnumOptionValues(
  1730. DhcpDefaultOptions,
  1731. NULL,
  1732. NULL );
  1733. if( Error != ERROR_SUCCESS) {
  1734. printf("TestDhcpEnumOptionValues failed, %ld.\n", Error );
  1735. }
  1736. Error = TestDhcpSetOptionValue(
  1737. DhcpGlobalOptions,
  1738. NULL,
  1739. NULL );
  1740. if( Error != ERROR_SUCCESS) {
  1741. printf("TestDhcpSetOptionValue failed, %ld.\n", Error );
  1742. }
  1743. Error = TestDhcpEnumOptionValues(
  1744. DhcpGlobalOptions,
  1745. NULL,
  1746. NULL );
  1747. if( Error != ERROR_SUCCESS) {
  1748. printf("TestDhcpEnumOptionValues failed, %ld.\n", Error );
  1749. }
  1750. Error = TestDhcpSetOptionValue1(
  1751. DhcpGlobalOptions,
  1752. NULL,
  1753. NULL );
  1754. if( Error != ERROR_SUCCESS) {
  1755. printf("TestDhcpSetOptionValue1 failed, %ld.\n", Error );
  1756. }
  1757. Error = TestDhcpEnumOptionValues(
  1758. DhcpGlobalOptions,
  1759. NULL,
  1760. NULL );
  1761. if( Error != ERROR_SUCCESS) {
  1762. printf("TestDhcpEnumOptionValues failed, %ld.\n", Error );
  1763. }
  1764. Error = TestDhcpSetOptionValue(
  1765. DhcpSubnetOptions,
  1766. "11.1.0.0",
  1767. NULL );
  1768. if( Error != ERROR_SUCCESS) {
  1769. printf("TestDhcpSetOptionValue failed, %ld.\n", Error );
  1770. }
  1771. Error = TestDhcpEnumOptionValues(
  1772. DhcpSubnetOptions,
  1773. "11.1.0.0",
  1774. NULL );
  1775. if( Error != ERROR_SUCCESS) {
  1776. printf("TestDhcpEnumOptionValues failed, %ld.\n", Error );
  1777. }
  1778. Error = TestDhcpSetOptionValue(
  1779. DhcpReservedOptions,
  1780. "11.4.0.0",
  1781. "11.4.111.222");
  1782. if( Error != ERROR_SUCCESS) {
  1783. printf("TestDhcpSetOptionValue failed, %ld.\n", Error );
  1784. }
  1785. Error = TestDhcpEnumOptionValues(
  1786. DhcpReservedOptions,
  1787. "11.4.0.0",
  1788. "11.4.111.222");
  1789. if( Error != ERROR_SUCCESS) {
  1790. printf("TestDhcpEnumOptionValues failed, %ld.\n", Error );
  1791. }
  1792. Error = TestDhcpRemoveOptionValues(
  1793. DhcpGlobalOptions,
  1794. NULL,
  1795. NULL );
  1796. if( Error != ERROR_SUCCESS) {
  1797. printf("TestDhcpRemoveOptionValues failed, %ld.\n", Error );
  1798. }
  1799. Error = TestDhcpRemoveOptionValues(
  1800. DhcpSubnetOptions,
  1801. "11.1.0.0",
  1802. NULL );
  1803. if( Error != ERROR_SUCCESS) {
  1804. printf("TestDhcpRemoveOptionValues failed, %ld.\n", Error );
  1805. }
  1806. Error = TestDhcpRemoveOptionValues(
  1807. DhcpReservedOptions,
  1808. "11.4.0.0",
  1809. "11.4.111.222");
  1810. if( Error != ERROR_SUCCESS) {
  1811. printf("TestDhcpRemoveOptionValues failed, %ld.\n", Error );
  1812. }
  1813. Error = TestDhcpRemoveOption();
  1814. if( Error != ERROR_SUCCESS) {
  1815. printf("TestDhcpRemoveOption failed, %ld.\n", Error );
  1816. }
  1817. }
  1818. DWORD
  1819. TestCreateClient(
  1820. LPSTR SubnetAddress,
  1821. DWORD Count
  1822. )
  1823. {
  1824. DWORD Error;
  1825. DWORD ReturnError;
  1826. DWORD i;
  1827. DHCP_CLIENT_INFO ClientInfo;
  1828. DHCP_IP_ADDRESS IpAddress;
  1829. WCHAR ClientName[SCRATCH_SMALL_BUFFER_SIZE];
  1830. LPWSTR NameAppend;
  1831. WCHAR ClientComment[SCRATCH_SMALL_BUFFER_SIZE];
  1832. LPWSTR CommentAppend;
  1833. WCHAR Key[SCRATCH_SMALL_BUFFER_SIZE];
  1834. BYTE BinaryData[RANDOM_BINARY_DATA_MAX_LEN];
  1835. //
  1836. // create clients;
  1837. wcscpy( ClientName, L"Client Name ");
  1838. NameAppend = ClientName + wcslen(ClientName);
  1839. wcscpy( ClientComment, L"Client Comment ");
  1840. CommentAppend = ClientComment + wcslen(ClientComment);
  1841. IpAddress = DhcpDottedStringToIpAddress(SubnetAddress);
  1842. ClientInfo.SubnetMask = 0xFFFF0000;
  1843. ClientInfo.ClientName = ClientName;
  1844. ClientInfo.ClientComment = ClientComment;
  1845. ClientInfo.ClientHardwareAddress.DataLength = 0;
  1846. ClientInfo.ClientHardwareAddress.Data = BinaryData;
  1847. ClientInfo.OwnerHost.IpAddress = 0;
  1848. ClientInfo.OwnerHost.NetBiosName = NULL;
  1849. ClientInfo.OwnerHost.HostName = NULL;
  1850. for( i = 1; i < Count; i++) {
  1851. ClientInfo.ClientIpAddress = IpAddress + i;
  1852. RandBinaryData( &ClientInfo.ClientHardwareAddress );
  1853. DhcpRegOptionIdToKey(i, Key);
  1854. wcscpy( NameAppend, Key ); // make "Client Name 001" like this.
  1855. wcscpy( CommentAppend, Key );
  1856. ClientInfo.ClientLeaseExpires = DhcpCalculateTime( RandWord() );
  1857. Error = DhcpCreateClientInfo(
  1858. GlobalServerIpAddress,
  1859. &ClientInfo );
  1860. if( Error != ERROR_SUCCESS ) {
  1861. printf("DhcpCreateClientInfo failed, %ld.\n", Error );
  1862. ReturnError = Error;
  1863. }
  1864. printf("DhcpCreateClientInfo, %ld.\n", i);
  1865. }
  1866. return( ReturnError );
  1867. }
  1868. VOID
  1869. PrintClientInfo(
  1870. LPDHCP_CLIENT_INFO ClientInfo
  1871. )
  1872. {
  1873. DWORD i;
  1874. DWORD DataLength;
  1875. LPBYTE Data;
  1876. printf("ClientInfo : ");
  1877. printf("\tIP Address = %s.\n",
  1878. DhcpIpAddressToDottedString(ClientInfo->ClientIpAddress));
  1879. printf("\tSubnetMask = %s.\n",
  1880. DhcpIpAddressToDottedString(ClientInfo->SubnetMask));
  1881. DataLength = ClientInfo->ClientHardwareAddress.DataLength;
  1882. Data = ClientInfo->ClientHardwareAddress.Data;
  1883. printf("\tClient Hardware Address Length = %ld.\n", DataLength );
  1884. for( i = 0; i < DataLength; i++ ) {
  1885. if( (i+1) < DataLength ) {
  1886. printf("%.2lx-", (DWORD)Data[i]);
  1887. }
  1888. else {
  1889. printf("%.2lx", (DWORD)Data[i]);
  1890. }
  1891. }
  1892. printf(".\n");
  1893. printf("\tName = %ws.\n", ClientInfo->ClientName);
  1894. printf("\tComment = %ws.\n", ClientInfo->ClientComment);
  1895. printf("\tExpires = %lx %lx.\n",
  1896. ClientInfo->ClientLeaseExpires.dwHighDateTime,
  1897. ClientInfo->ClientLeaseExpires.dwLowDateTime);
  1898. printf("\tOwner Host IP Address = %ld.\n",
  1899. ClientInfo->OwnerHost.IpAddress );
  1900. printf("\tOwner Host NetBios Name = %ws.\n",
  1901. ClientInfo->OwnerHost.NetBiosName );
  1902. printf("\tOwner Host Name = %ws.\n",
  1903. ClientInfo->OwnerHost.HostName );
  1904. }
  1905. DWORD
  1906. TestGetClientInfo(
  1907. VOID
  1908. )
  1909. {
  1910. DWORD Error;
  1911. DWORD ReturnError = ERROR_SUCCESS;
  1912. BYTE i;
  1913. WCHAR ClientName[SCRATCH_SMALL_BUFFER_SIZE];
  1914. LPWSTR NameAppend;
  1915. WCHAR Key[SCRATCH_SMALL_BUFFER_SIZE];
  1916. DHCP_SEARCH_INFO SearchInfo;
  1917. LPDHCP_CLIENT_INFO ClientInfo;
  1918. wcscpy( ClientName, L"Client Name ");
  1919. NameAppend = ClientName + wcslen(ClientName);
  1920. SearchInfo.SearchType = DhcpClientName;
  1921. SearchInfo.SearchInfo.ClientName = ClientName;
  1922. for( i = 0; i < CLIENT_COUNT; i++) {
  1923. wcscpy( NameAppend, DhcpRegOptionIdToKey(i, Key) );
  1924. Error = DhcpGetClientInfo(
  1925. GlobalServerIpAddress,
  1926. &SearchInfo,
  1927. &ClientInfo );
  1928. if( Error != ERROR_SUCCESS ) {
  1929. printf("DhcpGetClientInfo failed, %ld.\n", Error );
  1930. ReturnError = Error;
  1931. continue;
  1932. }
  1933. PrintClientInfo( ClientInfo );
  1934. DhcpRpcFreeMemory( ClientInfo );
  1935. }
  1936. return( ReturnError );
  1937. }
  1938. DWORD
  1939. TestSetClientInfo(
  1940. VOID
  1941. )
  1942. {
  1943. DWORD Error;
  1944. DWORD ReturnError = ERROR_SUCCESS;
  1945. DHCP_RESUME_HANDLE ResumeHandle = 0;
  1946. LPDHCP_CLIENT_INFO_ARRAY ClientEnumInfo = NULL;
  1947. DWORD ClientsRead = 0;
  1948. DWORD ClientsTotal = 0;
  1949. DHCP_SEARCH_INFO SearchInfo;
  1950. DWORD i;
  1951. Error = DhcpEnumSubnetClients(
  1952. GlobalServerIpAddress,
  1953. 0,
  1954. &ResumeHandle,
  1955. (DWORD)(-1),
  1956. &ClientEnumInfo,
  1957. &ClientsRead,
  1958. &ClientsTotal );
  1959. if( (Error != ERROR_SUCCESS) && (Error != ERROR_MORE_DATA) ) {
  1960. printf("DhcpEnumSubnetClients failed, %ld.\n", Error );
  1961. return( Error );
  1962. }
  1963. DhcpAssert( ClientEnumInfo != NULL );
  1964. DhcpAssert( ClientEnumInfo->NumElements == ClientsRead );
  1965. if( Error == ERROR_MORE_DATA ) {
  1966. printf("DhcpEnumSubnetClients returned ERROR_MORE_DATA.\n");
  1967. }
  1968. //
  1969. // set client info.
  1970. //
  1971. SearchInfo.SearchType = DhcpClientHardwareAddress;
  1972. for( i = 0; i < ClientsRead; i++ ) {
  1973. WCHAR ClientComment[SCRATCH_SMALL_BUFFER_SIZE];
  1974. LPDHCP_CLIENT_INFO ClientInfo = NULL;
  1975. SearchInfo.SearchInfo.ClientHardwareAddress =
  1976. ClientEnumInfo->Clients[i]->ClientHardwareAddress;
  1977. ClientInfo = NULL;
  1978. Error = DhcpGetClientInfo(
  1979. GlobalServerIpAddress,
  1980. &SearchInfo,
  1981. &ClientInfo );
  1982. if( Error != ERROR_SUCCESS ) {
  1983. printf("DhcpGetClientInfo failed, %ld.\n", Error );
  1984. ReturnError = Error;
  1985. continue;
  1986. }
  1987. DhcpAssert( ClientInfo != NULL);
  1988. //
  1989. // modify client comment.
  1990. //
  1991. if( ClientInfo->ClientComment != NULL ) {
  1992. wcscpy( ClientComment, ClientInfo->ClientComment);
  1993. wcscat( ClientComment, L" - New" );
  1994. }
  1995. else {
  1996. wcscpy( ClientComment, L" - New" );
  1997. }
  1998. ClientInfo->ClientComment = ClientComment;
  1999. Error = DhcpSetClientInfo(
  2000. GlobalServerIpAddress,
  2001. ClientInfo );
  2002. if( Error != ERROR_SUCCESS ) {
  2003. printf("DhcpSetClientInfo failed, %ld.\n", Error );
  2004. ReturnError = Error;
  2005. }
  2006. DhcpRpcFreeMemory( ClientInfo );
  2007. ClientInfo = NULL;
  2008. }
  2009. DhcpRpcFreeMemory( ClientEnumInfo );
  2010. return( ReturnError );
  2011. }
  2012. DWORD
  2013. TestEnumClients(
  2014. LPSTR SubnetAddress
  2015. )
  2016. {
  2017. DWORD Error;
  2018. DHCP_RESUME_HANDLE ResumeHandle = 0;
  2019. LPDHCP_CLIENT_INFO_ARRAY ClientEnumInfo = NULL;
  2020. DWORD ClientsRead = 0;
  2021. DWORD ClientsTotal = 0;
  2022. DWORD i;
  2023. Error = DhcpEnumSubnetClients(
  2024. GlobalServerIpAddress,
  2025. DhcpDottedStringToIpAddress(SubnetAddress),
  2026. &ResumeHandle,
  2027. (DWORD)(-1),
  2028. &ClientEnumInfo,
  2029. &ClientsRead,
  2030. &ClientsTotal );
  2031. if( (Error != ERROR_SUCCESS) && (Error != ERROR_MORE_DATA) ) {
  2032. printf("DhcpEnumSubnetClients failed, %ld.\n", Error );
  2033. return( Error );
  2034. }
  2035. DhcpAssert( ClientEnumInfo != NULL );
  2036. DhcpAssert( ClientEnumInfo->NumElements == ClientsRead );
  2037. printf("Num Client info read = %ld.\n", ClientsRead );
  2038. printf("Total Client count = %ld.\n", ClientsTotal );
  2039. for( i = 0; i < ClientsRead; i++ ) {
  2040. PrintClientInfo( ClientEnumInfo->Clients[i] );
  2041. }
  2042. DhcpRpcFreeMemory( ClientEnumInfo );
  2043. return(Error);
  2044. }
  2045. DWORD
  2046. TestDeleteClients(
  2047. LPSTR SubnetAddress
  2048. )
  2049. {
  2050. DWORD Error;
  2051. DWORD ReturnError = ERROR_SUCCESS;
  2052. DHCP_RESUME_HANDLE ResumeHandle = 0;
  2053. LPDHCP_CLIENT_INFO_ARRAY ClientEnumInfo = NULL;
  2054. DWORD ClientsRead = 0;
  2055. DWORD ClientsTotal = 0;
  2056. DHCP_SEARCH_INFO SearchInfo;
  2057. DWORD i;
  2058. Error = DhcpEnumSubnetClients(
  2059. GlobalServerIpAddress,
  2060. DhcpDottedStringToIpAddress(SubnetAddress),
  2061. &ResumeHandle,
  2062. (DWORD)(-1),
  2063. &ClientEnumInfo,
  2064. &ClientsRead,
  2065. &ClientsTotal );
  2066. if( (Error != ERROR_SUCCESS) && (Error != ERROR_MORE_DATA) ) {
  2067. printf("DhcpEnumSubnetClients failed, %ld.\n", Error );
  2068. return( Error );
  2069. }
  2070. DhcpAssert( ClientEnumInfo != NULL );
  2071. DhcpAssert( ClientEnumInfo->NumElements == ClientsRead );
  2072. if( Error == ERROR_MORE_DATA ) {
  2073. printf("DhcpEnumSubnetClients returned ERROR_MORE_DATA.\n");
  2074. }
  2075. //
  2076. // delete clients.
  2077. //
  2078. SearchInfo.SearchType = DhcpClientIpAddress;
  2079. for( i = 0; i < ClientsRead; i++ ) {
  2080. SearchInfo.SearchInfo.ClientIpAddress =
  2081. ClientEnumInfo->Clients[i]->ClientIpAddress;
  2082. Error = DhcpDeleteClientInfo(
  2083. GlobalServerIpAddress,
  2084. &SearchInfo );
  2085. if( Error != ERROR_SUCCESS ) {
  2086. printf("DhcpDeleteClientInfo failed, %ld.\n", Error );
  2087. ReturnError = Error;
  2088. continue;
  2089. }
  2090. }
  2091. DhcpRpcFreeMemory( ClientEnumInfo );
  2092. return( ReturnError );
  2093. }
  2094. VOID
  2095. TestDhcpMibApi(
  2096. VOID
  2097. )
  2098. {
  2099. DWORD Error;
  2100. LPDHCP_MIB_INFO MibInfo = NULL;
  2101. DWORD i;
  2102. LPSCOPE_MIB_INFO ScopeInfo;
  2103. SYSTEMTIME SystemTime;
  2104. Error = DhcpGetMibInfo(
  2105. GlobalServerIpAddress,
  2106. &MibInfo );
  2107. if( Error != ERROR_SUCCESS ) {
  2108. printf("DhcpGetMibInfo failed, %ld.\n", Error );
  2109. return;
  2110. }
  2111. DhcpAssert( MibInfo != NULL );
  2112. printf("Discovers = %d.\n", MibInfo->Discovers);
  2113. printf("Offers = %d.\n", MibInfo->Offers);
  2114. printf("Requests = %d.\n", MibInfo->Requests);
  2115. printf("Acks = %d.\n", MibInfo->Acks);
  2116. printf("Naks = %d.\n", MibInfo->Naks);
  2117. printf("Declines = %d.\n", MibInfo->Declines);
  2118. printf("Releases = %d.\n", MibInfo->Releases);
  2119. printf("ServerStartTime = ");
  2120. if( FileTimeToSystemTime(
  2121. (FILETIME *)(&MibInfo->ServerStartTime),
  2122. &SystemTime ) ) {
  2123. printf( "%02u/%02u/%02u %02u:%02u:%02u.\n",
  2124. SystemTime.wMonth,
  2125. SystemTime.wDay,
  2126. SystemTime.wYear,
  2127. SystemTime.wHour,
  2128. SystemTime.wMinute,
  2129. SystemTime.wSecond );
  2130. }
  2131. else {
  2132. printf( "Unknown, %ld.\n", GetLastError() );
  2133. }
  2134. printf("Scopes = %d.\n", MibInfo->Scopes);
  2135. ScopeInfo = MibInfo->ScopeInfo;
  2136. for ( i = 0; i < MibInfo->Scopes; i++ ) {
  2137. printf("Subnet = %s.\n",
  2138. DhcpIpAddressToDottedString(ScopeInfo[i].Subnet));
  2139. printf("\tNumAddressesInuse = %d.\n",
  2140. ScopeInfo[i].NumAddressesInuse );
  2141. printf("\tNumAddressesFree = %d.\n",
  2142. ScopeInfo[i].NumAddressesFree );
  2143. printf("\tNumPendingOffers = %d.\n",
  2144. ScopeInfo[i].NumPendingOffers );
  2145. }
  2146. DhcpRpcFreeMemory( MibInfo );
  2147. return;
  2148. }
  2149. VOID
  2150. TestDhcpClientAPIs(
  2151. VOID
  2152. )
  2153. {
  2154. DWORD Error;
  2155. Error = TestCreateClient( "11.1.0.0", CLIENT_COUNT );
  2156. if( Error != ERROR_SUCCESS) {
  2157. printf("TestCreateClient failed, %ld.\n", Error );
  2158. }
  2159. Error = TestGetClientInfo();
  2160. if( Error != ERROR_SUCCESS) {
  2161. printf("TestCreateClient failed, %ld.\n", Error );
  2162. }
  2163. Error = TestSetClientInfo();
  2164. if( Error != ERROR_SUCCESS) {
  2165. printf("TestCreateClient failed, %ld.\n", Error );
  2166. }
  2167. Error = TestGetClientInfo();
  2168. if( Error != ERROR_SUCCESS) {
  2169. printf("TestCreateClient failed, %ld.\n", Error );
  2170. }
  2171. Error = TestEnumClients("11.1.0.0");
  2172. if( Error != ERROR_SUCCESS) {
  2173. printf("TestEnumClients failed, %ld.\n", Error );
  2174. }
  2175. }
  2176. VOID
  2177. TestDhcpRemoveDhcpAPIs(
  2178. VOID
  2179. )
  2180. {
  2181. DWORD Error;
  2182. Error = TestDeleteClients("11.1.0.0");
  2183. if( Error != ERROR_SUCCESS) {
  2184. printf("TestEnumClients failed, %ld.\n", Error );
  2185. }
  2186. //
  2187. // remove Ip Ranges.
  2188. //
  2189. Error = TestRemoveSubnetIpRange( "11.2.0.0", "11.2.1.0", "11.2.1.255" );
  2190. printf("TestRemoveSubnetIpRange(%s) result = %ld.\n", "11.2.0.0", Error );
  2191. //
  2192. // Remove secondary host.
  2193. //
  2194. Error = TestRemoveSecondaryHost( "11.3.0.0", "11.3.11.129" );
  2195. printf("TestRemoveSecondaryHost(%s) result = %ld.\n", "11.3.0.0", Error );
  2196. //
  2197. // Remove Reserve IpAddress
  2198. //
  2199. Error = TestRemoveReserveIpAddress( "11.4.0.0", "11.4.111.222" );
  2200. printf("TestRemoveReserveIpAddress(%s) result = %ld.\n",
  2201. "11.4.0.0",
  2202. Error );
  2203. //
  2204. // Remove Exclude IpRanges
  2205. //
  2206. Error = TestRemoveExcludeSubnetIpRange(
  2207. "11.5.0.0",
  2208. "11.5.0.100",
  2209. "11.5.0.255" );
  2210. printf("TestRemoveExcludeSubnetIpRange(%s) result = %ld.\n",
  2211. "11.5.0.0",
  2212. Error );
  2213. Error = TestRemoveExcludeSubnetIpRange(
  2214. "11.6.0.0",
  2215. "11.6.3.200",
  2216. "11.6.3.255" );
  2217. printf("TestRemoveExcludeSubnetIpRange(%s) result = %ld.\n",
  2218. "11.6.0.0",
  2219. Error );
  2220. Error = TestRemoveExcludeSubnetIpRange(
  2221. "11.6.0.0",
  2222. "11.6.5.100",
  2223. "11.6.5.200" );
  2224. printf("TestRemoveExcludeSubnetIpRange(%s) result = %ld.\n",
  2225. "11.6.0.0",
  2226. Error );
  2227. //
  2228. // remove Subnets.
  2229. //
  2230. Error = TestDhcpDeleteSubnet( "11.1.0.0" );
  2231. printf("TestDhcpDeleteSubnet(%s) result = %ld.\n", "11.1.0.0", Error );
  2232. Error = TestDhcpDeleteSubnet( "11.2.0.0" );
  2233. printf("TestDhcpDeleteSubnet(%s) result = %ld.\n", "11.2.0.0", Error );
  2234. Error = Test1DhcpDeleteSubnet( "11.2.0.0" );
  2235. printf("Test1DhcpDeleteSubnet(%s) result = %ld.\n", "11.2.0.0", Error );
  2236. Error = TestDhcpDeleteSubnet( "11.3.0.0" );
  2237. printf("TestDhcpDeleteSubnet(%s) result = %ld.\n", "11.3.0.0", Error );
  2238. Error = TestDhcpDeleteSubnet( "11.4.0.0" );
  2239. printf("TestDhcpDeleteSubnet(%s) result = %ld.\n", "11.4.0.0", Error );
  2240. Error = TestDhcpDeleteSubnet( "11.5.0.0" );
  2241. printf("TestDhcpDeleteSubnet(%s) result = %ld.\n", "11.5.0.0", Error );
  2242. Error = TestDhcpDeleteSubnet( "11.6.0.0" );
  2243. printf("TestDhcpDeleteSubnet(%s) result = %ld.\n", "11.6.0.0", Error );
  2244. }
  2245. VOID
  2246. TestDhcpSpecial(
  2247. LPSTR SubnetAddressString,
  2248. LPSTR SubnetMaskString
  2249. )
  2250. {
  2251. DWORD Error;
  2252. DHCP_IP_MASK SubnetMask;
  2253. //
  2254. // create a subnet.
  2255. //
  2256. SubnetMask = DhcpDottedStringToIpAddress(SubnetMaskString);
  2257. Error = TestDhcpCreateSubnet(
  2258. SubnetAddressString,
  2259. SubnetMask,
  2260. L"Subnet1",
  2261. L"Subnet1 Comment",
  2262. "127.0.0.1",
  2263. L"Subnet1PrimaryHostName",
  2264. L"Subnet1PrimaryNBName",
  2265. DhcpSubnetEnabled
  2266. );
  2267. printf("TestDhcpCreateSubnet(%s) result = %ld.\n",
  2268. SubnetAddressString, Error );
  2269. if( Error != ERROR_SUCCESS ) {
  2270. return;
  2271. }
  2272. //
  2273. // add subnet IpAddress Range.
  2274. //
  2275. Error = TestAddSubnetIpRange1(
  2276. SubnetAddressString,
  2277. SubnetMask );
  2278. if( Error != ERROR_SUCCESS ) {
  2279. return;
  2280. }
  2281. Error = TestCreateClient(
  2282. SubnetAddressString,
  2283. (~SubnetMask > 10000 ) ? 10000 : ~SubnetMask );
  2284. }
  2285. DWORD __cdecl
  2286. main(
  2287. int argc,
  2288. char **argv
  2289. )
  2290. {
  2291. if( argc < 2 ) {
  2292. printf("usage:testapis server-ipaddress <othertests> \n");
  2293. return(1);
  2294. }
  2295. GlobalServerIpAddress = DhcpOemToUnicode( argv[1], NULL );
  2296. if( GlobalServerIpAddress == NULL ) {
  2297. printf("Insufficient memory\n");
  2298. return(1);
  2299. }
  2300. srand( (DWORD)time( NULL ) );
  2301. if( argc == 2 ) {
  2302. TestDhcpSubnetAPIs();
  2303. TestDhcpOptionAPIs();
  2304. TestDhcpClientAPIs();
  2305. TestDhcpMibApi();
  2306. TestDhcpRemoveDhcpAPIs();
  2307. }
  2308. else if( _stricmp(argv[2], "JetTest") == 0 ) {
  2309. if( argc < 5 ) {
  2310. printf("usage:testapis server-ipaddress JetTest subnet-addr subnet-mask \n");
  2311. return(1);
  2312. }
  2313. TestDhcpSpecial( argv[3], argv[4] );
  2314. }
  2315. #if 0
  2316. TestEnumClients( "11.1.0.0" );
  2317. #endif
  2318. return(0);
  2319. }