hey all....this is a snippet of code which I am going to use to call a function called trace(), which traceroute's to a specified host. what I want to do here is traceroute continuously until a user-specified time.
this code is not returning the right times, and no matter what time I enter in, the program says it is roughly twice what the current time is and the difference is always 1024 seconds.
have I got the types right? there is probably something small I'm missing.
this will take some knowledge of <time.h> to solve.
#include<sys/time.h>
int option,
quit = 1,
temp1 = 0,
temp2 = 0;
double difference = 0;
time_t stoptime ;
time_t now;
struct tm stop;
now = time(NULL);
while(quit != 0)
{
printf("Please enter option.\n\n");
printf("1 Conduct a fixed number of Traceroutes.\n");
printf("2 Conduct Traceroutes Until a specific Time.\n");
printf("3 Quit\n\n\n");
scanf("%d", &option);
switch(option)
{
case 1

rintf("Please enter the time you would like to run Traceroute until.\n\n");
printf("\nYear: YYYY\n");
scanf("%d", &temp1);
stop.tm_year = temp1 - 1900;
printf("\nMonth: 1-12\n");
scanf("%d", &temp2);
stop.tm_mon = temp2 - 1;
printf("\nday of the month: 0-31\n");
scanf("%d", &stop.tm_mday);
printf("\nhour (24hour clock):\n");
scanf("%d", &stop.tm_hour);
printf("\nminute:\n");
scanf("%d", &stop.tm_min);
printf("\nsecond:\n");
scanf("%d", &stop.tm_sec);
if(mktime(&stop) == -1)
{
printf("Error getting time.\n");
}
stoptime = mktime(&stop);
now = time(NULL);
printf("stop = %d\n", &stoptime);
printf("now = %d\n", &now);
difference = difftime(now, stoptime);
printf("difference in seconds: %f.\n", &difference);
/*
for(; now < stoptime; now = time(NULL))
{
trace(ip);
}
quit = 0;
*/
break;