add winpcap 4.0.2 from url http://www.winpcap.org/
[natblaster.git] / src / helper / natblaster_helper.c
blobc692e6bd48f9d3a0eb78e331ba5b8e4a40084b32
1 /*****************************************************************************
2 * Copyright 2005 Daniel Ferullo *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 *****************************************************************************/
18 /**
19 * @file natblaster_helper.c
20 * @author Daniel Ferullo (ferullo@cmu.edu)
22 * @brief contains entrypoint for a helper into natblaster
25 #include "natblaster_helper.h"
27 #include "connlist.h"
28 #include "debug.h"
29 #include "errorcodes.h"
30 #include "berkeleyapi.h"
31 #include "nethelp.h"
32 #include "helpercon.h"
34 int natblaster_server(port_t listen_port) {
36 sock_t listen_sd;
37 connlist_t list;
38 observed_data_t data;
39 sock_t this_sd;
40 struct sockaddr_in peer_con;
41 int peer_con_size;
43 /* The return type is "int" and the return codes are "errorcodes". Even
44 * though there aren't strictly the same type, I know they are, and using
45 * the errorcodes makes the code more readable and debug-able. */
47 CHECK_FAILED(bindSocket(listen_port,&listen_sd),ERROR_BIND);
49 /* initalize the list for connection information */
50 CHECK_FAILED(connlist_init(&list),ERROR_INIT);
52 if (listen(listen_sd,5)!=0)
53 return ERROR_TCP_LISTEN;
55 peer_con_size = sizeof(peer_con);
56 /* loop forever */
57 while (1) {
58 this_sd = accept(listen_sd,(struct sockaddr*)&peer_con,
59 &peer_con_size);
60 data.ip = peer_con.sin_addr.s_addr;
61 data.port = peer_con.sin_port;
62 DEBUG(DBG_NETWORK,"NETWORK:recieved a connection!\n");
63 DEBUG(DBG_LIST, "LIST:list size: %d\n",
64 connlist_count(&list));
65 CHECK_FAILED(create_new_handler(&list,&data,this_sd),ERROR_1);
69 /* should never happen */
70 return ERROR_1;