Skip to content

Commit 9efa690

Browse files
refactor: Improve usage message
1 parent abb8a93 commit 9efa690

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,26 @@ fakehttp -h www.example.com -i eth0
1717
```
1818
Usage: fakehttp [options]
1919
20-
Options:
21-
-4 enable IPv4
22-
-6 enable IPv6
23-
-b <file> use custom tcp payload from binary file
20+
Basic Options:
21+
-h <hostname> hostname for obfuscation
22+
-i <interface> work on specified network interface
23+
24+
General Options:
25+
-4 process IPv4 connections
26+
-6 process IPv6 connections
2427
-d run as a daemon
25-
-f skip firewall rules
26-
-h <hostname> hostname for obfuscation (required)
27-
-i <interface> network interface name (required)
2828
-k kill the running process
29+
-s enable silent mode
30+
-w <file> write log to <file> instead of stderr
31+
32+
Advanced Options:
33+
-b <file> use TCP payload from binary file (ignores -h)
34+
-f skip firewall rules
35+
-g disable hop count estimation
2936
-m <mark> fwmark for bypassing the queue
3037
-n <number> netfilter queue number
3138
-r <repeat> duplicate generated packets for <repeat> times
32-
-s enable silent mode
3339
-t <ttl> TTL for generated packets
34-
-w <file> write log to <file> instead of stderr
3540
-x <mask> set the mask for fwmark
3641
-z use iptables commands instead of nft
3742

src/mainfun.c

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,45 @@
4040
#include "rawsend.h"
4141
#include "signals.h"
4242

43+
#ifndef PROGNAME
44+
#define PROGNAME "fakehttp"
45+
#endif /* PROGNAME */
46+
4347
#ifndef VERSION
4448
#define VERSION "dev"
4549
#endif /* VERSION */
4650

4751
static void print_usage(const char *name)
4852
{
49-
fprintf(stderr,
50-
"Usage: %s [options]\n"
51-
"\n"
52-
"Options:\n"
53-
" -4 enable IPv4\n"
54-
" -6 enable IPv6\n"
55-
" -b use custom tcp payload from binary file\n"
56-
" -d run as a daemon\n"
57-
" -f skip firewall rules\n"
58-
" -g disable hop count estimation\n"
59-
" -h <hostname> hostname for obfuscation (required)\n"
60-
" -i <interface> network interface name (required)\n"
61-
" -k kill the running process\n"
62-
" -m <mark> fwmark for bypassing the queue\n"
63-
" -n <number> netfilter queue number\n"
64-
" -r <repeat> duplicate generated packets for <repeat> "
65-
"times\n"
66-
" -s enable silent mode\n"
67-
" -t <ttl> TTL for generated packets\n"
68-
" -w <file> write log to <file> instead of stderr\n"
69-
" -x <mask> set the mask for fwmark\n"
70-
" -z use iptables commands instead of nft\n"
71-
"\n"
72-
"FakeHTTP version " VERSION "\n",
73-
name);
53+
static const char *usage_fmt =
54+
"Usage: %s [options]\n"
55+
"\n"
56+
"Basic Options:\n"
57+
" -h <hostname> hostname for obfuscation\n"
58+
" -i <interface> work on specified network interface\n"
59+
"\n"
60+
"General Options:\n"
61+
" -4 process IPv4 connections\n"
62+
" -6 process IPv6 connections\n"
63+
" -d run as a daemon\n"
64+
" -k kill the running process\n"
65+
" -s enable silent mode\n"
66+
" -w <file> write log to <file> instead of stderr\n"
67+
"\n"
68+
"Advanced Options:\n"
69+
" -b <file> use TCP payload from binary file (ignores -h)\n"
70+
" -f skip firewall rules\n"
71+
" -g disable hop count estimation\n"
72+
" -m <mark> fwmark for bypassing the queue\n"
73+
" -n <number> netfilter queue number\n"
74+
" -r <repeat> duplicate generated packets for <repeat> times\n"
75+
" -t <ttl> TTL for generated packets\n"
76+
" -x <mask> set the mask for fwmark\n"
77+
" -z use iptables commands instead of nft\n"
78+
"\n"
79+
"FakeHTTP version " VERSION "\n";
80+
81+
fprintf(stderr, usage_fmt, name);
7482
}
7583

7684

@@ -81,6 +89,10 @@ int main(int argc, char *argv[])
8189
char *ipproto_info;
8290

8391
if (!argc || !argv[0]) {
92+
print_usage(PROGNAME);
93+
return EXIT_FAILURE;
94+
} else if (argc == 1) {
95+
print_usage(argv[0]);
8496
return EXIT_FAILURE;
8597
}
8698

0 commit comments

Comments
 (0)