]> rtime.felk.cvut.cz Git - frescor/fwp.git/blobdiff - fwp/lib/fwp/fwp_endpoint.c
Remove unused flags parameter of fwp_send()
[frescor/fwp.git] / fwp / lib / fwp / fwp_endpoint.c
index 008e669ab093fa0eb8bb89162013e682d054926f..8418b5388bb755570be893660c21e6422db13d70 100644 (file)
@@ -1,8 +1,58 @@
+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                */
+/*                                                                       */
+/*   Universidad de Cantabria,              SPAIN                        */
+/*   University of York,                    UK                           */
+/*   Scuola Superiore Sant'Anna,            ITALY                        */
+/*   Kaiserslautern University,             GERMANY                      */
+/*   Univ. Politécnica  Valencia,           SPAIN                       */
+/*   Czech Technical University in Prague,  CZECH REPUBLIC               */
+/*   ENEA                                   SWEDEN                       */
+/*   Thales Communication S.A.              FRANCE                       */
+/*   Visual Tools S.A.                      SPAIN                        */
+/*   Rapita Systems Ltd                     UK                           */
+/*   Evidence                               ITALY                        */
+/*                                                                       */
+/*   See http://www.frescor.org for a link to partners' websites         */
+/*                                                                       */
+/*          FRESCOR project (FP6/2005/IST/5-034026) is funded            */
+/*       in part by the European Union Sixth Framework Programme         */
+/*       The European Union is not liable of any use that may be         */
+/*       made of this code.                                              */
+/*                                                                       */
+/*                                                                       */
+/*  This file is part of FWP (Frescor WLAN Protocol)                     */
+/*                                                                       */
+/* FWP is free software; you can redistribute it and/or modify it        */
+/* under terms of the GNU General Public License as published by the     */
+/* Free Software Foundation; either version 2, or (at your option) any   */
+/* later version.  FWP is distributed in the hope that it will be        */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty   */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   */
+/* General Public License for more details. You should have received a   */
+/* copy of the GNU General Public License along with FWP; see file       */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
+/* Cambridge, MA 02139, USA.                                             */
+/*                                                                       */
+/* As a special exception, including FWP header files in a file,         */
+/* instantiating FWP generics or templates, or linking other files       */
+/* with FWP objects to produce an executable application, does not       */
+/* by itself cause the resulting executable application to be covered    */
+/* by the GNU General Public License. This exception does not            */
+/* however invalidate any other reasons why the executable file might be  */
+/* covered by the GNU Public License.                                    */
+/**************************************************************************/
 #include "fwp_endpoint.h"
 #include "fwp_msgb.h"
 #include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include "fwp_utils.h"
 
 #include <pthread.h>
+#include "fwp_debug.h"
 
 typedef unsigned int fwp_endpoint_id_t;
 
@@ -43,7 +93,6 @@ struct fwp_endpoint{
        unsigned int            nr_connections;
        /** client fdset */
        fd_set                  fdset;
-       fd_set                  testfds;
        /** specific operation options*/
        int                     flags;  
 };
@@ -197,7 +246,7 @@ int fwp_send_endpoint_create(unsigned int node,
        
        FWP_DEBUG("FWP Send endpoint created.\n"); 
 
-#ifndef FWP_WITH_CONTNEGT
+#ifdef FWP_WITHOUT_CONTNEGT
        /* Create vres with default parameters */
        FWP_DEBUG("Creating default vres\n");
        if (fwp_vres_create(&fwp_vres_params_default, &fwp_epoint->vresd)) {
@@ -208,7 +257,7 @@ int fwp_send_endpoint_create(unsigned int node,
 #endif
        
        *epointd = fwp_epoint;
-       return 0;               
+       return fwp_epoint->sockd;               
 err:
        fwp_endpoint_destroy(fwp_epoint);
        return -1;      
@@ -273,14 +322,13 @@ int fwp_receive_endpoint_create(unsigned int port,
                }
                
                if (listen(fwp_epoint->sockd, fwp_epoint->attr.max_connections)){
-                       perror("Error on listen call\n");
+                       FWP_ERROR("Error on listen call: %s\n", strerror(errno));
                        goto err;
                }
                
                FD_ZERO(&fwp_epoint->fdset);
                /*add listen socket */
                FD_SET(fwp_epoint->sockd, &fwp_epoint->fdset); 
-               fwp_epoint->testfds = fwp_epoint->fdset;
                fwp_epoint->c_sockd = 
                                (int*)malloc(fwp_epoint->attr.max_connections);
                bzero(fwp_epoint->c_sockd, fwp_epoint->attr.max_connections);
@@ -320,6 +368,7 @@ int fwp_receive_endpoint_create(unsigned int port,
                        &fwp_epoint->peer.addrlen);
 
        addr = (struct sockaddr_in*) fwp_epoint->peer.addr;
+       fwp_epoint->port = ntohs(addr->sin_port);
        FWP_DEBUG("Recv port= %d\n",ntohs(addr->sin_port));     
        *epointd = fwp_epoint;  
        return 0;
@@ -339,7 +388,7 @@ err:
 int fwp_send_endpoint_bind(fwp_endpoint_d_t epointd, fwp_vres_d_t vresd)
 {
        int rv = 0;
-#ifdef FWP_WITH_CONTNEGT
+#ifndef FWP_WITHOUT_CONTNEGT
        fwp_endpoint_t *fwp_epoint = epointd;
        
        fwp_epoint->vresd = vresd;      
@@ -394,7 +443,7 @@ static int fwp_receive_endpoint_accept(fwp_endpoint_t *fwp_epoint)
                        &peer.addrlen);
        
        if (csockd < 0) {
-               perror("Error on accept\n");
+               FWP_ERROR("Error on accept: %s\n", strerror(errno));
                return errno;   
        }               
 
@@ -423,7 +472,7 @@ static int fwp_receive_endpoint_accept(fwp_endpoint_t *fwp_epoint)
  *
  */
 int fwp_recv_conn(fwp_endpoint_d_t epointd, void *buffer, 
-                               size_t buffer_size)
+                       size_t buffer_size)
 {
        fwp_endpoint_t *fwp_epoint = epointd;
        fwp_sockaddr_t *peer = &fwp_epoint->peer;
@@ -478,6 +527,7 @@ ssize_t fwp_recv(fwp_endpoint_d_t epointd,
 {
        fwp_endpoint_t *fwp_epoint = epointd;
        fwp_sockaddr_t *peer = &fwp_epoint->peer;
+       struct sockaddr_in *addr = (struct sockaddr_in*) fwp_epoint->peer.addr;
        ssize_t len;
        fd_set fdset;
        
@@ -489,11 +539,12 @@ ssize_t fwp_recv(fwp_endpoint_d_t epointd,
        if (fwp_epoint->attr.reliability == FWP_EPOINT_BESTEFFORT) {    
                len = _fwp_recvfrom(fwp_epoint->sockd, buffer, 
                                        buffer_size, 0, peer);
+               
+               *from = addr->sin_addr.s_addr;
                return len;
        }
        
        while (1){
-       /* FIXME: What about using a loop here and continue instead of goto???? */
                /* FWP_EPOINT_RELIABLE */
                fdset = fwp_epoint->fdset;
                if (select(FD_SETSIZE, &fdset, (fd_set *)0, 
@@ -510,8 +561,10 @@ ssize_t fwp_recv(fwp_endpoint_d_t epointd,
 
                /* Check client TCP sockets */
                len = fwp_recv_conn(fwp_epoint, buffer, buffer_size);
-               if (len)
+               if (len) {
+                       *from = addr->sin_addr.s_addr;
                        return len;
+               }
        }
 }
 
@@ -527,8 +580,7 @@ ssize_t fwp_recv(fwp_endpoint_d_t epointd,
  * On error, -1 is returned and errno is set appropriately.
  *
  */
-int fwp_send(fwp_endpoint_d_t epointd,const void *msg, const size_t size, 
-               int flags)
+int fwp_send(fwp_endpoint_d_t epointd,const void *msg, const size_t size)
 {
        fwp_endpoint_t *fwp_epoint = epointd;
        struct fwp_msgb *msgb;