digitalmars.D.learn - another question about time()
- Abby (J.P.) (32/32) Apr 26 2006 Hello, I'm trying to make a ping utility, I made a working ICMP request
- Tydr Schnubbis (3/46) Apr 26 2006 I can't ping www.microsoft.com at all, did you try another address, like...
- Abby (J.P.) (9/56) Apr 26 2006 yes, I tried few addresses (I thought microsoft.com would work also)
- Abby (J.P.) (11/71) Apr 27 2006 After testing the content of char[] response, it looks like the problem
- Derek Parnell (16/55) Apr 26 2006 You might be better to use another undocumented module 'std.perf'.
- Bruno Medeiros (5/62) Apr 30 2006 Wouldn't clock() suffice ?
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
Apr 26 2006
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?
Apr 26 2006
Tydr Schnubbis wrote:Abby (J.P.) wrote: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 -- AbbyHello, 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() ? -- AbbyI can't ping www.microsoft.com at all, did you try another address, like google.com?
Apr 26 2006
Abby (J.P.) wrote:Tydr Schnubbis wrote:After testing the content of char[] response, it looks like the problem comes from pingingSocket.receive(response) The string is always null, and that might also be the cause of my bad timer. But I can see the resquest AND the reply fom the server in ethereal. Is there something special to do, when working with ICMP packets ? I didn't use connect(Address) so my socket is not connected, maybe I should specify that it has to listen for incoming packets ?Abby (J.P.) wrote: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 -- AbbyHello, 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() ? -- AbbyI can't ping www.microsoft.com at all, did you try another address, like google.com?
Apr 27 2006
On Wed, 26 Apr 2006 22:09:05 +0200, 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() ?
You might be better to use another undocumented module 'std.perf'.
For example ...
import std.perf;
. . .
ProcessTimesCounter counter = new ProcessTimesCounter();
counter.start();
. . . the stuff you want to time . . .
counter.stop();
writefln("Duration: %s microseconds", counter.microseconds);
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
27/04/2006 10:50:33 AM
Apr 26 2006
Derek Parnell wrote:On Wed, 26 Apr 2006 22:09:05 +0200, Abby (J.P.) wrote:Wouldn't clock() suffice ? -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DHello, 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() ?You might be better to use another undocumented module 'std.perf'. For example ... import std.perf; . . . ProcessTimesCounter counter = new ProcessTimesCounter(); counter.start(); . . . the stuff you want to time . . . counter.stop(); writefln("Duration: %s microseconds", counter.microseconds);
Apr 30 2006









"Abby (J.P.)" <the.ueabraham laposte.net> 