1 /*
2  * Packit -- network injection and capture tool
3  *
4  * Original author: Darren Bounds <dbounds@intrusense.com>
5  *
6  * Copyright 2002-2004 Darren Bounds <dbounds@intrusense.com>
7  * Copyright 2013      Mats Erik Andersson <gnu@gisladisker.se>
8  * Copyright 2015-2021 Joao Eriberto Mota Filho <eriberto@eriberto.pro.br>
9  * Copyright 2020      David Polverari <david.polverari@gmail.com>
10  *
11  * SPDX-License-Identifier: GPL-2.0-or-later
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  * MA  02110-1301, USA.
27  *
28  * packit official page at https://github.com/resurrecting-open-source-projects/packit
29  */
30 
31 #include "../config.h"
32 #include "usage.h"
33 
34 void
print_usage()35 print_usage()
36 {
37     fprintf(stdout, "usage: packit -m mode [-options] 'expression'\n\n");
38 
39     fprintf(stdout, "Mode:\n");
40     fprintf(stdout, "  -m mode     Runtime mode ");
41 
42 #ifdef WITH_INJECTION
43     fprintf(stdout, "(Default: injection)\n");
44 #else
45 #ifdef WITH_CAPTURE
46     fprintf(stdout, "(Default: capture)\n");
47 #else
48     fprintf(stdout, "(Default: none)\n");
49 #endif /* WITH_CAPTURE */
50 #endif /* WITH_INJECTION */
51 
52     fprintf(stdout, "\n");
53 
54 #ifdef WITH_CAPTURE
55     fprintf(stdout, "Packet capture:\n");
56     fprintf(stdout, "  -c count    Number of packets to process\n");
57     fprintf(stdout, "  -e          Display link-level data\n");
58     fprintf(stdout, "  -G          Display time in GMT\n");
59     fprintf(stdout, "  -i device   Select listening interface\n");
60     fprintf(stdout, "  -n          Disable IP/host resolution\n");
61     fprintf(stdout, "  -nn         Disable port/service resolution\n");
62     fprintf(stdout, "  -nnn        Disable IP/host and port/service resolution\n");
63     fprintf(stdout, "  -r file     Read data from file\n");
64     fprintf(stdout, "  -s snaplen  Bytes of data to read from each packet (Default: 68)\n");
65     fprintf(stdout, "  -v          Verbose packet capture\n");
66     fprintf(stdout, "  -w file     Write data to file\n");
67     fprintf(stdout, "  -X          Dump the packet in hex and ascii\n");
68     fprintf(stdout, "\n");
69 #endif /* WITH_CAPTURE */
70 
71 #ifdef WITH_INJECTION
72     fprintf(stdout, "Packet injection:\n");
73     fprintf(stdout, "  -t proto    Select protocol for injection (Default: TCP) \n");
74     fprintf(stdout, "\n");
75 
76     fprintf(stdout, "TCP/UDP header options\n");
77     fprintf(stdout, "  -a ack      Acknowledgement number\n");
78     fprintf(stdout, "  -D port     Destination port (Range format: start-end)\n");
79     fprintf(stdout, "  -F flags    Flags (format: -F UAPRSF)\n");
80     fprintf(stdout, "  -q seq      Sequence number\n");
81     fprintf(stdout, "  -S port     Source port (Default: Random)\n");
82     fprintf(stdout, "  -u urg      Urgent pointer\n");
83     fprintf(stdout, "  -W size     Window size (Default: 65535)\n");
84     fprintf(stdout, "\n");
85 
86     fprintf(stdout, "ICMPv4 header options\n");
87     fprintf(stdout, "  General:\n");
88     fprintf(stdout, "  -C code     Code (Default: 0)\n");
89     fprintf(stdout, "  -K type     Type (Default: 8)\n");
90     fprintf(stdout, "\n");
91 
92     fprintf(stdout, "  Echo(0) / Echo Reply(8):\n");
93     fprintf(stdout, "  -N id       ID number\n");
94     fprintf(stdout, "  -Q seq      Sequence number\n");
95     fprintf(stdout, "\n");
96 
97     fprintf(stdout, "  Unreachable(3) / Redirect(5) / Time Exceeded(11):\n");
98     fprintf(stdout, "  -g gateway  Redirect gateway host (ICMP Redirect only)\n");
99     fprintf(stdout, "  -j address  Original source address\n");
100     fprintf(stdout, "  -J port     Original source port\n");
101     fprintf(stdout, "  -l address  Original destination address\n");
102     fprintf(stdout, "  -L port     Original destination port\n");
103     fprintf(stdout, "  -m ttl      Original time to live\n");
104     fprintf(stdout, "  -M id       Original ID number\n");
105     fprintf(stdout, "  -O tos      Original type of service\n");
106     fprintf(stdout, "  -P proto    Original protocol (Default: UDP)\n");
107     fprintf(stdout, "\n");
108 
109     fprintf(stdout, "  Mask Request(17) / Mask Reply(18):\n");
110     fprintf(stdout, "  -N id       ID number\n");
111     fprintf(stdout, "  -Q seq      Sequence number\n");
112     fprintf(stdout, "  -G mask     Address mask\n");
113     fprintf(stdout, "\n");
114 
115     fprintf(stdout, "  Timestamp Request(13) / Timestamp Reply(14):\n");
116     fprintf(stdout, "  -N id       ID number\n");
117     fprintf(stdout, "  -Q seq      Sequence number\n");
118     fprintf(stdout, "  -U ts       Original timestamp\n");
119     fprintf(stdout, "  -k ts       Received timestamp\n");
120     fprintf(stdout, "  -z ts       Transmit timestamp\n");
121     fprintf(stdout, "\n");
122 
123     fprintf(stdout, "IP header options\n");
124     fprintf(stdout, "  -d address  Destination address\n");
125     fprintf(stdout, "  -f          Don't fragment\n");
126     fprintf(stdout, "  -n id       ID number\n");
127     fprintf(stdout, "  -o tos      Type of service\n");
128     fprintf(stdout, "  -s address  Source address\n");
129     fprintf(stdout, "  -T ttl      Time to live (Default: 128)\n");
130     fprintf(stdout, "  -V ipproto  IP protocol number (RAWIP only)\n");
131     fprintf(stdout, "\n");
132 
133 #ifndef MACOS
134     fprintf(stdout, "ARP and RARP header options\n");
135     fprintf(stdout, "  -A op       Operation type (Default: 1 (ARP request)\n");
136     fprintf(stdout, "              and 3 (Reverse ARP request))\n");
137     fprintf(stdout, "  -x address  Source protocol address\n");
138     fprintf(stdout, "  -X hwaddr   Source hardware address\n");
139     fprintf(stdout, "  -y address  Destination protocol address\n");
140     fprintf(stdout, "  -Y hwaddr   Destination hardware address\n");
141     fprintf(stdout, "\n");
142 
143     fprintf(stdout, "Ethernet header options\n");
144     fprintf(stdout, "  -e ethaddr  Source ethernet address\n");
145     fprintf(stdout, "  -E ethaddr  Destination ethernet address\n");
146     fprintf(stdout, "\n");
147 #endif /* MACOS */
148 
149     fprintf(stdout, "General options\n");
150     fprintf(stdout, "  -b burst    Send 'burst' packets per interval (Default: 1)\n");
151     fprintf(stdout, "  -c count    Number of packets to inject (Default: 1)\n");
152     fprintf(stdout, "  -h          Display remote host response (Inject mode only)\n");
153     fprintf(stdout, "  -H seconds  Specify the timeout value for '-h' (Default: 1, Max: 255)\n");
154     fprintf(stdout, "  -i device   Select injection interface\n");
155     fprintf(stdout, "  -I tci      Specify 802.1Q TCI (VLAN ID/CFI/prio combination) EXPERIMENTAL\n");
156     fprintf(stdout, "  -p payload  Payload (Hex payload is prefixed with '0x ')\n");
157     fprintf(stdout, "  -R          Disable IP/host resolution\n");
158     fprintf(stdout, "  -v          Verbose packet injection\n");
159     fprintf(stdout, "  -w seconds  Interval between injecting each burst (Default: 1)\n");
160     fprintf(stdout, "  -Z length   Specify the size of the packet to inject (Overrides the -p option)\n");
161     fprintf(stdout, "\n");
162 #endif /* WITH_INJECTION */
163 
164     fprintf(stdout, "Version: %s\n", VERSION);
165 //    fprintf(stdout, "Author:  %s\n", P_AUTHOR);
166     fprintf(stdout, "Website: https://github.com/resurrecting-open-source-projects/packit\n");
167     fprintf(stdout, "\nSee the man page for more options, detailed descriptions and examples.\n\n");
168 }
169