[Autosec-devel] sonar/plugins log_file.c,1.14,1.15 log_xml.c,1.2,1.3 network_icmp.c,1.34,1.35 rfc793
Brought to you by:
red0x
From: <re...@us...> - 2004-01-17 03:12:35
|
Update of /cvsroot/autosec/sonar/plugins In directory sc8-pr-cvs1:/tmp/cvs-serv14128/plugins Modified Files: log_file.c log_xml.c network_icmp.c rfc793.c Log Message: Removed results_t and placed it all in target_t Index: log_file.c =================================================================== RCS file: /cvsroot/autosec/sonar/plugins/log_file.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** log_file.c 10 Nov 2003 10:13:20 -0000 1.14 --- log_file.c 17 Jan 2004 03:12:31 -0000 1.15 *************** *** 40,44 **** static int plugin_close(void); static int plugin_output(char *msg, va_list * ap); ! static int plugin_results(result_t *result); static void plugin_usage(void); static void plugin_status(void); --- 40,44 ---- static int plugin_close(void); static int plugin_output(char *msg, va_list * ap); ! static int plugin_results(target_t *result, unsigned int num); static void plugin_usage(void); static void plugin_status(void); *************** *** 215,219 **** } ! static int null_result(result_t *result) { /* there is no way to report the hostname if we didn't get any responses :( */ --- 215,219 ---- } ! static int null_result(target_t *result) { /* there is no way to report the hostname if we didn't get any responses :( */ *************** *** 223,227 **** } ! static int plugin_results(result_t *result) { struct sockaddr_in *sa = NULL; --- 223,227 ---- } ! static int plugin_results(target_t *result, unsigned int num) { struct sockaddr_in *sa = NULL; *************** *** 229,280 **** char ip6sa_format[] = "%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x\0"; char buf[256]; ! int i; ! ! assert(result != NULL); ! if(result->ainfo == NULL) ! return null_result(result); ! memset(buf, 0, 256); ! fprintf(my_fp, "Host %s[", result->ainfo->ai_canonname); ! switch(result->ainfo->ai_family) ! { ! case PF_INET: ! sa = (struct sockaddr_in*) result->ainfo->ai_addr; ! fprintf(my_fp, "%s] results:", inet_ntoa(sa->sin_addr)); ! break; ! case PF_INET6: ! sa6 = (struct sockaddr_in6 *) result->ainfo->ai_addr; ! snprintf(buf, 255, ip6sa_format, sa6->sin6_addr.s6_addr[0], sa6->sin6_addr.s6_addr[1], ! sa6->sin6_addr.s6_addr[2], sa6->sin6_addr.s6_addr[3], sa6->sin6_addr.s6_addr[4], ! sa6->sin6_addr.s6_addr[5], sa6->sin6_addr.s6_addr[6], sa6->sin6_addr.s6_addr[7], ! sa6->sin6_addr.s6_addr[8], sa6->sin6_addr.s6_addr[9], sa6->sin6_addr.s6_addr[10], ! sa6->sin6_addr.s6_addr[11], sa6->sin6_addr.s6_addr[12], sa6->sin6_addr.s6_addr[13], ! sa6->sin6_addr.s6_addr[14], sa6->sin6_addr.s6_addr[15]); ! fprintf(my_fp, "%s] results:", buf); ! break; ! default: ! fprintf(my_fp, "unknown] results:"); ! }; ! fprintf(my_fp, " rtt=%0.2f ttl=%d\n", result->rtt, result->ttl); ! /* print the port info */ ! for(i =0; i < 65536; i++) { ! switch(result->ports[i]) { ! case PORT_OPENED: ! fprintf(my_fp, " port %d state: open range: %0.2f ttl: %u\n", i, result->rtt, result->ttl); ! break; ! case PORT_CLOSED: ! fprintf(my_fp, " port %d state: closed range: %0.2f ttl: %u\n", i, result->rtt, result->ttl); ! break; ! case PORT_FILTERED: ! fprintf(my_fp, " port %d state: filtered range: %0.2f ttl: %u\n", i, result->rtt, result->ttl); break; ! case PORT_UNFILTERED: ! fprintf(my_fp, " port %d state: unfiltered range: %0.2f ttl: %u\n", i, result->rtt, result->ttl); break; } } - return PLUGIN_OK; } --- 229,290 ---- char ip6sa_format[] = "%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x:%x\0"; char buf[256]; ! int i, j; ! for(j = 0; j < num; j++) { ! assert(result != NULL); ! if(result->addrinfo == NULL) { ! null_result(result); ! continue; ! } ! ! memset(buf, 0, 256); ! fprintf(my_fp, "Host %s[", result->addrinfo->ai_canonname); ! switch(result->addrinfo->ai_family) ! { ! case PF_INET: ! sa = (struct sockaddr_in*) result->addrinfo->ai_addr; ! fprintf(my_fp, "%s] results:", inet_ntoa(sa->sin_addr)); break; ! case PF_INET6: ! sa6 = (struct sockaddr_in6 *) result->addrinfo->ai_addr; ! snprintf(buf, 255, ip6sa_format, sa6->sin6_addr.s6_addr[0], sa6->sin6_addr.s6_addr[1], ! sa6->sin6_addr.s6_addr[2], sa6->sin6_addr.s6_addr[3], sa6->sin6_addr.s6_addr[4], ! sa6->sin6_addr.s6_addr[5], sa6->sin6_addr.s6_addr[6], sa6->sin6_addr.s6_addr[7], ! sa6->sin6_addr.s6_addr[8], sa6->sin6_addr.s6_addr[9], sa6->sin6_addr.s6_addr[10], ! sa6->sin6_addr.s6_addr[11], sa6->sin6_addr.s6_addr[12], sa6->sin6_addr.s6_addr[13], ! sa6->sin6_addr.s6_addr[14], sa6->sin6_addr.s6_addr[15]); ! fprintf(my_fp, "%s] results:", buf); break; + default: + fprintf(my_fp, "unknown] results:"); + }; + fprintf(my_fp, " rtt=%0.2f ttl=%d mask=%d\n", result->stats.rtt_min, result->stats.ttl, result->netmask); + /* print the port info */ + for(i =0; i < 65536; i++) + { + switch(result->ports[i]) + { + case PORT_OPENED: + fprintf(my_fp, " port %d state: open range: %0.2f ttl: %u\n", i, result->stats.rtt_avg, result->stats.ttl); + break; + case PORT_CLOSED: + fprintf(my_fp, " port %d state: closed range: %0.2f ttl: %u\n", i, result->stats.rtt_avg, result->stats.ttl); + break; + case PORT_FILTERED: + fprintf(my_fp, " port %d state: filtered range: %0.2f ttl: %u\n", i, result->stats.rtt_avg, result->stats.ttl); + break; + case PORT_UNFILTERED: + fprintf(my_fp, " port %d state: unfiltered range: %0.2f ttl: %u\n", i, result->stats.rtt_avg, result->stats.ttl); + break; + } } + fprintf(my_fp, " stats: sent: %d, recvd: %d, dropped: %d\n", result->stats.packets_sent, result->stats.packets_recvd, + result->stats.packets_sent - result->stats.packets_recvd); + fprintf(my_fp, " rtt (min/max/avg): %.2f/%.2f/%.2f ms\n", result->stats.rtt_min, result->stats.rtt_max, + result->stats.rtt_avg); + result = result->next; } return PLUGIN_OK; } Index: log_xml.c =================================================================== RCS file: /cvsroot/autosec/sonar/plugins/log_xml.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** log_xml.c 10 Nov 2003 10:13:20 -0000 1.2 --- log_xml.c 17 Jan 2004 03:12:31 -0000 1.3 *************** *** 43,47 **** static int plugin_close(void); static int plugin_output(char *msg, va_list * ap); ! static int plugin_results(result_t *result); static void plugin_usage(void); static void plugin_status(void); --- 43,47 ---- static int plugin_close(void); static int plugin_output(char *msg, va_list * ap); ! static int plugin_results(target_t *result, unsigned int num); static void plugin_usage(void); static void plugin_status(void); *************** *** 223,227 **** } ! static int null_result(result_t *result) { /* as of right now, there is no way to report dead hosts */ --- 223,227 ---- } ! static int null_result(target_t *result) { /* as of right now, there is no way to report dead hosts */ *************** *** 230,234 **** } ! static int plugin_results(result_t *result) { struct sockaddr_in *sa = NULL; --- 230,234 ---- } ! static int plugin_results(target_t *result, unsigned int num_hosts) { struct sockaddr_in *sa = NULL; *************** *** 237,293 **** char buf[256]; /*struct sockaddr_un *un;*/ - assert(result != NULL); - int i; - - if(result->ainfo == NULL) - return null_result(result); ! memset(buf, 0, 256); ! fprintf(my_fp, "\t<host hostname=\"%s\" rtt=\"%0.2f\" ttl=\"%d\"", result->ainfo->ai_canonname, result->rtt, result->ttl); ! switch(result->ainfo->ai_family) ! { ! case PF_INET: ! sa = (struct sockaddr_in*) result->ainfo->ai_addr; ! fprintf(my_fp, " address=\"%s\" addr-type=\"%s\">\n", inet_ntoa(sa->sin_addr), "ipv4"); ! break; ! case PF_INET6: ! sa6 = (struct sockaddr_in6 *) result->ainfo->ai_addr; ! snprintf(buf, 255, ip6sa_format, sa6->sin6_addr.s6_addr[0], sa6->sin6_addr.s6_addr[1], ! sa6->sin6_addr.s6_addr[2], sa6->sin6_addr.s6_addr[3], sa6->sin6_addr.s6_addr[4], ! sa6->sin6_addr.s6_addr[5], sa6->sin6_addr.s6_addr[6], sa6->sin6_addr.s6_addr[7], ! sa6->sin6_addr.s6_addr[8], sa6->sin6_addr.s6_addr[9], sa6->sin6_addr.s6_addr[10], ! sa6->sin6_addr.s6_addr[11], sa6->sin6_addr.s6_addr[12], sa6->sin6_addr.s6_addr[13], ! sa6->sin6_addr.s6_addr[14], sa6->sin6_addr.s6_addr[15]); ! fprintf(my_fp, " address=\"%s\" addr-type=\"%s\">\n", buf, "ipv6"); ! break; ! /*case PF_UNIX: ! un = (struct sockaddr_un*) result->ainfo->ai_addr; ! fprintf(my_fp, " address=\"%s\" addr-type=\"%s\">\n", un->sun_path, "unix"); ! break;*/ ! default: ! fprintf(my_fp, " address=\"%s\" addr-type=\"%s\">\n", "unknown-type", "unknown"); ! }; ! /* print the port info */ ! for(i =0; i < 65536; i++) { ! switch(result->ports[i]) { ! case PORT_OPENED: ! fprintf(my_fp, "\t\t<port number=\"%d\" state=\"open\"/>\n", i); ! break; ! case PORT_CLOSED: ! fprintf(my_fp, "\t\t<port number=\"%d\" state=\"closed\"/>\n", i); ! break; ! case PORT_FILTERED: ! fprintf(my_fp, "\t\t<port number=\"%d\" state=\"filtered\"/>\n", i); break; ! case PORT_UNFILTERED: ! fprintf(my_fp, "\t\t<port number=\"%d\" state=\"unfiltered\"/>\n", i); break; } } - fprintf(my_fp, "\t</host>\n"); - fflush(my_fp); return PLUGIN_OK; } --- 237,306 ---- char buf[256]; /*struct sockaddr_un *un;*/ ! int i, j; ! for(j = 0; j< num_hosts; j++) { ! assert(result != NULL); ! if(result->addrinfo == NULL) { ! null_result(result); ! continue; ! } ! ! memset(buf, 0, 256); ! fprintf(my_fp, "\t<host hostname=\"%s\" rtt=\"%0.2f\" ttl=\"%d\" mask=\"%d\"", result->addrinfo->ai_canonname, ! result->stats.rtt_avg, result->stats.ttl, result->netmask); ! switch(result->addrinfo->ai_family) ! { ! case PF_INET: ! sa = (struct sockaddr_in*) result->addrinfo->ai_addr; ! fprintf(my_fp, " address=\"%s\" addr-type=\"%s\">\n", inet_ntoa(sa->sin_addr), "ipv4"); break; ! case PF_INET6: ! sa6 = (struct sockaddr_in6 *) result->addrinfo->ai_addr; ! snprintf(buf, 255, ip6sa_format, sa6->sin6_addr.s6_addr[0], sa6->sin6_addr.s6_addr[1], ! sa6->sin6_addr.s6_addr[2], sa6->sin6_addr.s6_addr[3], sa6->sin6_addr.s6_addr[4], ! sa6->sin6_addr.s6_addr[5], sa6->sin6_addr.s6_addr[6], sa6->sin6_addr.s6_addr[7], ! sa6->sin6_addr.s6_addr[8], sa6->sin6_addr.s6_addr[9], sa6->sin6_addr.s6_addr[10], ! sa6->sin6_addr.s6_addr[11], sa6->sin6_addr.s6_addr[12], sa6->sin6_addr.s6_addr[13], ! sa6->sin6_addr.s6_addr[14], sa6->sin6_addr.s6_addr[15]); ! fprintf(my_fp, " address=\"%s\" addr-type=\"%s\">\n", buf, "ipv6"); break; + /*case PF_UNIX: + un = (struct sockaddr_un*) result->ainfo->ai_addr; + fprintf(my_fp, " address=\"%s\" addr-type=\"%s\">\n", un->sun_path, "unix"); + break;*/ + default: + fprintf(my_fp, " address=\"%s\" addr-type=\"%s\">\n", "unknown-type", "unknown"); + }; + + /* print the port info */ + for(i =0; i < 65536; i++) + { + switch(result->ports[i]) + { + case PORT_OPENED: + fprintf(my_fp, "\t\t<port number=\"%d\" state=\"open\"/>\n", i); + break; + case PORT_CLOSED: + fprintf(my_fp, "\t\t<port number=\"%d\" state=\"closed\"/>\n", i); + break; + case PORT_FILTERED: + fprintf(my_fp, "\t\t<port number=\"%d\" state=\"filtered\"/>\n", i); + break; + case PORT_UNFILTERED: + fprintf(my_fp, "\t\t<port number=\"%d\" state=\"unfiltered\"/>\n", i); + break; + } } + fprintf(my_fp, "\t\t<stats sent=\"%d\" recvd=\"%d\" dropped=\"%d\" ", result->stats.packets_sent, result->stats.packets_recvd, + result->stats.packets_sent - result->stats.packets_recvd); + fprintf(my_fp, " rtt_min=\"%.2f\" rtt_max=\"%.2f\" rtt_avg=\"%.2f\" />\n", result->stats.rtt_min, result->stats.rtt_max, + result->stats.rtt_avg); + fprintf(my_fp, "\t</host>\n"); + fflush(my_fp); + result = result->next; } return PLUGIN_OK; } Index: network_icmp.c =================================================================== RCS file: /cvsroot/autosec/sonar/plugins/network_icmp.c,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** network_icmp.c 12 Jan 2004 09:20:40 -0000 1.34 --- network_icmp.c 17 Jan 2004 03:12:31 -0000 1.35 *************** *** 24,27 **** --- 24,28 ---- #include <assert.h> #include <pthread.h> + #include <errno.h> #include "network_icmp.h" #include "error.h" *************** *** 94,99 **** // this is assumed mthis = (sonar_t *) in_data; ! if(mthis->api < 5) ! err_msg("Plugin API must be 5 or higher, update sonar"); srand(getpid() ^ (uid_t) time(NULL)); --- 95,100 ---- // this is assumed mthis = (sonar_t *) in_data; ! if(mthis->api < 6) ! err_msg("Plugin API must be 6 or higher, update sonar"); srand(getpid() ^ (uid_t) time(NULL)); *************** *** 103,107 **** seq_no = (int) (256.0 * rand() / (RAND_MAX + 0.0)); payload_file = NULL; ! pthis.version = 5; /* set API version 5 */ //setup my plugin stuff --- 104,108 ---- seq_no = (int) (256.0 * rand() / (RAND_MAX + 0.0)); payload_file = NULL; ! pthis.version = 6; /* set API version 5 */ //setup my plugin stuff *************** *** 279,283 **** { // load socket stuff here - // i_data will be the TTL to set it to uid_t uid; struct linger l; --- 280,283 ---- *************** *** 287,291 **** assert(mthis->getprivs != NULL); assert(mthis->dropprivs != NULL); ! if(mthis->pCon.iPostDelay == -1) mthis->pCon.iPostDelay = 0; //default Post Delay of (NONE) --- 287,291 ---- assert(mthis->getprivs != NULL); assert(mthis->dropprivs != NULL); ! if(mthis->pCon.iPostDelay == -1) mthis->pCon.iPostDelay = 0; //default Post Delay of (NONE) *************** *** 658,662 **** err_msg("wrote %d bytes\n", bwrote); } ! } return PLUGIN_OK; --- 658,662 ---- err_msg("wrote %d bytes\n", bwrote); } ! target->stats.packets_sent++; } return PLUGIN_OK; *************** *** 669,673 **** * @return This thread returns NULL when its done. */ ! static void *recv_thread(void *arg) //struct recv_t *rec) { fd_set rfds; --- 669,673 ---- * @return This thread returns NULL when its done. */ ! static void *recv_thread(void *arg) { fd_set rfds; *************** *** 675,679 **** struct icmp *icmphdr; unsigned short iphdrlen; ! unsigned long triptime; unsigned long num_res = 0; struct timeval *tv, tr; --- 675,679 ---- struct icmp *icmphdr; unsigned short iphdrlen; ! double triptime; unsigned long num_res = 0; struct timeval *tv, tr; *************** *** 684,691 **** struct sockaddr_in from; static struct addrinfo *ai = NULL; - result_t *results, /* results used to pass back to sonar */ - *first_res; /* first on the list */ - static result_t res; /* temporary for *this* result */ int psuedo = false; /* signals, baby */ --- 684,689 ---- struct sockaddr_in from; static struct addrinfo *ai = NULL; int psuedo = false; + target_t *my_host; /* signals, baby */ *************** *** 694,705 **** signal(SIGHUP, sig_handler); signal(SIGSEGV, sig_handler); ! /* make us a list */ ! results = (result_t *) malloc(sizeof(result_t)); ! if(!results) ! err_sys("No memory for result list.\n"); ! first_res = results; /* store a pointer to the top of the list */ rec->responses = 0; - memset(&res, 0, sizeof(result_t)); - memset(results, 0, sizeof(result_t)); while((done == 0 || clock() <= rec->max) && rec->responses < rec->hosts) --- 692,697 ---- signal(SIGHUP, sig_handler); signal(SIGSEGV, sig_handler); ! rec->responses = 0; while((done == 0 || clock() <= rec->max) && rec->responses < rec->hosts) *************** *** 707,710 **** --- 699,703 ---- tr.tv_sec = 0; tr.tv_usec = 0; + my_host = NULL; FD_ZERO(&rfds); *************** *** 714,718 **** if(ret == -1) { ! *(pthis.err) = PLUGIN_ERROR; err_ret("could not select socket\n"); return NULL; //PLUGIN_ERROR; --- 707,711 ---- if(ret == -1) { ! *(pthis.err) = errno; err_ret("could not select socket\n"); return NULL; //PLUGIN_ERROR; *************** *** 740,745 **** continue; } - - memset(&res, 0, sizeof(result_t)); iphdr = (struct ip *) buf; --- 733,736 ---- *************** *** 792,806 **** // can't check based on icmp id's, cause only linux keeps these in replies ! // now we check that the sequence number is in range ! if(icmphdr->icmp_seq > seq_no2 + 1 || icmphdr->icmp_seq < low_seq) ! { ! //keep looking ! continue; ! }/* ! if(icmphdr->i_id != getpid()) { //keep looking continue; }*/ gettimeofday(&tr, &tz); --- 783,796 ---- // can't check based on icmp id's, cause only linux keeps these in replies ! // check based on if we asked to scan this host ! /*if(icmphdr->icmp_seq < low_seq || icmphdr->icmp_seq > seq_no2 + 1) { //keep looking continue; }*/ + if((my_host = mthis->find_target(mthis, ai)) == NULL) + { + continue; + } gettimeofday(&tr, &tz); *************** *** 819,822 **** --- 809,813 ---- icmphdr->icmp_code); rec->responses++; + break; } *************** *** 832,862 **** ai->ai_canonname); - continue; } } ! res.next = NULL; ! len = strlen(ai->ai_canonname); - /* i have problems here, as sometimes this b0rks when its time to get freed */ - res.hostname = (char *) malloc (len +1); - if(!res.hostname) - err_sys("Could not malloc!\n"); - memset(res.hostname, 0, len+1); - strncpy(res.hostname, ai->ai_canonname, len); - res.ainfo = ai; - res.rtt = (double) triptime; - res.ttl = iphdr->ip_ttl; - res.user_data = NULL; num_res++; mthis->message ! ("%s[%s] online: icmp_seq = %d. range: %lu ms ttl: %d size: %d\n", ai->ai_canonname, inet_ntoa(from.sin_addr), icmphdr->icmp_seq, triptime, iphdr->ip_ttl, ntohs(iphdr->ip_len)); - /* put the result in the list */ - mthis->insert_results(results, &res); - /* get rid of our address memory, we dont need it now */ - freeaddrinfo(ai); if(mthis->pCon.prog != NULL) --- 823,851 ---- ai->ai_canonname); } + continue; } ! if(triptime < my_host->stats.rtt_min || my_host->stats.rtt_min == 0) ! my_host->stats.rtt_min = triptime; ! if(triptime > my_host->stats.rtt_max || my_host->stats.rtt_max == 0) ! my_host->stats.rtt_max = triptime; ! if(my_host->stats.rtt_avg == 0) ! my_host->stats.rtt_avg = triptime; ! else ! my_host->stats.rtt_avg = ((((double) my_host->stats.packets_recvd - 1) * my_host->stats.rtt_avg) + triptime) / ! (double) my_host->stats.packets_recvd; ! if(my_host->stats.rtt_avg < 0) ! my_host->stats.rtt_avg *= -1; ! ! my_host->stats.ttl = iphdr->ip_ttl; ! my_host->stats.packets_recvd++; num_res++; mthis->message ! ("%s[%s]\tonline: icmp_seq = %d. range: %.2f ms ttl: %d size: %d\n", ai->ai_canonname, inet_ntoa(from.sin_addr), icmphdr->icmp_seq, triptime, iphdr->ip_ttl, ntohs(iphdr->ip_len)); if(mthis->pCon.prog != NULL) *************** *** 871,882 **** } } ! rec->responses++; continue; } - /* these will work even if results are zero */ - mthis->results(results, num_res); - mthis->free_results(results); - result = rec->hosts - rec->responses; if(result > 0) --- 860,867 ---- } } ! rec->responses++; continue; } result = rec->hosts - rec->responses; if(result > 0) Index: rfc793.c =================================================================== RCS file: /cvsroot/autosec/sonar/plugins/rfc793.c,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** rfc793.c 6 Dec 2003 00:14:04 -0000 1.31 --- rfc793.c 17 Jan 2004 03:12:31 -0000 1.32 *************** *** 28,31 **** --- 28,33 ---- #endif + #include <errno.h> + static const char rcsid[] = "\100$ autosec/sonar: $Id$"; *************** *** 325,329 **** CLOCKS_PER_SEC) / 1000; /* add a default magic number to get some extra (late) responses */ ! recd.max += CLOCKS_PER_SEC / 2000; /* default is one half extra second */ /* start the receiving thread */ --- 327,331 ---- CLOCKS_PER_SEC) / 1000; /* add a default magic number to get some extra (late) responses */ ! recd.max += CLOCKS_PER_SEC / 1000; /* default is one half extra second */ /* start the receiving thread */ *************** *** 336,344 **** if(targets->num_ports > 0) { ! recd.max += ! (timeout * (targets->num_ports - 1) * ! CLOCKS_PER_SEC) / 1000; ! recd.hosts += (targets->num_ports - 1); ! targets->num_ports = 0; } for(i = 0; i < 65536; i++) --- 338,346 ---- if(targets->num_ports > 0) { ! recd.start = clock(); ! recd.max += recd.start + ! (timeout * CLOCKS_PER_SEC) / 1000; ! recd.hosts++; // += (targets->num_ports - 1); ! targets->num_ports--; } for(i = 0; i < 65536; i++) *************** *** 483,486 **** --- 485,489 ---- err_msg("wrote %d bytes\n", bwrote); } + target->stats.packets_sent++; free(packet); /* fresh copy of port list */ *************** *** 498,502 **** struct tcphdr *tcp = NULL; unsigned short iphdrlen; ! unsigned long triptime, unreach = 0, filt = 0, unfilt = 0; struct timeval tv; int bread, ret; --- 501,506 ---- struct tcphdr *tcp = NULL; unsigned short iphdrlen; ! double triptime; ! unsigned long unreach = 0, filt = 0, unfilt = 0; struct timeval tv; int bread, ret; *************** *** 507,515 **** struct sockaddr_in from; static struct addrinfo *ai = NULL; - int psuedo = false; - result_t *results = NULL, /* results used to pass back to sonar */ - *first_res = NULL; /* first on the list */ - static result_t res; /* temporary for *this* result */ unsigned long num_res = 0; /* number of results */ assert(my_socket != -1 && my_socket != 0); --- 511,517 ---- struct sockaddr_in from; static struct addrinfo *ai = NULL; unsigned long num_res = 0; /* number of results */ + int psuedo = false; + target_t *my_host; assert(my_socket != -1 && my_socket != 0); *************** *** 522,532 **** signal(SIGHUP, sig_handler); signal(SIGSEGV, sig_handler); ! /* make us a list */ ! results = (result_t *) malloc(sizeof(result_t)); ! if(!results) ! err_sys("No memory for result list.\n"); ! first_res = results; /* store a pointer to the top of the list */ ! memset(results, 0, sizeof(result_t)); /* dont want to accidentally free an uninitialized value */ ! rec->responses = 0; while((done == 0 || clock() <= rec->max) --- 524,528 ---- signal(SIGHUP, sig_handler); signal(SIGSEGV, sig_handler); ! rec->responses = 0; while((done == 0 || clock() <= rec->max) *************** *** 536,539 **** --- 532,537 ---- tv.tv_usec = 0; tv.tv_sec = 0; + my_host = NULL; + FD_ZERO(&rfds); FD_SET(my_socket, &rfds); *************** *** 544,547 **** --- 542,546 ---- if(ret == -1) { + *(pthis.err) = errno; err_ret("could not select socket\n"); return NULL; //PLUGIN_ERROR; *************** *** 551,555 **** continue; //return PLUGIN_NORESP; } ! if(psuedo == true) { assert(ai != NULL); --- 550,554 ---- continue; //return PLUGIN_NORESP; } ! if(psuedo == true) { assert(ai != NULL); *************** *** 557,563 **** free(ai); } - /* XXX: breaks result returning */ - /*else - freeaddrinfo(ai); */ memset(&from, 0, sizeof(struct sockaddr_in)); --- 556,559 ---- *************** *** 567,572 **** memset(buf, 0, MAX_PACKET); - /* clear the result */ - memset(&res, 0, sizeof(result_t)); if(FD_ISSET(my_socket, &rfds)) { --- 563,566 ---- *************** *** 577,581 **** if(bread == -1) { ! //perror("recvfrom"); err_ret("recvfrom error"); continue; //return PLUGIN_ERROR; --- 571,575 ---- if(bread == -1) { ! *(pthis.err) = errno; err_ret("recvfrom error"); continue; //return PLUGIN_ERROR; *************** *** 635,669 **** } free(adr); // we get something other than a RST, it should be filtered if((tcp->th_flags & TH_RST)) { int len; ! res.next = NULL; ! len = strlen(ai->ai_canonname); ! ! /*res.hostname = ai->ai_canonname; */ ! res.hostname = (char *) malloc(len + 1); ! if(!res.hostname) ! err_sys("Could not malloc!\n"); ! memset(res.hostname, 0, len + 1); ! strncpy(res.hostname, ai->ai_canonname, len); ! res.ports[ntohs(tcp->th_sport)] = PORT_UNFILTERED; ! res.ainfo = ai; ! res.rtt = (double) triptime; ! res.ttl = iphdr->ip_ttl; ! res.user_data = NULL; num_res++; mthis->message ! ("%s[%s]:%d online & UNfiltered: range: %lu ms ttl: %d size: %d\n", ! res.hostname, inet_ntoa(from.sin_addr), ntohs(tcp->th_sport), triptime, iphdr->ip_ttl, ntohs(iphdr->ip_len)); ! /* put the result in the list */ ! mthis->insert_results(results, &res); ! /* get rid of our address memory, we dont need it now */ ! freeaddrinfo(ai); /* print the packet if they want it */ if(mthis->sCon.iVerbose > 1) --- 629,667 ---- } free(adr); + + if((my_host = mthis->find_target(mthis, ai)) == NULL) + { + continue; + } // we get something other than a RST, it should be filtered if((tcp->th_flags & TH_RST)) { int len; ! ! my_host->ports[ntohs(tcp->th_sport)] = PORT_UNFILTERED; ! if(triptime < my_host->stats.rtt_min || my_host->stats.rtt_min == 0) ! my_host->stats.rtt_min = triptime; ! if(triptime > my_host->stats.rtt_max || my_host->stats.rtt_max == 0) ! my_host->stats.rtt_max = triptime; ! if(my_host->stats.rtt_avg == 0) ! my_host->stats.rtt_avg = triptime; ! else ! my_host->stats.rtt_avg = ((((double) my_host->stats.packets_recvd - 1) * my_host->stats.rtt_avg) + triptime) / ! (double) my_host->stats.packets_recvd; ! if(my_host->stats.rtt_avg < 0) ! my_host->stats.rtt_avg *= -1; ! my_host->stats.ttl = iphdr->ip_ttl; ! my_host->stats.packets_recvd++; ! num_res++; mthis->message ! ("%s[%s]:%d online & UNfiltered: range: %.2f ms ttl: %d size: %d\n", ! my_host->addrinfo->ai_canonname, inet_ntoa(from.sin_addr), ntohs(tcp->th_sport), triptime, iphdr->ip_ttl, ntohs(iphdr->ip_len)); ! /* print the packet if they want it */ if(mthis->sCon.iVerbose > 1) *************** *** 760,763 **** --- 758,767 ---- } free(adr); + + if((my_host = mthis->find_target(mthis, ai)) == NULL) + { + continue; + } + rec->responses++; switch (icmphdr->icmp_code) *************** *** 765,789 **** case ICMP_UNREACH_PORT: assert(ai != NULL); ! res.next = NULL; ! /*res.hostname = ai->ai_canonname; */ ! len = strlen(ai->ai_canonname); ! res.hostname = ! (char *) malloc(len + 1); ! if(!res.hostname) ! err_sys("Could not malloc!\n"); ! memset(res.hostname, 0, len + 1); ! strncpy(res.hostname, ! ai->ai_canonname, len); ! res.ports[ntohs(tcp->th_dport)] = PORT_FILTERED; ! res.ainfo = ai; ! res.rtt = (double) triptime; ! res.ttl = iphdr->ip_ttl; ! res.user_data = NULL; num_res++; - mthis->insert_results(results, &res); mthis->message ! ("%s[%s]:%d online & filtered: range: %lu ms ttl: %d size: %d\n", ! ai->ai_canonname, inet_ntoa(from.sin_addr), ntohs(tcp->th_dport), --- 769,793 ---- case ICMP_UNREACH_PORT: assert(ai != NULL); ! my_host->ports[ntohs(tcp->th_dport)] = PORT_FILTERED; ! ! if(triptime < my_host->stats.rtt_min || my_host->stats.rtt_min == 0) ! my_host->stats.rtt_min = triptime; ! if(triptime > my_host->stats.rtt_max || my_host->stats.rtt_max == 0) ! my_host->stats.rtt_max = triptime; ! if(my_host->stats.rtt_avg == 0) ! my_host->stats.rtt_avg = triptime; ! else ! my_host->stats.rtt_avg = ((((double) my_host->stats.packets_recvd - 1) * my_host->stats.rtt_avg) + triptime) / ! (double) my_host->stats.packets_recvd; ! if(my_host->stats.rtt_avg < 0) ! my_host->stats.rtt_avg *= -1; ! my_host->stats.ttl = iphdr->ip_ttl; ! my_host->stats.packets_recvd++; ! num_res++; mthis->message ! ("%s[%s]:%d\tonline & filtered: range: %.2f ms ttl: %d size: %d\n", ! my_host->addrinfo->ai_canonname, inet_ntoa(from.sin_addr), ntohs(tcp->th_dport), *************** *** 822,827 **** break; } ! /* get rid of our address memory, we dont need it now */ ! freeaddrinfo(ai); continue; } --- 826,830 ---- break; } ! continue; } *************** *** 844,849 **** unreach); } - mthis->results(results, num_res); - mthis->free_results(results); return NULL; } --- 847,850 ---- |