2006-11-25 14:31:52 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2007-03-11 13:59:40 +01:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2006-11-25 14:31:52 +01:00
|
|
|
#include "configfile.h"
|
|
|
|
#include "connection.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "logging.h"
|
2007-04-17 18:31:59 +02:00
|
|
|
#include "tcpsocket.h"
|
|
|
|
#include "sockaddr.h"
|
2006-11-25 14:31:52 +01:00
|
|
|
|
|
|
|
static int listen_init(const char *value, void *privdata)
|
|
|
|
{
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
|
2007-04-17 18:31:59 +02:00
|
|
|
if (parse_sockaddr(value, &addr) == -1) {
|
2006-11-25 14:31:52 +01:00
|
|
|
log_print(LOG_WARN, "invalid listen addr: '%s'", value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-04-17 18:31:59 +02:00
|
|
|
int sock = tcp_listen(&addr);
|
2006-11-25 14:31:52 +01:00
|
|
|
if (sock < 0)
|
|
|
|
return -1;
|
|
|
|
|
2007-03-11 17:23:34 +01:00
|
|
|
event_add_readfd(NULL, sock, listen_handler, privdata);
|
2006-11-25 14:31:52 +01:00
|
|
|
log_print(LOG_INFO, "listen on %s", get_sockaddr_buf(&addr));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (config_parse("telnetproxy.conf") == -1)
|
|
|
|
return -1;
|
|
|
|
|
2007-04-17 18:31:59 +02:00
|
|
|
int cnt = config_get_strings("global", "listen", listen_init, client_handler);
|
2006-11-25 14:31:52 +01:00
|
|
|
if (cnt <= 0) {
|
|
|
|
log_print(LOG_ERROR, "no listen sockets defined!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-04-17 18:31:59 +02:00
|
|
|
cnt = config_get_strings("global", "admin_listen", listen_init, admin_handler);
|
2006-12-03 20:03:16 +01:00
|
|
|
if (cnt <= 0) {
|
|
|
|
log_print(LOG_ERROR, "no admin_listen sockets defined!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-11-25 14:31:52 +01:00
|
|
|
event_loop();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|