Commit 1903d0d7 authored by robertdavidgraham's avatar robertdavidgraham
Browse files

#71 readscan now reports start time correctly

parent 239850cc
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ parse_status(struct Output *out,
    record.reason    = buf[10];
    record.ttl       = buf[11];

    if (out->when_scan_started == 0)
        out->when_scan_started = record.timestamp;

    switch (record.port) {
    case 53:
    case 123:
@@ -93,6 +96,9 @@ parse_status2(struct Output *out,
    record.reason    = buf[11];
    record.ttl       = buf[12];

    if (out->when_scan_started == 0)
        out->when_scan_started = record.timestamp;

    /*
     * Now report the result
     */
@@ -127,6 +133,8 @@ parse_banner3(struct Output *out, unsigned char *buf, size_t buf_length)
    record.port      = buf[8]<<8 | buf[9];
    record.app_proto = buf[10]<<8 | buf[11];

    if (out->when_scan_started == 0)
        out->when_scan_started = record.timestamp;

    /*
     * Now print the output
@@ -160,6 +168,9 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length)
    record.port      = buf[9]<<8 | buf[10];
    record.app_proto = buf[11]<<8 | buf[12];

    if (out->when_scan_started == 0)
        out->when_scan_started = record.timestamp;

    /*
     * Now print the output
     */
@@ -325,6 +336,12 @@ convert_binary_files(struct Masscan *masscan,

    out = output_create(masscan, 0);
    
    /*
     * Set the start time to zero. We'll read it from the first file
     * that we parse
     */
    out->when_scan_started = 0;

    /*
     * We don't parse the entire argument list, just a subrange
     * containing the list of files. The 'arg_first' parameter
+24 −5
Original line number Diff line number Diff line
@@ -196,9 +196,10 @@ open_rotate(struct Output *out, const char *filename)
    }

    /*
     * Write the format-specific headers, like <xml>
     * Mark the file as newly opened. That way, before writing any data
     * to it, we'll first have to write headers
     */
    out->funcs->open(out, fp);
    out->is_virgin_file = 1;

    return fp;
}
@@ -220,6 +221,7 @@ close_rotate(struct Output *out, FILE *fp)
    /*
     * Write the format-specific trailers, like </xml>
     */
    if (!out->is_virgin_file)
        out->funcs->close(out, fp);

    memset(&out->counts, 0, sizeof(out->counts));
@@ -368,6 +370,7 @@ output_create(const struct Masscan *masscan, unsigned thread_index)
    memset(out, 0, sizeof(*out));
    out->masscan = masscan;
    out->when_scan_started = time(0);
    out->is_virgin_file = 1;

    /*
     * Copy the configuration information from the 'masscan' structure.
@@ -644,7 +647,7 @@ output_report_status(struct Output *out, time_t timestamp, int status,
     * file, rather than in a separate thread right at the time interval.
     * Thus, if results are coming in slowly, the rotation won't happen
     * on precise boundaries */
    if (now >= out->rotate.next) {
    if (now >= out->rotate.next && !out->is_virgin_file) {
        fp = output_do_rotate(out, 0);
        if (fp == NULL)
            return;
@@ -694,6 +697,14 @@ output_report_status(struct Output *out, time_t timestamp, int status,
                return;
    }

    /*
     * If this is a newly opened file, then write file headers
     */
    if (out->is_virgin_file) {
        out->funcs->open(out, fp);
        out->is_virgin_file = 0;
    }

    /*
     * Now do the actual output, whether it be XML, binary, JSON, Redis,
     * and so on.
@@ -753,12 +764,20 @@ output_report_banner(struct Output *out, time_t now,
     * file, rather than in a separate thread right at the time interval.
     * Thus, if results are coming in slowly, the rotation won't happen
     * on precise boundaries */
    if (now >= out->rotate.next) {
    if (now >= out->rotate.next && !out->is_virgin_file) {
        fp = output_do_rotate(out, 0);
        if (fp == NULL)
            return;
    }

    /*
     * If this is a newly opened file, then write file headers
     */
    if (out->is_virgin_file) {
        out->funcs->open(out, fp);
        out->is_virgin_file = 0;
    }

    /*
     * Now do the actual output, whether it be XML, binary, JSON, Redis,
     * and so on.
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ struct Output
    unsigned format;

    time_t when_scan_started;
    unsigned is_virgin_file:1;

    struct {
        time_t next;