File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ fakehttp -h www.example.com -i eth0
1818Usage: fakehttp [options]
1919
2020Options:
21+ -d run as daemon
2122 -h <hostname> hostname for obfuscation (required)
2223 -i <interface> network interface name (required)
2324 -m <mark> fwmark for bypassing the queue
Original file line number Diff line number Diff line change 5252static FILE * g_logfp = NULL ;
5353static int g_sockfd = 0 ;
5454static int g_exit = 0 ;
55+ static int g_daemon = 0 ;
5556static int g_silent = 0 ;
5657static int g_repeat = 3 ;
5758static uint32_t g_fwmark = 0x8000 ;
@@ -67,6 +68,7 @@ static void print_usage(const char *name)
6768 "Usage: %s [options]\n"
6869 "\n"
6970 "Options:\n"
71+ " -d run as a daemon\n"
7072 " -h <hostname> hostname for obfuscation (required)\n"
7173 " -i <interface> network interface name (required)\n"
7274 " -m <mark> fwmark for bypassing the queue\n"
@@ -712,8 +714,11 @@ int main(int argc, char *argv[])
712714 return EXIT_FAILURE ;
713715 }
714716
715- while ((opt = getopt (argc , argv , "h :i:m:n:r:st:w:x:" )) != -1 ) {
717+ while ((opt = getopt (argc , argv , "dh :i:m:n:r:st:w:x:" )) != -1 ) {
716718 switch (opt ) {
719+ case 'd' :
720+ g_daemon = 1 ;
721+ break ;
717722 case 'h' :
718723 if (strlen (optarg ) > _POSIX_HOST_NAME_MAX ) {
719724 fprintf (stderr , "%s: hostname is too long.\n" , argv [0 ]);
@@ -814,6 +819,19 @@ int main(int argc, char *argv[])
814819 return EXIT_FAILURE ;
815820 }
816821
822+ if (g_daemon ) {
823+ res = daemon (0 , 0 );
824+ if (res < 0 ) {
825+ fprintf (stderr , "%s: failed to daemonize: %s\n" , argv [0 ],
826+ strerror (errno ));
827+ return EXIT_FAILURE ;
828+ }
829+
830+ if (!g_logfp ) {
831+ g_silent = 1 ;
832+ }
833+ }
834+
817835 E ("FakeHTTP version " VERSION );
818836
819837 srand (time (NULL ));
You can’t perform that action at this time.
0 commit comments