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.

73 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2000, Microsoft Corporation
  3. Module Name:
  4. enablerouter.c
  5. Abstract:
  6. This module implements a system utility for dynamically enabling forwarding
  7. on Windows 2000 systems using the EnableRouter and UnenableRouter routines.
  8. Author:
  9. Abolade Gbadegesin (aboladeg) 26-March-1999
  10. Revision History:
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. int __cdecl
  16. main(
  17. int argc,
  18. char* argv[]
  19. )
  20. {
  21. HINSTANCE Hinstance = LoadLibrary("IPHLPAPI.DLL");
  22. if (!Hinstance) {
  23. printf("LoadLibrary: %d\n", GetLastError());
  24. } else {
  25. DWORD (WINAPI* EnableRouter)(PHANDLE, LPOVERLAPPED) =
  26. (DWORD (WINAPI*)(PHANDLE, LPOVERLAPPED))
  27. GetProcAddress(Hinstance, "EnableRouter");
  28. DWORD (WINAPI* UnenableRouter)(LPOVERLAPPED, LPDWORD) =
  29. (DWORD (WINAPI*)(LPOVERLAPPED, LPDWORD))
  30. GetProcAddress(Hinstance, "UnenableRouter");
  31. if (!EnableRouter || !UnenableRouter) {
  32. printf("GetProcAddress: %d\n", GetLastError());
  33. } else {
  34. DWORD Error;
  35. HANDLE Handle;
  36. OVERLAPPED Overlapped;
  37. DWORD Count;
  38. ZeroMemory(&Overlapped, sizeof(Overlapped));
  39. Overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  40. if (!Overlapped.hEvent) {
  41. printf("CreateEvent: %d\n", GetLastError());
  42. } else {
  43. Error = EnableRouter(&Handle, &Overlapped);
  44. if (Error != ERROR_IO_PENDING) {
  45. printf("EnableRouter: %d\n", Error);
  46. } else {
  47. printf("Forwarding is now enabled.");
  48. printf("Press <Enter> to disable forwarding...");
  49. getchar();
  50. Error = UnenableRouter(&Overlapped, &Count);
  51. if (Error) {
  52. printf("UnenableRouter: %d\n", Error);
  53. } else {
  54. printf("UnenableRouter: %d references left\n", Count);
  55. }
  56. CloseHandle(Overlapped.hEvent);
  57. }
  58. }
  59. }
  60. FreeLibrary(Hinstance);
  61. }
  62. return 0;
  63. }