aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-05-21 00:16:09 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-05-21 00:16:09 +0200
commite736194f56ffb9f082cde5084abacaa66cc08aa7 (patch)
tree9c03b2b934a5db8c077381a10db7cdfa05cd4071
parentd4c41cc1c9195d5843d3ff1519636f4519e33fa9 (diff)
downloaddns-e736194f56ffb9f082cde5084abacaa66cc08aa7.tar.gz
arguments
-rw-r--r--src/main.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index bb1a4ac..3c7f0b8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,23 +14,67 @@
#include "test.h"
#endif
+void print_help( char *_argv0 ) {
+ printf(
+ "dns\n"
+ "Usage: %s [OPTIONS]\n\n"
+ "Options:\n"
+ " -h Display this help text\n"
+ " -i IP IP to bind to, default: 0.0.0.0\n"
+ " -p PORT Port to listen, default: 53 on\n"
+ " -z FILE Zonefile\n", _argv0
+ );
+}
+
+void parse_args( server_config_t *_config, int argc, char* argv[]) {
+ memset( _config, 0, sizeof( server_config_t ) );
+
+ _config->bind_ip = "0.0.0.0";
+ _config->bind_port = 53;
+ _config->zonefile = "/nofile";
+
+ for( int i = 1; i < argc; i++ ) {
+ const int icpy = i;
+ if ( argv[i][0] != '-' ) {
+ print_help( argv[0] );
+ exit( 1 );
+ }
+
+ for( int o = 1; o < strlen(argv[icpy]); o++ ) {
+ switch( argv[icpy][o] ) {
+ case 'h':
+ print_help( argv[0] );
+ exit( 0 );
+ case 'i':
+ _config->bind_ip = argv[++i];
+ break;
+ case 'p':
+ _config->bind_port = atoi( argv[++i] );
+ break;
+ case 'z':
+ _config->zonefile = argv[++i];
+ break;
+ default:
+ printf( "Unkown option \"%c\"\n", argv[icpy][o] );
+ print_help( argv[0] );
+ exit( 1 );
+ }
+ }
+ }
+}
+
int main(int argc, char* argv[])
{
+ server_config_t config;
+ parse_args( &config, argc, argv );
+
log_init_stdout(_LOG_DEBUG);
- //CMD line arg parsing goes in here
+
#ifdef _TEST
run_test();
#else
- server_config_t config;
-
- memset(&config, 0, sizeof config);
-
- config.bind_ip = "0.0.0.0";
- config.bind_port = 53;
- config.zonefile = "/nofile";
-
server_start( &config );
#endif
-
+ return 0;
}