From dcdab12c271033ab083eb85c90af62e76e4d5f5d Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 3 Aug 2010 12:06:14 +0200 Subject: [PATCH] [lib-client] Fix interface, rename variables Parameter 'iface' of the function owlps_create_socket_to_aggregator() can now be NULL. Use variable name 'packet' instead of 'buf'. --- .../libowlps-client/Makefile | 3 +-- .../libowlps-client/libowlps-client.c | 23 ++++++++++++------- .../libowlps-client/owlps-client.h | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/infrastructure-centred/libowlps-client/Makefile b/infrastructure-centred/libowlps-client/Makefile index 7324083..5642a41 100644 --- a/infrastructure-centred/libowlps-client/Makefile +++ b/infrastructure-centred/libowlps-client/Makefile @@ -4,6 +4,7 @@ CC = gcc # Autres outils AR = ar RANLIB = ranlib +RM = rm -fv # Variables générales LIB_CIBLE=libowlps-client @@ -33,8 +34,6 @@ LIBS=-liw all : static static : $(STATIC) -% : %.o - $(CC) $(LDFLAGS) $(STRIPFLAGS) $(XCFLAGS) -o $@ $^ %.o : %.c $(HEADER) $(CC) $(XCFLAGS) -c $< diff --git a/infrastructure-centred/libowlps-client/libowlps-client.c b/infrastructure-centred/libowlps-client/libowlps-client.c index f79202e..e51fc43 100644 --- a/infrastructure-centred/libowlps-client/libowlps-client.c +++ b/infrastructure-centred/libowlps-client/libowlps-client.c @@ -2,7 +2,13 @@ -/* Opens an UDP socket to the aggregator. */ +/* + * Opens an UDP socket to the aggregator (whose IP address is 'dest_ip' + * and listening port is 'dest_port'). The server information is stored + * into 'server'. The socket will send through the network interface + * 'iface' if specified (if you want the interface to be selected, + * automatically, this parameter should be NULL or an empty string). + */ int owlps_create_socket_to_aggregator(char *dest_ip, int dest_port, struct sockaddr_in *server, char *iface) @@ -18,7 +24,8 @@ int owlps_create_socket_to_aggregator(char *dest_ip, int dest_port, exit(ERR_CREATING_SOCKET) ; } - if (iface[0] != '\0') // If we specified an interface name + // If we specified an interface name + if (iface != NULL && iface[0] != '\0') owlps_use_iface(sockfd, iface) ; return sockfd ; @@ -42,7 +49,7 @@ void owlps_use_iface(int sockfd, char *iface) void owlps_send_request(int sockfd, struct sockaddr_in *server, - char *buf, int buf_size, + char *packet, int packet_size, short nb_pkt, long delay) { int i ; @@ -52,13 +59,13 @@ void owlps_send_request(int sockfd, struct sockaddr_in *server, #endif // DEBUG // Transmit first packet: - owlps_send_packet(sockfd, server, buf, buf_size) ; + owlps_send_packet(sockfd, server, packet, packet_size) ; // Transmit remaining packets (if any): for (i = 0 ; i < nb_pkt - 1 ; ++i) { usleep(delay) ; // Wait during the wanted delay - owlps_send_packet(sockfd, server, buf, buf_size) ; + owlps_send_packet(sockfd, server, packet, packet_size) ; } #ifdef DEBUG @@ -69,12 +76,12 @@ void owlps_send_request(int sockfd, struct sockaddr_in *server, void owlps_send_packet(int sockfd, struct sockaddr_in *server, - char *buf, int buf_size) + char *packet, int packet_size) { - ssize_t nsent = sendto(sockfd, (void *) buf, buf_size, 0, + ssize_t nsent = sendto(sockfd, (void *) packet, packet_size, 0, (struct sockaddr *) &server, (socklen_t) sizeof(server)) ; - if (nsent != (ssize_t) buf_size) + if (nsent != (ssize_t) packet_size) { perror("Error sending data to the aggregation server") ; exit(ERR_SENDING_INFO) ; diff --git a/infrastructure-centred/libowlps-client/owlps-client.h b/infrastructure-centred/libowlps-client/owlps-client.h index 136d57e..0a4eca4 100644 --- a/infrastructure-centred/libowlps-client/owlps-client.h +++ b/infrastructure-centred/libowlps-client/owlps-client.h @@ -19,10 +19,10 @@ int owlps_create_socket_to_aggregator(char *dest_ip, int dest_port, char *iface) ; void owlps_use_iface(int sockfd, char *iface) ; void owlps_send_request(int sockfd, struct sockaddr_in *server, - char *buf, int buf_size, + char *packet, int packet_size, short nb_pkt, long delay) ; void owlps_send_packet(int sockfd, struct sockaddr_in *server, - char *buf, int buf_size) ; + char *packet, int packet_size) ; #endif // _LIBOWLPS_CLIENT_