this class work excellent with 32 bit but dosn't with 64 bit
any body can help me to fix it ?
using System;
using System.Net;
using System.Runtime.InteropServices;
namespace testPing
{
class Class1
{
public static class ServerStatus
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct ICMP_ECHO_REPLY
{
public uint Address;
public uint Status;
public uint RoundTripTime;
public ushort DataSize;
public ushort Reserved;
public IntPtr Data;
public IP_OPTION_INFORMATION Options;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct IP_OPTION_INFORMATION
{
public byte TTL;
public byte TOS;
public byte Flags;
public byte OptionsSize;
public IntPtr OptionsData;
public int RealOptionData;
}
public static class Icmp
{
public const int IP_SUCCESS = 0;
public const int IP_BUF_TOO_SMALL = 11001;
public const int IP_REQ_TIMED_OUT = 11010;
[DllImport("icmp.dll")]
public static extern IntPtr IcmpCreateFile();
[DllImport("icmp.dll")]
public static extern uint IcmpSendEcho(IntPtr icmpHandle, uint
ipAddr, ref int requestData, ushort requestSize, IntPtr optionInfo, ref
ICMP_ECHO_REPLY replyBuffer, uint replySize, int timeout);
[DllImport("icmp.dll")]
public static extern bool IcmpCloseHandle(IntPtr icmpHandle);
public static bool Ping(string host)
{
uint addr =
BitConverter.ToUInt32(IPAddress.Parse(host).GetAddressBytes(), 0);
IntPtr h = IcmpCreateFile();
int req = 123456789;
ICMP_ECHO_REPLY rep = new ICMP_ECHO_REPLY();
uint retval = IcmpSendEcho(h, addr, ref req, 4, IntPtr.Zero,
ref rep, 56, 10);
IcmpCloseHandle(h);
return (retval != 0 && rep.Status == IP_SUCCESS);
}
}
}
}
}