File: randomdelay.cc

package info (click to toggle)
stealth 1.47.4-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 780 kB
  • ctags: 190
  • sloc: cpp: 1,710; makefile: 155; sh: 62
file content (37 lines) | stat: -rw-r--r-- 874 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "util.ih"

void Util::randomDelay()
{ 
    string delay;

    if (!Arg::instance().option(&delay, 'i'))
        return;

    if (!Arg::instance().option(0, "repeat"))
    {
        cerr << "--random-interval ignored unless --repeat is specified\n";
        return;
    }

    delay += "\n";                  // to make sure the istr doesn't fail
                                    // if only a number is read: no separating
                                    // ws at the end would cause istr.peek() 
                                    // to fail.

    istringstream istr(delay.c_str());

    istr >> s_delayInterval;

    if (istr.peek() == 'm')
        s_delayInterval *= 60;

    if (!istr || s_delayInterval < 0)
        throw Errno(-1, "Invalid interval for --random-interval");

    srandom(time(0));               // seed the random time generator
}