00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #include "natblaster_helper.h"
00026 
00027 #include "connlist.h"
00028 #include "debug.h"
00029 #include "errorcodes.h"
00030 #include "berkeleyapi.h"
00031 #include "nethelp.h"
00032 #include "helpercon.h"
00033 
00034 int natblaster_server(port_t listen_port) {
00035 
00036         sock_t listen_sd;
00037         connlist_t list;
00038         observed_data_t data;
00039         sock_t this_sd;
00040         struct sockaddr_in peer_con;
00041         int peer_con_size;
00042 
00043         
00044 
00045 
00046 
00047         CHECK_FAILED(bindSocket(listen_port,&listen_sd),ERROR_BIND);
00048 
00049         
00050         CHECK_FAILED(connlist_init(&list),ERROR_INIT);
00051 
00052         if (listen(listen_sd,5)!=0)
00053                 return ERROR_TCP_LISTEN;
00054 
00055         peer_con_size = sizeof(peer_con);
00056         
00057         while (1) {
00058                 this_sd = accept(listen_sd,(struct sockaddr*)&peer_con,
00059                                  &peer_con_size);
00060                 data.ip   = peer_con.sin_addr.s_addr;
00061                 data.port = peer_con.sin_port;
00062                 DEBUG(DBG_NETWORK,"NETWORK:recieved a connection!\n");
00063                 DEBUG(DBG_LIST, "LIST:list size: %d\n",
00064                         connlist_count(&list));
00065                 CHECK_FAILED(create_new_handler(&list,&data,this_sd),ERROR_1);
00066 
00067         }
00068 
00069         
00070         return ERROR_1;
00071 }