+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* 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;
unsigned int nr_connections;
/** client fdset */
fd_set fdset;
- fd_set testfds;
/** specific operation options*/
int flags;
};
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)) {
#endif
*epointd = fwp_epoint;
- return 0;
+ return fwp_epoint->sockd;
err:
fwp_endpoint_destroy(fwp_epoint);
return -1;
}
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);
&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;
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;
&peer.addrlen);
if (csockd < 0) {
- perror("Error on accept\n");
+ FWP_ERROR("Error on accept: %s\n", strerror(errno));
return errno;
}
*
*/
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;
{
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;
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,
/* 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;
+ }
}
}
* 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;