[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'.
This commit is contained in:
parent
2150dc1cde
commit
dcdab12c27
|
@ -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 $<
|
||||
|
||||
|
|
|
@ -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) ;
|
||||
|
|
|
@ -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_
|
||||
|
|
Loading…
Reference in New Issue