IP to Geo

IP to Geo Commit Details

Date:2016-02-04 20:39:50 (4 years 5 months ago)
Author:Grégory Soutadé
Branch:master
Commit:148a2a81c83975863050d6587ee2c582e4825e7e
Parents: feb89ff6b38db812f55a9fc4c57e4f827b9485f2
Message:Add -B option to doesn't go in background

Changes:
Msrc/cmdline.c (12 diffs)
Msrc/cmdline.ggo (1 diff)
Msrc/cmdline.h (4 diffs)
Msrc/server.c (1 diff)

File differences

src/cmdline.c
11
2
2
33
44
55
......
2929
3030
3131
32
33
3432
3533
3634
......
4442
4543
4644
45
4746
48
47
4948
50
49
5150
5251
5352
......
8180
8281
8382
83
8484
8585
8686
......
9999
100100
101101
102
102103
103104
104105
......
121122
122123
123124
124
125
126
125
126
127
128
127129
128130
129131
......
133135
134136
135137
136
137
138
139138
140139
141140
......
261260
262261
263262
263
264
264265
265266
266267
......
491492
492493
493494
494
495
495496
496497
497498
......
529530
530531
531532
533
532534
533535
534536
535537
536538
537539
538
540
539541
540542
541543
......
616618
617619
618620
621
622
623
624
625
626
627
628
629
630
619631
620632
621633
......
670682
671683
672684
673
685
674686
675687
676688
/*
File autogenerated by gengetopt version 2.22.6
File autogenerated by gengetopt version 2.22.5
generated with the following command:
gengetopt --input cmdline.ggo
const char *gengetopt_args_info_usage = "Usage: ip_to_geo --ip <ipv4>|--daemon [--port <port>] [--bind-ip <ip>]";
const char *gengetopt_args_info_versiontext = "";
const char *gengetopt_args_info_description = "Convert an IP to country code. Currently, onyl IPv4 supported";
const char *gengetopt_args_info_help[] = {
" -D, --daemon Daemonize (default=off)",
" -p, --port=INT Port (default=`53333')",
" -b, --bind-ip=STRING IP to bind to",
" -B, --no-background Don't go to background for daemon mode \n (default=off)",
"\nAdvanced daemon options:",
" -s, --sockets-per-thread=INT Number of sockets managed by a single thread\n (default=`10')",
" -s, --sockets-per-thread=INT Number of sockets managed by a single thread \n (default=`10')",
" -t, --sockets-timeout=INT Close connection after X seconds (default=`5')",
" -r, --client-max-requests=INT Number of requests allowed for one client\n (default=`100')",
" -r, --client-max-requests=INT Number of requests allowed for one client \n (default=`100')",
0
};
args_info->daemon_given = 0 ;
args_info->port_given = 0 ;
args_info->bind_ip_given = 0 ;
args_info->no_background_given = 0 ;
args_info->sockets_per_thread_given = 0 ;
args_info->sockets_timeout_given = 0 ;
args_info->client_max_requests_given = 0 ;
args_info->port_orig = NULL;
args_info->bind_ip_arg = NULL;
args_info->bind_ip_orig = NULL;
args_info->no_background_flag = 0;
args_info->sockets_per_thread_arg = 10;
args_info->sockets_per_thread_orig = NULL;
args_info->sockets_timeout_arg = 5;
args_info->daemon_help = gengetopt_args_info_help[7] ;
args_info->port_help = gengetopt_args_info_help[8] ;
args_info->bind_ip_help = gengetopt_args_info_help[9] ;
args_info->sockets_per_thread_help = gengetopt_args_info_help[11] ;
args_info->sockets_timeout_help = gengetopt_args_info_help[12] ;
args_info->client_max_requests_help = gengetopt_args_info_help[13] ;
args_info->no_background_help = gengetopt_args_info_help[10] ;
args_info->sockets_per_thread_help = gengetopt_args_info_help[12] ;
args_info->sockets_timeout_help = gengetopt_args_info_help[13] ;
args_info->client_max_requests_help = gengetopt_args_info_help[14] ;
}
printf ("%s %s\n",
(strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
CMDLINE_PARSER_VERSION);
if (strlen(gengetopt_args_info_versiontext) > 0)
printf("\n%s\n", gengetopt_args_info_versiontext);
}
static void print_help_common(void) {
write_into_file(outfile, "port", args_info->port_orig, 0);
if (args_info->bind_ip_given)
write_into_file(outfile, "bind-ip", args_info->bind_ip_orig, 0);
if (args_info->no_background_given)
write_into_file(outfile, "no-background", 0, 0 );
if (args_info->sockets_per_thread_given)
write_into_file(outfile, "sockets-per-thread", args_info->sockets_per_thread_orig, 0);
if (args_info->sockets_timeout_given)
{
int c;/* Character of the parsed option. */
int error_occurred = 0;
int error = 0;
struct gengetopt_args_info local_args_info;
int override;
{ "daemon",0, NULL, 'D' },
{ "port",1, NULL, 'p' },
{ "bind-ip",1, NULL, 'b' },
{ "no-background",0, NULL, 'B' },
{ "sockets-per-thread",1, NULL, 's' },
{ "sockets-timeout",1, NULL, 't' },
{ "client-max-requests",1, NULL, 'r' },
{ 0, 0, 0, 0 }
};
c = getopt_long (argc, argv, "hVi:qvDp:b:s:t:r:", long_options, &option_index);
c = getopt_long (argc, argv, "hVi:qvDp:b:Bs:t:r:", long_options, &option_index);
if (c == -1) break;/* Exit from `while (1)' loop. */
additional_error))
goto failure;
break;
case 'B':/* Don't go to background for daemon mode. */
if (update_arg((void *)&(args_info->no_background_flag), 0, &(args_info->no_background_given),
&(local_args_info.no_background_given), optarg, 0, 0, ARG_FLAG,
check_ambiguity, override, 1, 0, "no-background", 'B',
additional_error))
goto failure;
break;
case 's':/* Number of sockets managed by a single thread. */
cmdline_parser_release (&local_args_info);
if ( error_occurred )
if ( error )
return (EXIT_FAILURE);
return 0;
src/cmdline.ggo
1212
1313
1414
15
1516
1617
1718
option "daemon" D "Daemonize" flag off
option "port" p "Port" default="53333" int optional
option "bind-ip" b "IP to bind to" string optional
option "no-background" B "Don't go to background for daemon mode" flag off
section "Advanced daemon options"
option "sockets-per-thread" s "Number of sockets managed by a single thread" default="10" int optional
option "sockets-timeout" t "Close connection after X seconds" default="5" int optional
src/cmdline.h
11
22
3
3
44
55
66
......
5454
5555
5656
57
58
5759
5860
5961
......
7274
7375
7476
77
7578
7679
7780
......
9295
9396
9497
95
96
9798
9899
99100
/** @file cmdline.h
* @brief The header file for the command line option parser
* generated by GNU Gengetopt version 2.22.6
* generated by GNU Gengetopt version 2.22.5
* http://www.gnu.org/software/gengetopt.
* DO NOT modify this file, since it can be overwritten
* @author GNU Gengetopt by Lorenzo Bettini */
char * bind_ip_arg;/**< @brief IP to bind to. */
char * bind_ip_orig;/**< @brief IP to bind to original value given at command line. */
const char *bind_ip_help; /**< @brief IP to bind to help description. */
int no_background_flag;/**< @brief Don't go to background for daemon mode (default=off). */
const char *no_background_help; /**< @brief Don't go to background for daemon mode help description. */
int sockets_per_thread_arg;/**< @brief Number of sockets managed by a single thread (default='10'). */
char * sockets_per_thread_orig;/**< @brief Number of sockets managed by a single thread original value given at command line. */
const char *sockets_per_thread_help; /**< @brief Number of sockets managed by a single thread help description. */
unsigned int daemon_given ;/**< @brief Whether daemon was given. */
unsigned int port_given ;/**< @brief Whether port was given. */
unsigned int bind_ip_given ;/**< @brief Whether bind-ip was given. */
unsigned int no_background_given ;/**< @brief Whether no-background was given. */
unsigned int sockets_per_thread_given ;/**< @brief Whether sockets-per-thread was given. */
unsigned int sockets_timeout_given ;/**< @brief Whether sockets-timeout was given. */
unsigned int client_max_requests_given ;/**< @brief Whether client-max-requests was given. */
extern const char *gengetopt_args_info_purpose;
/** @brief the usage string of the program */
extern const char *gengetopt_args_info_usage;
/** @brief the description string of the program */
extern const char *gengetopt_args_info_description;
/** @brief all the lines making the help output */
extern const char *gengetopt_args_info_help[];
src/server.c
375375
376376
377377
378
379
378
380379
381
382
383
380
381
382
383
384
385
386
384387
385388
386389
return -3;
}
ret = daemon(0, 0);
if (ret)
if (!params->no_background_flag)
{
if (!params->quiet_flag)
fprintf(stderr, "Daemon error (%m)\n");
return -4;
ret = daemon(0, 0);
if (ret)
{
if (!params->quiet_flag)
fprintf(stderr, "Daemon error (%m)\n");
return -4;
}
}
openlog("ip_to_geod", 0, LOG_DAEMON);

Archive Download the corresponding diff file

Branches

Tags