comparison src/common.c @ 38:d9f5caa13898

Added support for NetBSD, added command line parsing to provide configuration options
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 06 May 2013 22:53:20 +0200
parents 1fe62a94c28a
children 47a34fe75c57
comparison
equal deleted inserted replaced
37:bb4bbf380938 38:d9f5caa13898
82 extern int debug; 82 extern int debug;
83 #else 83 #else
84 84
85 char* (*getconf)(const char*) = getenv; 85 char* (*getconf)(const char*) = getenv;
86 int debug = 0; 86 int debug = 0;
87 static int gargc = 0;
88 static char** gargv = NULL;
87 89
88 int errorexit(const char* text) { 90 int errorexit(const char* text) {
89 fprintf(stderr, "%s\n", text); 91 fprintf(stderr, "%s\n", text);
90 return -1; 92 return -1;
91 } 93 }
93 perror(text); 95 perror(text);
94 return -1; 96 return -1;
95 } 97 }
96 98
97 void print_header() { 99 void print_header() {
98 fprintf(stderr, "UCIS QuickTun (c) 2010 Ivo Smits <Ivo@UCIS.nl>\n"); 100 fprintf(stderr, "UCIS QuickTun "QT_VERSION" (c) 2010-2013 Ivo Smits <Ivo@UCIS.nl>\n");
99 fprintf(stderr, "More information: http://wiki.ucis.nl/QuickTun\n"); 101 fprintf(stderr, "More information: http://wiki.ucis.nl/QuickTun\n");
100 } 102 }
101 103
102 int init_udp(struct qtsession* session) { 104 int init_udp(struct qtsession* session) {
103 char* envval; 105 char* envval;
310 } 312 }
311 } 313 }
312 } 314 }
313 return 0; 315 return 0;
314 } 316 }
315 #endif 317
316 318 char* getconfcmdargs(const char* name) {
319 int i;
320 for (i = 1; i < gargc - 2; i++) {
321 if (strcmp(gargv[i], "-c")) continue;
322 if (strcmp(gargv[i + 1], name)) continue;
323 return gargv[i + 2];
324 }
325 return NULL;
326 }
327
328 int qtprocessargs(int argc, char** argv) {
329 int i;
330 for (i = 1; i < argc; i++) {
331 char* a = argv[i];
332 if (!strcmp(a, "-h") || !strcmp(a, "--help")) {
333 return errorexit("Please read the documentation at http://wiki.ucis.nl/QuickTun");
334 } else if (!strcmp(a, "-v") || !strcmp(a, "--version")) {
335 return errorexit("UCIS QuickTun "QT_VERSION);
336 } else if (!strcmp(a, "-c")) {
337 gargc = argc;
338 gargv = argv;
339 getconf = getconfcmdargs;
340 i += 2;
341 } else {
342 return errorexit("Unexpected command line argument");
343 }
344 }
345 }
346 #endif
347