another question about time()

Abby (J.P.) the.ueabraham at laposte.net
Wed Apr 26 23:50:57 PDT 2006


Tydr Schnubbis wrote:
> Abby (J.P.) wrote:
>> Hello, I'm trying to make a ping utility, I made a working ICMP 
>> request (I tested it with Ethereal, I get a reply from the server). 
>> But I wonder how much precise are the std.c.time.time() or the 
>> std.date.time(), because I always find a ping of 0ms (I know that it 
>> must be 1000 ticks per seconds, but I'm not sure, this really is).
>> Here is my code :
>>
>>
>> char[] host = "www.microsoft.com"
>> InternetHost targetHost;
>> targetHost.getHostByName(host);
>>
>> InternetAddress targetAddress = new 
>> InternetAddress(targetHost.addrList[0], InternetAddress.PORT_ANY);
>>
>> Socket pingingSocket = new Socket(AddressFamily.INET, SocketType.RAW, 
>> ProtocolType.ICMP);
>>
>> //pingingSocket.connect(targetAddress);
>> //long start_time = getUTCtime();
>> int start_time;
>> std.c.time.time(&start_time);
>>
>> pingingSocket.sendTo(PING_REQUEST, targetAddress);
>>
>> char[] response;
>> pingingSocket.receive(response);
>>
>> //long end_time = getUTCtime();
>> int end_time;
>> std.c.time.time(&end_time);
>>
>> // char [] str_ping = std.string.toString((end_time - start_time));
>> char [] str_ping = std.string.toString((end_time - start_time)/2);
>> pingingSocket.close();
>> printf("ping : " ~ str_ping);
>>
>> As you can see, I tried both std.c.time and std.date functions, but 
>> str_ping is always 0. Did I done something wrong ? Should I put the 
>> start_time before the resolving getHostByName() ?
>>
>> -- 
>> Abby
> 
> I can't ping www.microsoft.com at all, did you try another address, like 
> google.com?

yes, I tried few addresses (I thought microsoft.com would work also)
IP addresses on my LAN (with getHostByAddr) produce the same probleme.
But you're right, I should check the char[] response to see if the 
server has anwsered me !

I'm going to use std.perf as Dereck told me (I hope it will work !)

Thanks for your anwsers

--
Abby



More information about the Digitalmars-d-learn mailing list