1 2 /*************************************************************************** 3 * targets.h -- Functions relating to "ping scanning" as well as * 4 * determining the exact IPs to hit based on CIDR and other input formats. * 5 * * 6 ***********************IMPORTANT NMAP LICENSE TERMS************************ 7 * * 8 * The Nmap Security Scanner is (C) 1996-2020 Insecure.Com LLC ("The Nmap * 9 * Project"). Nmap is also a registered trademark of the Nmap Project. * 10 * * 11 * This program is distributed under the terms of the Nmap Public Source * 12 * License (NPSL). The exact license text applying to a particular Nmap * 13 * release or source code control revision is contained in the LICENSE * 14 * file distributed with that version of Nmap or source code control * 15 * revision. More Nmap copyright/legal information is available from * 16 * https://nmap.org/book/man-legal.html, and further information on the * 17 * NPSL license itself can be found at https://nmap.org/npsl. This header * 18 * summarizes some key points from the Nmap license, but is no substitute * 19 * for the actual license text. * 20 * * 21 * Nmap is generally free for end users to download and use themselves, * 22 * including commercial use. It is available from https://nmap.org. * 23 * * 24 * The Nmap license generally prohibits companies from using and * 25 * redistributing Nmap in commercial products, but we sell a special Nmap * 26 * OEM Edition with a more permissive license and special features for * 27 * this purpose. See https://nmap.org/oem * 28 * * 29 * If you have received a written Nmap license agreement or contract * 30 * stating terms other than these (such as an Nmap OEM license), you may * 31 * choose to use and redistribute Nmap under those terms instead. * 32 * * 33 * The official Nmap Windows builds include the Npcap software * 34 * (https://npcap.org) for packet capture and transmission. It is under * 35 * separate license terms which forbid redistribution without special * 36 * permission. So the official Nmap Windows builds may not be * 37 * redistributed without special permission (such as an Nmap OEM * 38 * license). * 39 * * 40 * Source is provided to this software because we believe users have a * 41 * right to know exactly what a program is going to do before they run it. * 42 * This also allows you to audit the software for security holes. * 43 * * 44 * Source code also allows you to port Nmap to new platforms, fix bugs, * 45 * and add new features. You are highly encouraged to submit your * 46 * changes as a Github PR or by email to the dev@nmap.org mailing list * 47 * for possible incorporation into the main distribution. Unless you * 48 * specify otherwise, it is understood that you are offering us very * 49 * broad rights to use your submissions as described in the Nmap Public * 50 * Source License Contributor Agreement. This is important because we * 51 * fund the project by selling licenses with various terms, and also * 52 * because the inability to relicense code has caused devastating * 53 * problems for other Free Software projects (such as KDE and NASM). * 54 * * 55 * The free version of Nmap is distributed in the hope that it will be * 56 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * 57 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Warranties, * 58 * indemnification and commercial support are all available through the * 59 * Npcap OEM program--see https://nmap.org/oem. * 60 * * 61 ***************************************************************************/ 62 63 /* $Id: targets.h 38078 2020-10-02 16:12:22Z dmiller $ */ 64 65 #ifndef TARGETS_H 66 #define TARGETS_H 67 68 #include "TargetGroup.h" 69 #include <list> 70 #include <nbase.h> 71 class Target; 72 73 class HostGroupState { 74 public: 75 /* The maximum number of entries we want to allow storing in defer_buffer. */ 76 static const unsigned int DEFER_LIMIT = 64; 77 78 HostGroupState(int lookahead, int randomize, int argc, const char *argv[]); 79 ~HostGroupState(); 80 Target **hostbatch; 81 82 /* The defer_buffer is a place to store targets that have previously been 83 returned but that can't be used right now. They wait in defer_buffer until 84 HostGroupState::undefer is called, at which point they all move to the end 85 of the undeferred list. HostGroupState::next_target always pulls from the 86 undeferred list before returning anything new. */ 87 std::list<Target *> defer_buffer; 88 std::list<Target *> undeferred; 89 90 int argc; 91 const char **argv; 92 int max_batch_sz; /* The size of the hostbatch[] array */ 93 int current_batch_sz; /* The number of VALID members of hostbatch[] */ 94 int next_batch_no; /* The index of the next hostbatch[] member to be given 95 back to the user */ 96 int randomize; /* Whether each batch should be "shuffled" prior to the ping 97 scan (they will also be out of order when given back one 98 at a time to the client program */ 99 TargetGroup current_group; /* For batch chunking -- targets in queue */ 100 101 /* Returns true iff the defer buffer is not yet full. */ 102 bool defer(Target *t); 103 void undefer(); 104 const char *next_expression(); 105 Target *next_target(); 106 }; 107 108 /* ports is used to pass information about what ports to use for host discovery */ 109 Target *nexthost(HostGroupState *hs,const struct addrset *exclude_group, 110 struct scan_lists *ports, int pingtype); 111 int load_exclude_file(struct addrset *exclude_group, FILE *fp); 112 int load_exclude_string(struct addrset *exclude_group, const char *s); 113 /* a debugging routine to dump an exclude list to stdout. */ 114 int dumpExclude(struct addrset *exclude_group); 115 /* Returns the last host obtained by nexthost. It will be given again the next 116 time you call nexthost(). */ 117 void returnhost(HostGroupState *hs); 118 119 120 bool target_needs_new_hostgroup(Target **targets, int targets_sz, const Target *target); 121 122 #endif /* TARGETS_H */ 123 124