Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

natblaster_helper.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright 2005 Daniel Ferullo                                             *
00003  *                                                                           *
00004  * Licensed under the Apache License, Version 2.0 (the "License");           *
00005  * you may not use this file except in compliance with the License.          *
00006  * You may obtain a copy of the License at                                   *
00007  *                                                                           *
00008  *    http://www.apache.org/licenses/LICENSE-2.0                             *
00009  *                                                                           *
00010  * Unless required by applicable law or agreed to in writing, software       *
00011  * distributed under the License is distributed on an "AS IS" BASIS,         *
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
00013  * See the License for the specific language governing permissions and       *
00014  * limitations under the License.                                            *
00015  *                                                                           *
00016  *****************************************************************************/
00017 
00018 /**
00019  * @file natblaster_helper.c
00020  * @author Daniel Ferullo (ferullo@cmu.edu)
00021  *
00022  * @brief contains entrypoint for a helper into natblaster
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         /* The return type is "int" and the return codes are "errorcodes".  Even
00044          * though there aren't strictly the same type, I know they are, and using
00045          * the errorcodes makes the code more readable and debug-able. */
00046 
00047         CHECK_FAILED(bindSocket(listen_port,&listen_sd),ERROR_BIND);
00048 
00049         /* initalize the list for connection information */
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         /* loop forever */
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         /* should never happen */
00070         return ERROR_1;
00071 }

Generated on Wed Mar 30 23:20:47 2005 for NATBLASTER by  doxygen 1.3.9.1