2006-11-25 14:31:52 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "configfile.h"
|
|
|
|
#include "connection.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "network.h"
|
|
|
|
|
|
|
|
static int listen_init(const char *value, void *privdata)
|
|
|
|
{
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
|
|
|
|
if (parse_saddr(value, &addr) == -1) {
|
|
|
|
log_print(LOG_WARN, "invalid listen addr: '%s'", value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-03 20:03:16 +01:00
|
|
|
int sock = tcp_listen_socket(&addr);
|
2006-11-25 14:31:52 +01:00
|
|
|
if (sock < 0)
|
|
|
|
return -1;
|
|
|
|
|
2006-12-03 20:03:16 +01:00
|
|
|
event_add_readfd(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;
|
|
|
|
|
2006-12-03 20:03:16 +01:00
|
|
|
int cnt = config_get_strings("global", "listen", listen_init, (void*)CON_NORMAL);
|
2006-11-25 14:31:52 +01:00
|
|
|
if (cnt <= 0) {
|
|
|
|
log_print(LOG_ERROR, "no listen sockets defined!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-03 20:03:16 +01:00
|
|
|
cnt = config_get_strings("global", "admin_listen", listen_init, (void*)CON_ADMIN);
|
|
|
|
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;
|
|
|
|
}
|