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.

142 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 2000, Microsoft Corporation
  3. Module Name:
  4. irdp.c
  5. Abstract:
  6. This module implements a utility to manipulate the TCP/IP driver's
  7. ICMP router-discovery (IRDP) settings.
  8. Author:
  9. Abolade Gbadegesin (aboladeg) 11-May-1999
  10. Revision History:
  11. --*/
  12. #define _PNP_POWER_
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <ndispnp.h>
  18. #include <ntddip.h>
  19. #include <iphlpapi.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. const char IrdpEnabled[] = "IrdpEnabled";
  23. const char IrdpDisabled[] = "IrdpDisabled";
  24. const char IrdpDisabledUseDhcp[] = "IrdpDisabledUseDhcp";
  25. const char Option31On[] = "Option31On";
  26. const char Option31Off[] = "Option31Off";
  27. const char Option31Absent[] = "Option31Absent";
  28. int __cdecl
  29. main(
  30. int argc,
  31. char* argv[]
  32. )
  33. {
  34. PIP_ADAPTER_INFO AdapterInfo;
  35. ANSI_STRING AnsiString;
  36. UNICODE_STRING BindList;
  37. UCHAR Buffer[4192];
  38. CHAR Device[80] = "\\Device\\";
  39. ULONG Error;
  40. ULONG Index;
  41. UNICODE_STRING LowerComponent;
  42. IP_PNP_RECONFIG_REQUEST Request;
  43. ULONG Size;
  44. WCHAR Tcpip[] = L"Tcpip";
  45. UNICODE_STRING UpperComponent;
  46. ZeroMemory(&Request, sizeof(Request));
  47. Request.version = IP_PNP_RECONFIG_VERSION;
  48. if (argc != 4) {
  49. Error = TRUE;
  50. } else {
  51. Error = FALSE;
  52. Index = atol(argv[1]);
  53. AdapterInfo = (PIP_ADAPTER_INFO)Buffer;
  54. Size = sizeof(Buffer);
  55. if (GetAdaptersInfo(AdapterInfo, &Size) != NO_ERROR) {
  56. Error = TRUE;
  57. } else {
  58. PIP_ADAPTER_INFO ai;
  59. for (ai = AdapterInfo; ai; ai = ai->Next) {
  60. if (ai->Index == Index) {
  61. strncat(Device, ai->AdapterName,
  62. RTL_NUMBER_OF(Device) - strlen(Device) - 1);
  63. break;
  64. }
  65. }
  66. if (!ai) { Error = TRUE; }
  67. }
  68. Request.Flags |= IP_PNP_FLAG_PERFORM_ROUTER_DISCOVERY;
  69. if (lstrcmpi(argv[2], IrdpEnabled) == 0) {
  70. Request.PerformRouterDiscovery = IP_IRDP_ENABLED;
  71. } else if (lstrcmpi(argv[2], IrdpDisabled) == 0) {
  72. Request.PerformRouterDiscovery = IP_IRDP_DISABLED;
  73. } else if (lstrcmpi(argv[2], IrdpDisabledUseDhcp) == 0) {
  74. Request.PerformRouterDiscovery = IP_IRDP_DISABLED_USE_DHCP;
  75. } else {
  76. Error = TRUE;
  77. }
  78. if (lstrcmpi(argv[3], Option31On) == 0) {
  79. Request.Flags |= IP_PNP_FLAG_DHCP_PERFORM_ROUTER_DISCOVERY;
  80. Request.DhcpPerformRouterDiscovery = TRUE;
  81. } else if (lstrcmpi(argv[3], Option31Off) == 0) {
  82. Request.Flags |= IP_PNP_FLAG_DHCP_PERFORM_ROUTER_DISCOVERY;
  83. Request.DhcpPerformRouterDiscovery = FALSE;
  84. } else if (lstrcmpi(argv[3], Option31Absent) == 0) {
  85. // leave the field blank.
  86. } else {
  87. Error = TRUE;
  88. }
  89. }
  90. if (Error) {
  91. printf("Usage:\n");
  92. printf(
  93. "irdp <interface-index>\n"
  94. " <%s|%s|%s>\n"
  95. " <%s|%s|%s>\n\n",
  96. IrdpEnabled, IrdpDisabled, IrdpDisabledUseDhcp,
  97. Option31On, Option31Off, Option31Absent
  98. );
  99. printf("<%s|%s|%s>:\n", IrdpEnabled, IrdpDisabled, IrdpDisabledUseDhcp);
  100. printf(" indicates the local setting for IRDP\n\n");
  101. printf("<%s|%s|%s>:\n", Option31On, Option31Off, Option31Absent);
  102. printf(" simulates the setting of DHCP option 31\n\n");
  103. return 0;
  104. }
  105. printf("Device: %d [%s]\n", Index, Device);
  106. RtlInitUnicodeString(&UpperComponent, Tcpip);
  107. RtlInitAnsiString(&AnsiString, Device);
  108. RtlInitUnicodeString(&LowerComponent, NULL);
  109. RtlAnsiStringToUnicodeString(&LowerComponent, &AnsiString, TRUE);
  110. RtlInitUnicodeString(&BindList, NULL);
  111. Error =
  112. NdisHandlePnPEvent(
  113. NDIS,
  114. RECONFIGURE,
  115. &LowerComponent,
  116. &UpperComponent,
  117. &BindList,
  118. &Request,
  119. sizeof(Request)
  120. );
  121. RtlFreeUnicodeString(&LowerComponent);
  122. printf("NdisHandlePnPEvent: %d\n", Error);
  123. return 0;
  124. }