summaryrefslogtreecommitdiff
path: root/src/tcpproxy.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-12-03 01:40:38 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-12-03 01:40:38 +0000
commite499866cde13bb04b65e4aaac4f229cd8811f7f4 (patch)
treee0a18657f6bb8b74398ec43f7bbadb949f4724c0 /src/tcpproxy.c
parentremoved useless source address resolving type option (diff)
added config file parser
git-svn-id: https://svn.spreadspace.org/tcpproxy/trunk@24 e61f0598-a718-4e21-a8f0-0aadfa62ad6b
Diffstat (limited to 'src/tcpproxy.c')
-rw-r--r--src/tcpproxy.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/tcpproxy.c b/src/tcpproxy.c
index 149fdf0..ef71cb4 100644
--- a/src/tcpproxy.c
+++ b/src/tcpproxy.c
@@ -40,6 +40,11 @@
#include "listener.h"
#include "clients.h"
+extern FILE *yyin;
+extern void yyinit(options_t* opt, listeners_t* listeners);
+extern int yyparse(void);
+
+
int main_loop(options_t* opt, listeners_t* listeners)
{
log_printf(INFO, "entering main loop");
@@ -145,12 +150,27 @@ int main(int argc, char* argv[])
log_close();
exit(-1);
}
- ret = listener_add(&listeners, opt.local_addr_, opt.lresolv_type_, opt.local_port_, opt.remote_addr_, opt.rresolv_type_, opt.remote_port_, opt.source_addr_);
- if(ret) {
- listener_clear(&listeners);
- options_clear(&opt);
- log_close();
- exit(-1);
+
+ if(opt.local_port_) {
+ ret = listener_add(&listeners, opt.local_addr_, opt.lresolv_type_, opt.local_port_, opt.remote_addr_, opt.rresolv_type_, opt.remote_port_, opt.source_addr_);
+ if(ret) {
+ listener_clear(&listeners);
+ options_clear(&opt);
+ log_close();
+ exit(-1);
+ }
+ } else {
+ yyin = fopen(opt.config_file_, "r");
+ if(!yyin) {
+ log_printf(ERROR, "can't open config file %s: %s", opt.config_file_, strerror(errno));
+ listener_clear(&listeners);
+ options_clear(&opt);
+ log_close();
+ exit(-1);
+ }
+
+ yyinit(&opt, &listeners);
+ yyparse();
}
priv_info_t priv;