[Autosec-devel] sonar/plugins network_icmp.c,1.33,1.34
Brought to you by:
red0x
From: <re...@us...> - 2004-01-12 09:20:43
|
Update of /cvsroot/autosec/sonar/plugins In directory sc8-pr-cvs1:/tmp/cvs-serv29153/plugins Modified Files: network_icmp.c Log Message: Add per packet ping statistics back into the ICMP scan Index: network_icmp.c =================================================================== RCS file: /cvsroot/autosec/sonar/plugins/network_icmp.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** network_icmp.c 6 Dec 2003 00:14:04 -0000 1.33 --- network_icmp.c 12 Jan 2004 09:20:40 -0000 1.34 *************** *** 54,59 **** /// Timestamp Time zone static struct timezone tz; - /// Timestamp timeval - static struct timeval tp; static unsigned int num_hosts; --- 54,57 ---- *************** *** 79,82 **** --- 77,81 ---- static const char *unreach_codes(int code); static RETSIGTYPE sig_handler(int i); + static void tvsub(struct timeval *out, struct timeval *in); /** @fn plugin_init(void *in_data) *************** *** 518,521 **** --- 517,521 ---- struct sockaddr_in *sa; struct in_addr ia; + struct timeval *tv; assert(target != NULL); *************** *** 533,536 **** --- 533,538 ---- else total_size += 64 + (int) (290.0 * rand() / (RAND_MAX + 64.0)); + /* adding timeval structure to end of packet */ + total_size += sizeof(struct timeval); for(j = 0; j <= target->extra_hosts; j++) *************** *** 550,554 **** } /* how much of the packet is data? */ ! dlen = total_size - sizeof(struct icmp); buf = (char *) malloc(total_size); if(!buf) --- 552,556 ---- } /* how much of the packet is data? */ ! dlen = total_size - sizeof(struct icmp) - sizeof(struct timeval); buf = (char *) malloc(total_size); if(!buf) *************** *** 565,573 **** icmp_hdr->icmp_cksum = 0; /* random sequence number, to make fingerprinting this tool harder */ ! /* clock works well, that way we can count round trip time as well */ ! /* however, the down side is that they always increase... */ ! icmp_hdr->icmp_seq = seq_no2 = clock();/*seq_no2 = low_seq + (int) (25.0 * rand() / (RAND_MAX + 1.0));*/ ! ! datapart = buf + sizeof(struct icmp); /* no payload */ if(!payload_file) --- 567,576 ---- icmp_hdr->icmp_cksum = 0; /* random sequence number, to make fingerprinting this tool harder */ ! low_seq = 1 + (int) (25.0 * rand() / (RAND_MAX + 1.0)); ! icmp_hdr->icmp_seq = seq_no2 = low_seq + (int) (25.0 * rand() / (RAND_MAX + 1.0)); ! /* time value included in packet */ ! tv = (struct timeval *) (buf + sizeof(struct icmp)); ! ! datapart = buf + sizeof(struct icmp) + sizeof(struct timeval); /* no payload */ if(!payload_file) *************** *** 636,641 **** } } ! ! gettimeofday(&tp, &(tz)); ((struct icmp *) buf)->icmp_cksum = --- 639,645 ---- } } ! ! /* Changed to per-packet based timestamp */ ! gettimeofday(tv, &(tz)); ((struct icmp *) buf)->icmp_cksum = *************** *** 673,677 **** unsigned long triptime; unsigned long num_res = 0; ! struct timeval tv; int bread, ret, len; char buf[MAX_PACKET], *adr = NULL; --- 677,681 ---- unsigned long triptime; unsigned long num_res = 0; ! struct timeval *tv, tr; int bread, ret, len; char buf[MAX_PACKET], *adr = NULL; *************** *** 701,711 **** while((done == 0 || clock() <= rec->max) && rec->responses < rec->hosts) { ! tv.tv_usec = 0; ! tv.tv_sec = 0; ! FD_ZERO(&rfds); FD_SET(my_socket, &rfds); ! ret = select(my_socket + 1, &rfds, NULL, NULL, &tv); if(ret == -1) { --- 705,715 ---- while((done == 0 || clock() <= rec->max) && rec->responses < rec->hosts) { ! tr.tv_sec = 0; ! tr.tv_usec = 0; ! FD_ZERO(&rfds); FD_SET(my_socket, &rfds); ! ret = select(my_socket + 1, &rfds, NULL, NULL, &tr); if(ret == -1) { *************** *** 747,756 **** iphdr->ip_src.s_addr; ! if(bread < iphdrlen + ICMP_MIN) mthis->message("Too few bytes from %s\n", inet_ntoa(from.sin_addr)); icmphdr = (struct icmp *) (buf + iphdrlen); ! adr = malloc(25); if(!adr) --- 751,762 ---- iphdr->ip_src.s_addr; ! if(bread < iphdrlen + ICMP_MIN + sizeof(struct timeval)) mthis->message("Too few bytes from %s\n", inet_ntoa(from.sin_addr)); icmphdr = (struct icmp *) (buf + iphdrlen); ! /* timestamp of time this packet was sent */ ! tv = (struct timeval *) (buf + iphdrlen + sizeof(struct icmp)); ! adr = malloc(25); if(!adr) *************** *** 797,805 **** continue; }*/ ! /* clock ticks since this packet has been gone */ ! triptime = (clock() - icmphdr->icmp_seq); ! triptime = (triptime * 1000) / CLOCKS_PER_SEC; /* ms */ ! /* calculating the trip time this way seems to only have ! a resolution of 10 ms */ if(icmphdr->icmp_type != resptype(my_type)) { --- 803,813 ---- continue; }*/ ! ! gettimeofday(&tr, &tz); ! ! /* how long since this packet has been gone */ ! tvsub(&tr, tv); ! triptime = tr.tv_sec*1000.0 + tr.tv_usec/1000.0; ! if(icmphdr->icmp_type != resptype(my_type)) { *************** *** 1058,1060 **** --- 1066,1079 ---- /* just close the thread and be done with it */ pthread_exit(NULL); + } + + /* out = out - in */ + static void tvsub(struct timeval *out, struct timeval *in) + { + if((out->tv_usec -= in->tv_usec) < 0) + { + out->tv_sec--; + out->tv_usec += 1000000; + } + out->tv_sec -= in->tv_sec; } |