2 /***************************************************************************
3 * output.c -- Handles the Nmap output system. This currently involves *
4 * console-style human readable output, XML output, Script |<iddi3 *
5 * output, and the legacy greppable output (used to be called "machine *
6 * readable"). I expect that future output forms (such as HTML) may be *
7 * created by a different program, library, or script using the XML *
10 ***********************IMPORTANT NMAP LICENSE TERMS************************
12 * The Nmap Security Scanner is (C) 1996-2006 Insecure.Com LLC. Nmap is *
13 * also a registered trademark of Insecure.Com LLC. This program is free *
14 * software; you may redistribute and/or modify it under the terms of the *
15 * GNU General Public License as published by the Free Software *
16 * Foundation; Version 2 with the clarifications and exceptions described *
17 * below. This guarantees your right to use, modify, and redistribute *
18 * this software under certain conditions. If you wish to embed Nmap *
19 * technology into proprietary software, we sell alternative licenses *
20 * (contact sales@insecure.com). Dozens of software vendors already *
21 * license Nmap technology such as host discovery, port scanning, OS *
22 * detection, and version detection. *
24 * Note that the GPL places important restrictions on "derived works", yet *
25 * it does not provide a detailed definition of that term. To avoid *
26 * misunderstandings, we consider an application to constitute a *
27 * "derivative work" for the purpose of this license if it does any of the *
29 * o Integrates source code from Nmap *
30 * o Reads or includes Nmap copyrighted data files, such as *
31 * nmap-os-fingerprints or nmap-service-probes. *
32 * o Executes Nmap and parses the results (as opposed to typical shell or *
33 * execution-menu apps, which simply display raw Nmap output and so are *
34 * not derivative works.) *
35 * o Integrates/includes/aggregates Nmap into a proprietary executable *
36 * installer, such as those produced by InstallShield. *
37 * o Links to a library or executes a program that does any of the above *
39 * The term "Nmap" should be taken to also include any portions or derived *
40 * works of Nmap. This list is not exclusive, but is just meant to *
41 * clarify our interpretation of derived works with some common examples. *
42 * These restrictions only apply when you actually redistribute Nmap. For *
43 * example, nothing stops you from writing and selling a proprietary *
44 * front-end to Nmap. Just distribute it by itself, and point people to *
45 * http://insecure.org/nmap/ to download Nmap. *
47 * We don't consider these to be added restrictions on top of the GPL, but *
48 * just a clarification of how we interpret "derived works" as it applies *
49 * to our GPL-licensed Nmap product. This is similar to the way Linus *
50 * Torvalds has announced his interpretation of how "derived works" *
51 * applies to Linux kernel modules. Our interpretation refers only to *
52 * Nmap - we don't speak for any other GPL products. *
54 * If you have any questions about the GPL licensing restrictions on using *
55 * Nmap in non-GPL works, we would be happy to help. As mentioned above, *
56 * we also offer alternative license to integrate Nmap into proprietary *
57 * applications and appliances. These contracts have been sold to dozens *
58 * of software vendors, and generally include a perpetual license as well *
59 * as providing for priority support and updates as well as helping to *
60 * fund the continued development of Nmap technology. Please email *
61 * sales@insecure.com for further information. *
63 * As a special exception to the GPL terms, Insecure.Com LLC grants *
64 * permission to link the code of this program with any version of the *
65 * OpenSSL library which is distributed under a license identical to that *
66 * listed in the included Copying.OpenSSL file, and distribute linked *
67 * combinations including the two. You must obey the GNU GPL in all *
68 * respects for all of the code used other than OpenSSL. If you modify *
69 * this file, you may extend this exception to your version of the file, *
70 * but you are not obligated to do so. *
72 * If you received these files with a written license agreement or *
73 * contract stating terms other than the terms above, then that *
74 * alternative license agreement takes precedence over these comments. *
76 * Source is provided to this software because we believe users have a *
77 * right to know exactly what a program is going to do before they run it. *
78 * This also allows you to audit the software for security holes (none *
79 * have been found so far). *
81 * Source code also allows you to port Nmap to new platforms, fix bugs, *
82 * and add new features. You are highly encouraged to send your changes *
83 * to fyodor@insecure.org for possible incorporation into the main *
84 * distribution. By sending these changes to Fyodor or one the *
85 * Insecure.Org development mailing lists, it is assumed that you are *
86 * offering Fyodor and Insecure.Com LLC the unlimited, non-exclusive right *
87 * to reuse, modify, and relicense the code. Nmap will always be *
88 * available Open Source, but this is important because the inability to *
89 * relicense code has caused devastating problems for other Free Software *
90 * projects (such as KDE and NASM). We also occasionally relicense the *
91 * code to third parties as discussed above. If you wish to specify *
92 * special license conditions of your contributions, just say so when you *
95 * This program is distributed in the hope that it will be useful, but *
96 * WITHOUT ANY WARRANTY; without even the implied warranty of *
97 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
98 * General Public License for more details at *
99 * http://www.gnu.org/copyleft/gpl.html , or in the COPYING file included *
102 ***************************************************************************/
104 /* $Id: output.h 3896 2006-08-29 04:03:03Z fyodor $ */
109 #define LOG_NUM_FILES 4 /* # of values that actual files (they must come first */
110 #define LOG_FILE_MASK 15 /* The mask for log typs in the file array */
112 #define LOG_MACHINE 2
115 #define LOG_STDOUT 1024
116 #define LOG_STDERR 2048
117 #define LOG_SKID_NOXLT 4096
118 #define LOG_MAX LOG_SKID_NOXLT /* The maximum log type value */
120 #define LOG_NAMES {"normal", "machine", "$Cr!pT |<!dd!3", "XML"}
122 #include "portlist.h"
124 #include "global_structures.h"
126 /* Prints the familiar Nmap tabular output showing the "interesting"
127 ports found on the machine. It also handles the Machine/Greppable
128 output and the XML output. It is pretty ugly -- in particular I
129 should write helper functions to handle the table creation */
130 void printportoutput(Target *currenths, PortList *plist);
132 /* Prints the MAC address if one was found for the target (generally
133 this means that the target is directly connected on an ethernet
134 network. This only prints to human output -- XML is handled by a
135 separate call ( print_MAC_XML_Info ) because it needs to be printed
136 in a certain place to conform to DTD. */
137 void printmacinfo(Target *currenths);
139 /* Write some information (printf style args) to the given log stream(s).
140 Remember to watch out for format string bugs. */
141 void log_write(int logt, const char *fmt, ...)
142 __attribute__ ((format (printf, 2, 3)));
144 /* This is the workhorse of the logging functions. Usually it is
145 called through log_write(), but it can be called directly if you
146 are dealing with a vfprintf-style va_list. Unlike log_write, YOU
147 CAN ONLY CALL THIS WITH ONE LOG TYPE (not a bitmask full of them).
148 In addition, YOU MUST SANDWHICH EACH EXECUTION IF THIS CALL BETWEEN
149 va_start() AND va_end() calls. */
150 void log_vwrite(int logt, const char *fmt, va_list ap);
152 /* Close the given log stream(s) */
153 void log_close(int logt);
155 /* Flush the given log stream(s). In other words, all buffered output
156 is written to the log immediately */
157 void log_flush(int logt);
159 /* Flush every single log stream -- all buffered output is written to the
160 corresponding logs immediately */
161 void log_flush_all();
163 /* Open a log descriptor of the type given to the filename given. If
164 append is nonzero, the file will be appended instead of clobbered if
165 it already exists. If the file does not exist, it will be created */
166 int log_open(int logt, int append, char *filename);
168 /* Output the list of ports scanned to the top of machine parseable
169 logs (in a comment, unfortunately). The items in ports should be
170 in sequential order for space savings and easier to read output */
171 void output_ports_to_machine_parseable_output(struct scan_lists *ports,
172 int tcpscan, int udpscan,
175 /* Similar to output_ports_to_machine_parseable_output, this function
176 outputs the XML version, which is scaninfo records of each scan
177 requested and the ports which it will scan for */
178 void output_xml_scaninfo_records(struct scan_lists *ports);
180 /* Writes host status info to the log streams (including STDOUT). An
181 example is "Host: 10.11.12.13 (foo.bar.example.com)\tStatus: Up\n" to
182 machine log. resolve_all should be passed nonzero if the user asked
183 for all hosts (even down ones) to be resolved */
184 void write_host_status(Target *currenths, int resolve_all);
186 /* Prints the formatted OS Scan output to stdout, logfiles, etc (but only
187 if an OS Scan was performed */
188 void printosscanoutput(Target *currenths);
190 /* Prints the alternate hostname/OS/device information we got from the
191 service scan (if it was performed) */
192 void printserviceinfooutput(Target *currenths);
194 /* Print a detailed list of Nmap interfaces and routes to
195 normal/skiddy/stdout output */
196 int print_iflist(void);
198 /* Prints a status message while the program is running */
199 void printStatusMessage();
201 /* Prints the statistics and other information that goes at the very end
203 void printfinaloutput();
205 char* xml_convert (const char* str);
206 #endif /* OUTPUT_H */