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.

123 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. ipaddr.c
  5. Abstract:
  6. Ip Address validation routines.
  7. Author:
  8. Sunita Shrivastava (sunitas) July 19, 1997
  9. Revision History:
  10. Who When What
  11. -------- -------- ----------------------------------------------
  12. sunitas 07-19-97 created
  13. --*/
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. #include <llinfo.h>
  19. #include <wchar.h>
  20. #include <ipexport.h>
  21. #include <cluster.h>
  22. #include <icmpapi.h>
  23. #include <llinfo.h>
  24. #include <ipinfo.h>
  25. //
  26. // Define IP Address ping test data
  27. //
  28. #define ICMP_TTL 128
  29. #define ICMP_TOS 0
  30. #define ICMP_TIMEOUT 500
  31. #define ICMP_TRY_COUNT 4
  32. #define ICMP_BUFFER_SIZE (sizeof(ICMP_ECHO_REPLY) + 8)
  33. BOOL
  34. ClRtlIsDuplicateTcpipAddress(
  35. IN IPAddr IpAddr
  36. )
  37. /*++
  38. Routine Description:
  39. This routine checks whether a give IP Address already exists on the
  40. network.
  41. Arguments:
  42. IpAddr - The IP Address to check for.
  43. Return Value:
  44. TRUE if the specified address exists on the network.
  45. FALSE otherwise.
  46. --*/
  47. {
  48. DWORD status;
  49. IP_OPTION_INFORMATION icmpOptionInfo;
  50. HANDLE icmpHandle;
  51. DWORD numberOfReplies;
  52. DWORD i;
  53. UCHAR icmpBuffer[ICMP_BUFFER_SIZE];
  54. PICMP_ECHO_REPLY reply;
  55. icmpHandle = IcmpCreateFile();
  56. if (icmpHandle != INVALID_HANDLE_VALUE) {
  57. icmpOptionInfo.OptionsData = NULL;
  58. icmpOptionInfo.OptionsSize = 0;
  59. icmpOptionInfo.Ttl = ICMP_TTL;
  60. icmpOptionInfo.Tos = ICMP_TOS;
  61. icmpOptionInfo.Flags = 0;
  62. for (i=0; i<ICMP_TRY_COUNT; i++) {
  63. numberOfReplies = IcmpSendEcho(
  64. icmpHandle,
  65. IpAddr,
  66. NULL,
  67. 0,
  68. &icmpOptionInfo,
  69. icmpBuffer,
  70. ICMP_BUFFER_SIZE,
  71. ICMP_TIMEOUT
  72. );
  73. reply = (PICMP_ECHO_REPLY) icmpBuffer;
  74. while (numberOfReplies != 0) {
  75. if (reply->Status == IP_SUCCESS) {
  76. IcmpCloseHandle( icmpHandle );
  77. return(TRUE);
  78. }
  79. reply++;
  80. numberOfReplies--;
  81. }
  82. }
  83. IcmpCloseHandle( icmpHandle );
  84. }
  85. return(FALSE);
  86. } // ClRtlIsDuplicateTcpipAddress