OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / nmap / timing.h
1
2 /***************************************************************************
3  * timing.h -- Functions related to computing scan timing (such as keeping *
4  * track of and adjusting smoothed round trip times, statistical           *
5  * deviations, timeout values, etc.  Various user options (such as the     *
6  * timing policy (-T)) also play a role in these calculations.             *
7  *                                                                         *
8  ***********************IMPORTANT NMAP LICENSE TERMS************************
9  *                                                                         *
10  * The Nmap Security Scanner is (C) 1996-2006 Insecure.Com LLC. Nmap is    *
11  * also a registered trademark of Insecure.Com LLC.  This program is free  *
12  * software; you may redistribute and/or modify it under the terms of the  *
13  * GNU General Public License as published by the Free Software            *
14  * Foundation; Version 2 with the clarifications and exceptions described  *
15  * below.  This guarantees your right to use, modify, and redistribute     *
16  * this software under certain conditions.  If you wish to embed Nmap      *
17  * technology into proprietary software, we sell alternative licenses      *
18  * (contact sales@insecure.com).  Dozens of software vendors already       *
19  * license Nmap technology such as host discovery, port scanning, OS       *
20  * detection, and version detection.                                       *
21  *                                                                         *
22  * Note that the GPL places important restrictions on "derived works", yet *
23  * it does not provide a detailed definition of that term.  To avoid       *
24  * misunderstandings, we consider an application to constitute a           *
25  * "derivative work" for the purpose of this license if it does any of the *
26  * following:                                                              *
27  * o Integrates source code from Nmap                                      *
28  * o Reads or includes Nmap copyrighted data files, such as                *
29  *   nmap-os-fingerprints or nmap-service-probes.                          *
30  * o Executes Nmap and parses the results (as opposed to typical shell or  *
31  *   execution-menu apps, which simply display raw Nmap output and so are  *
32  *   not derivative works.)                                                * 
33  * o Integrates/includes/aggregates Nmap into a proprietary executable     *
34  *   installer, such as those produced by InstallShield.                   *
35  * o Links to a library or executes a program that does any of the above   *
36  *                                                                         *
37  * The term "Nmap" should be taken to also include any portions or derived *
38  * works of Nmap.  This list is not exclusive, but is just meant to        *
39  * clarify our interpretation of derived works with some common examples.  *
40  * These restrictions only apply when you actually redistribute Nmap.  For *
41  * example, nothing stops you from writing and selling a proprietary       *
42  * front-end to Nmap.  Just distribute it by itself, and point people to   *
43  * http://insecure.org/nmap/ to download Nmap.                             *
44  *                                                                         *
45  * We don't consider these to be added restrictions on top of the GPL, but *
46  * just a clarification of how we interpret "derived works" as it applies  *
47  * to our GPL-licensed Nmap product.  This is similar to the way Linus     *
48  * Torvalds has announced his interpretation of how "derived works"        *
49  * applies to Linux kernel modules.  Our interpretation refers only to     *
50  * Nmap - we don't speak for any other GPL products.                       *
51  *                                                                         *
52  * If you have any questions about the GPL licensing restrictions on using *
53  * Nmap in non-GPL works, we would be happy to help.  As mentioned above,  *
54  * we also offer alternative license to integrate Nmap into proprietary    *
55  * applications and appliances.  These contracts have been sold to dozens  *
56  * of software vendors, and generally include a perpetual license as well  *
57  * as providing for priority support and updates as well as helping to     *
58  * fund the continued development of Nmap technology.  Please email        *
59  * sales@insecure.com for further information.                             *
60  *                                                                         *
61  * As a special exception to the GPL terms, Insecure.Com LLC grants        *
62  * permission to link the code of this program with any version of the     *
63  * OpenSSL library which is distributed under a license identical to that  *
64  * listed in the included Copying.OpenSSL file, and distribute linked      *
65  * combinations including the two. You must obey the GNU GPL in all        *
66  * respects for all of the code used other than OpenSSL.  If you modify    *
67  * this file, you may extend this exception to your version of the file,   *
68  * but you are not obligated to do so.                                     *
69  *                                                                         *
70  * If you received these files with a written license agreement or         *
71  * contract stating terms other than the terms above, then that            *
72  * alternative license agreement takes precedence over these comments.     *
73  *                                                                         *
74  * Source is provided to this software because we believe users have a     *
75  * right to know exactly what a program is going to do before they run it. *
76  * This also allows you to audit the software for security holes (none     *
77  * have been found so far).                                                *
78  *                                                                         *
79  * Source code also allows you to port Nmap to new platforms, fix bugs,    *
80  * and add new features.  You are highly encouraged to send your changes   *
81  * to fyodor@insecure.org for possible incorporation into the main         *
82  * distribution.  By sending these changes to Fyodor or one the            *
83  * Insecure.Org development mailing lists, it is assumed that you are      *
84  * offering Fyodor and Insecure.Com LLC the unlimited, non-exclusive right *
85  * to reuse, modify, and relicense the code.  Nmap will always be          *
86  * available Open Source, but this is important because the inability to   *
87  * relicense code has caused devastating problems for other Free Software  *
88  * projects (such as KDE and NASM).  We also occasionally relicense the    *
89  * code to third parties as discussed above.  If you wish to specify       *
90  * special license conditions of your contributions, just say so when you  *
91  * send them.                                                              *
92  *                                                                         *
93  * This program is distributed in the hope that it will be useful, but     *
94  * WITHOUT ANY WARRANTY; without even the implied warranty of              *
95  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
96  * General Public License for more details at                              *
97  * http://www.gnu.org/copyleft/gpl.html , or in the COPYING file included  *
98  * with Nmap.                                                              *
99  *                                                                         *
100  ***************************************************************************/
101
102 /* $Id: timing.h 3869 2006-08-25 01:47:49Z fyodor $ */
103
104 #ifndef NMAP_TIMING_H
105 #define NMAP_TIMING_H
106
107 #include "tcpip.h"
108 #include "global_structures.h"
109
110 /* Call this function on a newly allocated struct timeout_info to
111    initialize the values appropriately */
112 void initialize_timeout_info(struct timeout_info *to);
113
114 /* Same as adjust_timeouts(), except this one allows you to specify
115  the receive time too (which could be because it was received a while
116  back or it could be for efficiency because the caller already knows
117  the current time */
118 void adjust_timeouts2(const struct timeval *sent, 
119                       const struct timeval *received, 
120                       struct timeout_info *to);
121
122 /* Adjust our timeout values based on the time the latest probe took for a 
123    response.  We update our RTT averages, etc. */
124 void adjust_timeouts(struct timeval sent, struct timeout_info *to);
125
126
127 /* Sleeps if necessary to ensure that it isn't called twice within less
128    time than o.send_delay.  If it is passed a non-null tv, the POST-SLEEP
129    time is recorded in it */
130 void enforce_scan_delay(struct timeval *tv);
131
132 class ScanProgressMeter {
133  public:
134   /* A COPY of stypestr is made and saved for when stats are printed */
135   ScanProgressMeter(char *stypestr);
136   ~ScanProgressMeter();
137 /* Decides whether a timing report is likely to even be
138    printed.  There are stringent limitations on how often they are
139    printed, as well as the verbosity level that must exist.  So you
140    might as well check this before spending much time computing
141    progress info.  now can be NULL if caller doesn't have the current
142    time handy.  Just because this function returns true does not mean
143    that the next printStatsIfNeccessary will always print something.
144    It depends on whether time estimates have changed, which this func
145    doesn't even know about. */
146   bool mayBePrinted(const struct timeval *now);
147
148 /* Prints an estimate of when this scan will complete.  It only does
149    so if mayBePrinted() is true, and it seems reasonable to do so
150    because the estimate has changed significantly.  Returns whether
151    or not a line was printed.*/
152   bool printStatsIfNeccessary(double perc_done, const struct timeval *now);
153
154   /* Prints an estimate of when this scan will complete. */
155   bool printStats(double perc_done, const struct timeval *now);
156
157   /* Prints that this task is complete. */
158   bool endTask(const struct timeval *now, const char *additional_info) { return beginOrEndTask(now, additional_info, false); }
159
160   struct timeval begin; /* When this ScanProgressMeter was instantiated */
161  private:
162   struct timeval last_print_test; /* Last time printStatsIfNeccessary was called */
163   struct timeval last_print; /* The most recent time the ETC was printed */
164   char *scantypestr;
165   struct timeval last_est; /* The latest PRINTED estimate */
166
167   bool beginOrEndTask(const struct timeval *now, const char *additional_info, bool beginning);
168 };
169
170 #endif /* NMAP_TIMING_H */
171