2 /***************************************************************************
3 * Target.h -- The Target class encapsulates much of the information Nmap *
4 * has about a host. Results (such as ping, OS scan, etc) are stored in *
5 * this class as they are determined. *
7 ***********************IMPORTANT NMAP LICENSE TERMS************************
9 * The Nmap Security Scanner is (C) 1996-2006 Insecure.Com LLC. Nmap is *
10 * also a registered trademark of Insecure.Com LLC. This program is free *
11 * software; you may redistribute and/or modify it under the terms of the *
12 * GNU General Public License as published by the Free Software *
13 * Foundation; Version 2 with the clarifications and exceptions described *
14 * below. This guarantees your right to use, modify, and redistribute *
15 * this software under certain conditions. If you wish to embed Nmap *
16 * technology into proprietary software, we sell alternative licenses *
17 * (contact sales@insecure.com). Dozens of software vendors already *
18 * license Nmap technology such as host discovery, port scanning, OS *
19 * detection, and version detection. *
21 * Note that the GPL places important restrictions on "derived works", yet *
22 * it does not provide a detailed definition of that term. To avoid *
23 * misunderstandings, we consider an application to constitute a *
24 * "derivative work" for the purpose of this license if it does any of the *
26 * o Integrates source code from Nmap *
27 * o Reads or includes Nmap copyrighted data files, such as *
28 * nmap-os-fingerprints or nmap-service-probes. *
29 * o Executes Nmap and parses the results (as opposed to typical shell or *
30 * execution-menu apps, which simply display raw Nmap output and so are *
31 * not derivative works.) *
32 * o Integrates/includes/aggregates Nmap into a proprietary executable *
33 * installer, such as those produced by InstallShield. *
34 * o Links to a library or executes a program that does any of the above *
36 * The term "Nmap" should be taken to also include any portions or derived *
37 * works of Nmap. This list is not exclusive, but is just meant to *
38 * clarify our interpretation of derived works with some common examples. *
39 * These restrictions only apply when you actually redistribute Nmap. For *
40 * example, nothing stops you from writing and selling a proprietary *
41 * front-end to Nmap. Just distribute it by itself, and point people to *
42 * http://insecure.org/nmap/ to download Nmap. *
44 * We don't consider these to be added restrictions on top of the GPL, but *
45 * just a clarification of how we interpret "derived works" as it applies *
46 * to our GPL-licensed Nmap product. This is similar to the way Linus *
47 * Torvalds has announced his interpretation of how "derived works" *
48 * applies to Linux kernel modules. Our interpretation refers only to *
49 * Nmap - we don't speak for any other GPL products. *
51 * If you have any questions about the GPL licensing restrictions on using *
52 * Nmap in non-GPL works, we would be happy to help. As mentioned above, *
53 * we also offer alternative license to integrate Nmap into proprietary *
54 * applications and appliances. These contracts have been sold to dozens *
55 * of software vendors, and generally include a perpetual license as well *
56 * as providing for priority support and updates as well as helping to *
57 * fund the continued development of Nmap technology. Please email *
58 * sales@insecure.com for further information. *
60 * As a special exception to the GPL terms, Insecure.Com LLC grants *
61 * permission to link the code of this program with any version of the *
62 * OpenSSL library which is distributed under a license identical to that *
63 * listed in the included Copying.OpenSSL file, and distribute linked *
64 * combinations including the two. You must obey the GNU GPL in all *
65 * respects for all of the code used other than OpenSSL. If you modify *
66 * this file, you may extend this exception to your version of the file, *
67 * but you are not obligated to do so. *
69 * If you received these files with a written license agreement or *
70 * contract stating terms other than the terms above, then that *
71 * alternative license agreement takes precedence over these comments. *
73 * Source is provided to this software because we believe users have a *
74 * right to know exactly what a program is going to do before they run it. *
75 * This also allows you to audit the software for security holes (none *
76 * have been found so far). *
78 * Source code also allows you to port Nmap to new platforms, fix bugs, *
79 * and add new features. You are highly encouraged to send your changes *
80 * to fyodor@insecure.org for possible incorporation into the main *
81 * distribution. By sending these changes to Fyodor or one the *
82 * Insecure.Org development mailing lists, it is assumed that you are *
83 * offering Fyodor and Insecure.Com LLC the unlimited, non-exclusive right *
84 * to reuse, modify, and relicense the code. Nmap will always be *
85 * available Open Source, but this is important because the inability to *
86 * relicense code has caused devastating problems for other Free Software *
87 * projects (such as KDE and NASM). We also occasionally relicense the *
88 * code to third parties as discussed above. If you wish to specify *
89 * special license conditions of your contributions, just say so when you *
92 * This program is distributed in the hope that it will be useful, but *
93 * WITHOUT ANY WARRANTY; without even the implied warranty of *
94 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
95 * General Public License for more details at *
96 * http://www.gnu.org/copyleft/gpl.html , or in the COPYING file included *
99 ***************************************************************************/
101 /* $Id: Target.h 3869 2006-08-25 01:47:49Z fyodor $ */
107 #include "FingerPrintResults.h"
109 struct host_timeout_nfo {
110 unsigned long msecs_used; /* How many msecs has this Target used? */
111 bool toclock_running; /* Is the clock running right now? */
112 struct timeval toclock_start; /* When did the clock start? */
116 public: /* For now ... a lot of the data members should be made private */
119 /* Recycles the object by freeing internal objects and reinitializing
122 /* Fills a sockaddr_storage with the AF_INET or AF_INET6 address
123 information of the target. This is a preferred way to get the
124 address since it is portable for IPv6 hosts. Returns 0 for
125 success. ss_len must be provided. It is not examined, but is set
126 to the size of the sockaddr copied in. */
127 int TargetSockAddr(struct sockaddr_storage *ss, size_t *ss_len);
128 /* Note that it is OK to pass in a sockaddr_in or sockaddr_in6 casted
129 to sockaddr_storage */
130 void setTargetSockAddr(struct sockaddr_storage *ss, size_t ss_len);
131 // Returns IPv4 target host address or {0} if unavailable.
132 struct in_addr v4host();
133 const struct in_addr *v4hostip();
134 /* The source address used to reach the target */
135 int SourceSockAddr(struct sockaddr_storage *ss, size_t *ss_len);
136 /* Note that it is OK to pass in a sockaddr_in or sockaddr_in6 casted
137 to sockaddr_storage */
138 void setSourceSockAddr(struct sockaddr_storage *ss, size_t ss_len);
139 struct in_addr v4source();
140 const struct in_addr *v4sourceip();
141 /* The IPv4 or IPv6 literal string for the target host */
142 const char *targetipstr() { return targetipstring; }
143 /* Give the name from the last setHostName() call, which should be
144 the name obtained from reverse-resolution (PTR query) of the IP (v4
145 or v6). If the name has not been set, or was set to NULL, an empty
146 string ("") is returned to make printing easier. */
147 const char *HostName() { return hostname? hostname : ""; }
148 /* You can set to NULL to erase a name or if it failed to resolve -- or
149 just don't call this if it fails to resolve. The hostname is blown
150 away when you setTargetSockAddr(), so make sure you do these in proper
153 void setHostName(char *name);
154 /* Generates a printable string consisting of the host's IP
155 address and hostname (if available). Eg "www.insecure.org
156 (64.71.184.53)" or "fe80::202:e3ff:fe14:1102". The name is
157 written into the buffer provided, which is also returned. Results
158 that do not fit in buflen will be truncated. */
159 const char *NameIP(char *buf, size_t buflen);
160 /* This next version returns a STATIC buffer -- so no concurrency */
161 const char *NameIP();
163 /* If the host is directly connected on a network, set and retrieve
164 that information here. directlyConnected() will abort if it hasn't
166 void setDirectlyConnected(bool connected);
167 bool directlyConnected();
169 /* If the host is NOT directly connected, you can set the next hop
170 value here. It is OK to pass in a sockaddr_in or sockaddr_in6
171 casted to sockaddr_storage*/
172 void setNextHop(struct sockaddr_storage *next_hop, size_t next_hop_len);
173 /* Returns the next hop for sending packets to this host. Returns true if
174 next_hop was filled in. It might be false, for example, if
175 next_hop has never been set */
176 bool nextHop(struct sockaddr_storage *next_hop, size_t *next_hop_len);
178 /* Sets the interface type to one of:
179 devt_ethernet, devt_loopback, devt_p2p, devt_other
181 void setIfType(devtype iftype) { interface_type = iftype; }
182 /* Returns -1 if it has not yet been set with setIfType() */
183 devtype ifType() { return interface_type; }
184 /* Starts the timeout clock for the host running (e.g. you are
185 beginning a scan). If you do not have the current time handy,
186 you can pass in NULL. When done, call stopTimeOutClock (it will
187 also automatically be stopped of timedOut() returns true) */
188 void startTimeOutClock(const struct timeval *now);
189 /* The complement to startTimeOutClock. */
190 void stopTimeOutClock(const struct timeval *now);
191 /* Is the timeout clock currently running? */
192 bool timeOutClockRunning() { return htn.toclock_running; }
193 /* Returns whether the host is timedout. If the timeoutclock is
194 running, counts elapsed time for that. Pass NULL if you don't have the
195 current time handy. You might as well also pass NULL if the
196 clock is not running, as the func won't need the time. */
197 bool timedOut(const struct timeval *now);
199 /* Takes a 6-byte MAC address */
200 int setMACAddress(const u8 *addy);
201 int setSrcMACAddress(const u8 *addy);
202 int setNextHopMACAddress(const u8 *addy); // this should be the target's own MAC if directlyConnected()
204 /* Returns a pointer to 6-byte MAC address, or NULL if none is set */
205 const u8 *MACAddress();
206 const u8 *SrcMACAddress();
207 const u8 *NextHopMACAddress();
209 /* Set the device names so that they can be returned by deviceName()
210 and deviceFullName(). The normal name may not include alias
211 qualifier, while the full name may include it (e.g. "eth1:1"). If
212 these are non-null, they will overwrite the stored version */
213 void setDeviceNames(const char *name, const char *fullname);
214 const char *deviceName() { return *devname? devname : NULL; }
215 const char *deviceFullName() { return *devfullname? devfullname : NULL; }
219 FingerPrintResults *FPR1; /* FP results get by the old OS scan system. */
220 FingerPrintResults *FPR; /* FP results get by the new OS scan system. */
221 int osscan_performed; /* nonzero if an osscan was performed */
225 unsigned int down; */
226 int wierd_responses; /* echo responses from other addresses, Ie a network broadcast address */
227 unsigned int flags; /* HOST_UP, HOST_DOWN, HOST_FIREWALLED, HOST_BROADCAST (instead of HOST_BROADCAST use wierd_responses */
228 struct timeout_info to;
232 char *hostname; // Null if unable to resolve or unset
234 void FreeInternal(); // Free memory allocated inside this object
235 // Creates a "presentation" formatted string out of the IPv4/IPv6 address
236 void GenerateIPString();
237 struct sockaddr_storage targetsock, sourcesock, nexthopsock;
238 size_t targetsocklen, sourcesocklen, nexthopsocklen;
239 int directly_connected; // -1 = unset; 0 = no; 1 = yes
240 #ifndef INET6_ADDRSTRLEN
241 #define INET6_ADDRSTRLEN 46
243 char targetipstring[INET6_ADDRSTRLEN];
244 char *nameIPBuf; /* for the NameIP(void) function to return */
245 u8 MACaddress[6], SrcMACaddress[6], NextHopMACaddress[6];
246 bool MACaddress_set, SrcMACaddress_set, NextHopMACaddress_set;
247 struct host_timeout_nfo htn;
248 devtype interface_type;
249 char devname[32], devfullname[32];
252 #endif /* TARGET_H */