Loading src/main-status.c +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ status_print(struct Status *status, uint64_t count, uint64_t max_count) /* Get the time. NOTE: this is CLOCK_MONOTONIC_RAW on Linux, not * wall-clock time. */ now = port_gettime(); now = pixie_gettime(); elapsed = ((double)now - (double)status->last.clock)/(double)1000000.0; if (elapsed == 0) return; Loading src/main-throttle.c +3 −4 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ throttler_start(struct Throttler *throttler, double max_rate) throttler->max_rate = max_rate; for (i=0; i<sizeof(throttler->buckets)/sizeof(throttler->buckets[0]); i++) { throttler->buckets[i].timestamp = port_gettime(); throttler->buckets[i].timestamp = pixie_gettime(); throttler->buckets[i].packet_count = 0; } Loading Loading @@ -69,8 +69,7 @@ again: /* NOTE: this uses CLOCK_MONOTONIC_RAW on Linux, so the timstamp doesn't * move forward when the machine is suspended */ timestamp = port_gettime(); timestamp = pixie_gettime(); /* * We record that last 256 buckets, and average the rate over all of Loading Loading @@ -115,7 +114,7 @@ again: if (waittime > 0.1) waittime = 0.1; port_usleep((uint64_t)(waittime * 1000000.0)); pixie_usleep((uint64_t)(waittime * 1000000.0)); throttler->batch_size *= 0.999; goto again; Loading src/main.c +21 −11 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include "main-status.h" /* printf() regular status updates */ #include "main-throttle.h" /* rate limit */ #include "main-dedup.h" /* ignore duplicate responses */ #include "syn-cookie.h" /* for SYN-cookies on send */ #include "pixie-timer.h" /* portable time functions */ #include "pixie-threads.h" /* portable threads */ Loading Loading @@ -61,7 +62,7 @@ scanning_thread(void *v) status_start(&status); throttler_start(&throttler, masscan->max_rate); timestamp_start = 1.0 * port_gettime() / 1000000.0; timestamp_start = 1.0 * pixie_gettime() / 1000000.0; /* Loading Loading @@ -102,8 +103,14 @@ scanning_thread(void *v) /* Print packet if debugging */ if (packet_trace) tcpkt_trace(pkt_template, ip, port, timestamp_start); /* Send the probe */ rawsock_send_probe(masscan->adapter, ip, port, pkt_template); rawsock_send_probe( masscan->adapter, ip, port, syn_hash(ip, port), pkt_template); i++; Loading Loading @@ -136,7 +143,7 @@ scanning_thread(void *v) unsigned j; for (j=0; j<10 && !control_c_pressed; j++) { status_print(&status, i++, m); port_usleep(1000000); pixie_usleep(1000000); } fprintf(stderr, " \r"); } Loading Loading @@ -461,6 +468,7 @@ main_scan(struct Masscan *masscan) struct PreprocessedInfo parsed; unsigned dst; unsigned src; unsigned seqno; err = rawsock_recv_packet( masscan->adapter, Loading @@ -483,6 +491,9 @@ main_scan(struct Masscan *masscan) | parsed.ip_dst[2]<< 8 | parsed.ip_dst[3]<<0; src = parsed.ip_src[0]<<24 | parsed.ip_src[1]<<16 | parsed.ip_src[2]<< 8 | parsed.ip_src[3]<<0; seqno = px[parsed.transport_offset+8]<<24 | px[parsed.transport_offset+9]<<16 | px[parsed.transport_offset+10]<<8 | px[parsed.transport_offset+11]; seqno -= 1; /* verify: my IP address */ if (adapter_ip != dst) Loading @@ -499,16 +510,14 @@ main_scan(struct Masscan *masscan) if (parsed.found != FOUND_TCP) continue; /* verify: my IP address */ dst = parsed.ip_dst[0]<<24 | parsed.ip_dst[1]<<16 | parsed.ip_dst[2]<< 8 | parsed.ip_dst[3]<<0; if (adapter_ip != dst) continue; /* verify: my port number */ if (adapter_port != parsed.port_dst) continue; if (syn_hash(src, parsed.port_src) != seqno) { LOG(1, "bad packet: ackno=0x%08x expected=0x%08x\n", seqno, syn_hash(src, parsed.port_src)); } /* verify: ignore duplicates */ if (dedup_is_duplicate(dedup, src, parsed.port_src)) continue; Loading Loading @@ -592,7 +601,8 @@ int main(int argc, char *argv[]) * for Windows and PF_RING. */ rawsock_init(); /* Set randomization seed for SYN-cookies */ syn_set_entropy(); /* * Apply excludes Loading Loading @@ -668,7 +678,7 @@ int main(int argc, char *argv[]) x += randlcg_selftest(); x += tcpkt_selftest(); x += ranges_selftest(); x += port_time_selftest(); x += pixie_time_selftest(); if (x != 0) { /* one of the selftests failed, so return error */ Loading src/pixie-timer.c +44 −12 Original line number Diff line number Diff line Loading @@ -89,7 +89,7 @@ clock_gettime(int X, struct timeval *tv) uint64_t port_gettime() pixie_gettime() { //struct timeval tv; //clock_gettime(0, &tv); Loading @@ -106,9 +106,19 @@ port_gettime() //return (uint64_t)tv.tv_sec * 1000000UL + tv.tv_usec; } uint64_t pixie_nanotime() { uint64_t time1 = 0, freq = 0; double seconds; QueryPerformanceCounter((LARGE_INTEGER *) &time1); QueryPerformanceFrequency((LARGE_INTEGER *)&freq); seconds = (double)time1/(double)freq; return (uint64_t)(seconds * 1000000000.0); } void port_usleep(uint64_t waitTime) pixie_usleep(uint64_t waitTime) { /* uint64_t time1 = 0, time2 = 0, freq = 0; Loading @@ -123,16 +133,16 @@ port_usleep(uint64_t waitTime) uint64_t start; start = port_gettime(); start = pixie_gettime(); while (port_gettime() - start < waitTime) while (pixie_gettime() - start < waitTime) ; } #elif defined(CLOCK_MONOTONIC) #include <unistd.h> void port_usleep(uint64_t microseconds) pixie_usleep(uint64_t microseconds) { struct timespec ts; struct timespec remaining; Loading @@ -151,7 +161,7 @@ again: //usleep(microseconds); } uint64_t port_gettime() pixie_gettime() { int x; struct timespec tv; Loading @@ -167,30 +177,52 @@ port_gettime() return tv.tv_sec * 1000000 + tv.tv_nsec/1000; } uint64_t pixie_nanotime() { int x; struct timespec tv; #ifdef CLOCK_MONOTONIC_RAW x = clock_gettime(CLOCK_MONOTONIC_RAW, &tv); #else x = clock_gettime(CLOCK_MONOTONIC, &tv); #endif if (x != 0) { printf("clock_gettime() err %d\n", errno); } return tv.tv_sec * 1000000000 + tv.tv_nsec; } #elif defined(__MACH__) /* works for Apple */ #include <unistd.h> #include <mach/mach_time.h> void port_usleep(uint64_t microseconds) void pixie_usleep(uint64_t microseconds) { usleep(microseconds); } uint64_t port_gettime() pixie_gettime() { return mach_absolute_time()/1000; } uint64_t pixie_nanotime() { return mach_absolute_time(); } #endif int port_time_selftest() int pixie_time_selftest() { static const uint64_t duration = 123456; uint64_t start, stop, elapsed; start = port_gettime(); port_usleep(duration); stop = port_gettime(); start = pixie_gettime(); pixie_usleep(duration); stop = pixie_gettime(); elapsed = stop - start; if (elapsed < 0.9*duration || 1.1*duration < elapsed) { Loading src/pixie-timer.h +10 −5 Original line number Diff line number Diff line #ifndef PORT_TIMER_H #define PORT_TIMER_H #ifndef TIMER_H #define PIXIE_TIMER_H #include <stdint.h> /** * The current time, in microseconds */ uint64_t port_gettime(); uint64_t pixie_gettime(); /** * The current time, in nanoseconds */ uint64_t pixie_nanotime(); /** * Wait the specified number of microseconds */ void port_usleep(uint64_t usec); void pixie_usleep(uint64_t usec); int port_time_selftest(); int pixie_time_selftest(); Loading Loading
src/main-status.c +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ status_print(struct Status *status, uint64_t count, uint64_t max_count) /* Get the time. NOTE: this is CLOCK_MONOTONIC_RAW on Linux, not * wall-clock time. */ now = port_gettime(); now = pixie_gettime(); elapsed = ((double)now - (double)status->last.clock)/(double)1000000.0; if (elapsed == 0) return; Loading
src/main-throttle.c +3 −4 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ throttler_start(struct Throttler *throttler, double max_rate) throttler->max_rate = max_rate; for (i=0; i<sizeof(throttler->buckets)/sizeof(throttler->buckets[0]); i++) { throttler->buckets[i].timestamp = port_gettime(); throttler->buckets[i].timestamp = pixie_gettime(); throttler->buckets[i].packet_count = 0; } Loading Loading @@ -69,8 +69,7 @@ again: /* NOTE: this uses CLOCK_MONOTONIC_RAW on Linux, so the timstamp doesn't * move forward when the machine is suspended */ timestamp = port_gettime(); timestamp = pixie_gettime(); /* * We record that last 256 buckets, and average the rate over all of Loading Loading @@ -115,7 +114,7 @@ again: if (waittime > 0.1) waittime = 0.1; port_usleep((uint64_t)(waittime * 1000000.0)); pixie_usleep((uint64_t)(waittime * 1000000.0)); throttler->batch_size *= 0.999; goto again; Loading
src/main.c +21 −11 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include "main-status.h" /* printf() regular status updates */ #include "main-throttle.h" /* rate limit */ #include "main-dedup.h" /* ignore duplicate responses */ #include "syn-cookie.h" /* for SYN-cookies on send */ #include "pixie-timer.h" /* portable time functions */ #include "pixie-threads.h" /* portable threads */ Loading Loading @@ -61,7 +62,7 @@ scanning_thread(void *v) status_start(&status); throttler_start(&throttler, masscan->max_rate); timestamp_start = 1.0 * port_gettime() / 1000000.0; timestamp_start = 1.0 * pixie_gettime() / 1000000.0; /* Loading Loading @@ -102,8 +103,14 @@ scanning_thread(void *v) /* Print packet if debugging */ if (packet_trace) tcpkt_trace(pkt_template, ip, port, timestamp_start); /* Send the probe */ rawsock_send_probe(masscan->adapter, ip, port, pkt_template); rawsock_send_probe( masscan->adapter, ip, port, syn_hash(ip, port), pkt_template); i++; Loading Loading @@ -136,7 +143,7 @@ scanning_thread(void *v) unsigned j; for (j=0; j<10 && !control_c_pressed; j++) { status_print(&status, i++, m); port_usleep(1000000); pixie_usleep(1000000); } fprintf(stderr, " \r"); } Loading Loading @@ -461,6 +468,7 @@ main_scan(struct Masscan *masscan) struct PreprocessedInfo parsed; unsigned dst; unsigned src; unsigned seqno; err = rawsock_recv_packet( masscan->adapter, Loading @@ -483,6 +491,9 @@ main_scan(struct Masscan *masscan) | parsed.ip_dst[2]<< 8 | parsed.ip_dst[3]<<0; src = parsed.ip_src[0]<<24 | parsed.ip_src[1]<<16 | parsed.ip_src[2]<< 8 | parsed.ip_src[3]<<0; seqno = px[parsed.transport_offset+8]<<24 | px[parsed.transport_offset+9]<<16 | px[parsed.transport_offset+10]<<8 | px[parsed.transport_offset+11]; seqno -= 1; /* verify: my IP address */ if (adapter_ip != dst) Loading @@ -499,16 +510,14 @@ main_scan(struct Masscan *masscan) if (parsed.found != FOUND_TCP) continue; /* verify: my IP address */ dst = parsed.ip_dst[0]<<24 | parsed.ip_dst[1]<<16 | parsed.ip_dst[2]<< 8 | parsed.ip_dst[3]<<0; if (adapter_ip != dst) continue; /* verify: my port number */ if (adapter_port != parsed.port_dst) continue; if (syn_hash(src, parsed.port_src) != seqno) { LOG(1, "bad packet: ackno=0x%08x expected=0x%08x\n", seqno, syn_hash(src, parsed.port_src)); } /* verify: ignore duplicates */ if (dedup_is_duplicate(dedup, src, parsed.port_src)) continue; Loading Loading @@ -592,7 +601,8 @@ int main(int argc, char *argv[]) * for Windows and PF_RING. */ rawsock_init(); /* Set randomization seed for SYN-cookies */ syn_set_entropy(); /* * Apply excludes Loading Loading @@ -668,7 +678,7 @@ int main(int argc, char *argv[]) x += randlcg_selftest(); x += tcpkt_selftest(); x += ranges_selftest(); x += port_time_selftest(); x += pixie_time_selftest(); if (x != 0) { /* one of the selftests failed, so return error */ Loading
src/pixie-timer.c +44 −12 Original line number Diff line number Diff line Loading @@ -89,7 +89,7 @@ clock_gettime(int X, struct timeval *tv) uint64_t port_gettime() pixie_gettime() { //struct timeval tv; //clock_gettime(0, &tv); Loading @@ -106,9 +106,19 @@ port_gettime() //return (uint64_t)tv.tv_sec * 1000000UL + tv.tv_usec; } uint64_t pixie_nanotime() { uint64_t time1 = 0, freq = 0; double seconds; QueryPerformanceCounter((LARGE_INTEGER *) &time1); QueryPerformanceFrequency((LARGE_INTEGER *)&freq); seconds = (double)time1/(double)freq; return (uint64_t)(seconds * 1000000000.0); } void port_usleep(uint64_t waitTime) pixie_usleep(uint64_t waitTime) { /* uint64_t time1 = 0, time2 = 0, freq = 0; Loading @@ -123,16 +133,16 @@ port_usleep(uint64_t waitTime) uint64_t start; start = port_gettime(); start = pixie_gettime(); while (port_gettime() - start < waitTime) while (pixie_gettime() - start < waitTime) ; } #elif defined(CLOCK_MONOTONIC) #include <unistd.h> void port_usleep(uint64_t microseconds) pixie_usleep(uint64_t microseconds) { struct timespec ts; struct timespec remaining; Loading @@ -151,7 +161,7 @@ again: //usleep(microseconds); } uint64_t port_gettime() pixie_gettime() { int x; struct timespec tv; Loading @@ -167,30 +177,52 @@ port_gettime() return tv.tv_sec * 1000000 + tv.tv_nsec/1000; } uint64_t pixie_nanotime() { int x; struct timespec tv; #ifdef CLOCK_MONOTONIC_RAW x = clock_gettime(CLOCK_MONOTONIC_RAW, &tv); #else x = clock_gettime(CLOCK_MONOTONIC, &tv); #endif if (x != 0) { printf("clock_gettime() err %d\n", errno); } return tv.tv_sec * 1000000000 + tv.tv_nsec; } #elif defined(__MACH__) /* works for Apple */ #include <unistd.h> #include <mach/mach_time.h> void port_usleep(uint64_t microseconds) void pixie_usleep(uint64_t microseconds) { usleep(microseconds); } uint64_t port_gettime() pixie_gettime() { return mach_absolute_time()/1000; } uint64_t pixie_nanotime() { return mach_absolute_time(); } #endif int port_time_selftest() int pixie_time_selftest() { static const uint64_t duration = 123456; uint64_t start, stop, elapsed; start = port_gettime(); port_usleep(duration); stop = port_gettime(); start = pixie_gettime(); pixie_usleep(duration); stop = pixie_gettime(); elapsed = stop - start; if (elapsed < 0.9*duration || 1.1*duration < elapsed) { Loading
src/pixie-timer.h +10 −5 Original line number Diff line number Diff line #ifndef PORT_TIMER_H #define PORT_TIMER_H #ifndef TIMER_H #define PIXIE_TIMER_H #include <stdint.h> /** * The current time, in microseconds */ uint64_t port_gettime(); uint64_t pixie_gettime(); /** * The current time, in nanoseconds */ uint64_t pixie_nanotime(); /** * Wait the specified number of microseconds */ void port_usleep(uint64_t usec); void pixie_usleep(uint64_t usec); int port_time_selftest(); int pixie_time_selftest(); Loading