From ed6001a05b96215f36e1f94128097fa3afa1a703 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 5 Apr 2011 15:41:52 +0200 Subject: [PATCH] [lib-client] Use const arguments wherever possible --- TODO | 2 +- libowlps-client/libowlps-client.c | 24 +++++++++++++++--------- libowlps-client/owlps-client.h | 24 +++++++++++++++--------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/TODO b/TODO index 270e4ca..2465a16 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,7 @@ - Use string for network exchanges? - Mark arguments as const in function headers if needed That is done in the owlps-positioning C++ code, but not constantly - in C modules. + in C modules. [Done in libowlps & libowlps-client.] - Allow to use hostnames instead of IP addresses. - Use struct ether_addr to store MAC addresses? We could use the struct ether_addr to store binary MAC addresses, diff --git a/libowlps-client/libowlps-client.c b/libowlps-client/libowlps-client.c index 0c4f19b..1976f5e 100644 --- a/libowlps-client/libowlps-client.c +++ b/libowlps-client/libowlps-client.c @@ -16,9 +16,10 @@ * 'iface' if specified (if you want the interface to be selected, * automatically, this parameter should be NULL or an empty string). */ -int owlclient_create_trx_socket(char *dest_ip, uint_fast16_t dest_port, - struct sockaddr_in *server, - char *iface) +int owlclient_create_trx_socket(const char *const dest_ip, + const uint_fast16_t dest_port, + struct sockaddr_in *const server, + const char *const iface) { struct sockaddr_in client ; @@ -41,7 +42,7 @@ int owlclient_create_trx_socket(char *dest_ip, uint_fast16_t dest_port, /* Selects 'iface' as sending interface for the socket 'sockfd'. */ -void owlclient_use_iface(int sockfd, char *iface) +void owlclient_use_iface(const int sockfd, const char *const iface) { if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, iface, strlen(iface) + 1) == -1) @@ -55,9 +56,12 @@ void owlclient_use_iface(int sockfd, char *iface) -void owlclient_send_request(int sockfd, struct sockaddr_in *server, - void *packet, uint_fast16_t packet_size, - uint_fast16_t nb_pkt, uint_fast32_t delay) +void owlclient_send_request(const int sockfd, + const struct sockaddr_in *const server, + const void *const packet, + const uint_fast16_t packet_size, + const uint_fast16_t nb_pkt, + const uint_fast32_t delay) { uint_fast16_t i ; @@ -82,8 +86,10 @@ void owlclient_send_request(int sockfd, struct sockaddr_in *server, -void owlclient_send_packet(int sockfd, struct sockaddr_in *server, - void *packet, uint_fast16_t packet_size) +void owlclient_send_packet(const int sockfd, + const struct sockaddr_in *const server, + const void *const packet, + const uint_fast16_t packet_size) { ssize_t nsent = sendto(sockfd, packet, packet_size, 0, (struct sockaddr *) server, diff --git a/libowlps-client/owlps-client.h b/libowlps-client/owlps-client.h index 1cc6c20..b005d78 100644 --- a/libowlps-client/owlps-client.h +++ b/libowlps-client/owlps-client.h @@ -14,15 +14,21 @@ /* Function headers */ -int owlclient_create_trx_socket(char *dest_ip, uint_fast16_t dest_port, - struct sockaddr_in *server, - char *iface) ; -void owlclient_use_iface(int sockfd, char *iface) ; -void owlclient_send_request(int sockfd, struct sockaddr_in *server, - void *packet, uint_fast16_t packet_size, - uint_fast16_t nb_pkt, uint_fast32_t delay) ; -void owlclient_send_packet(int sockfd, struct sockaddr_in *server, - void *packet, uint_fast16_t packet_size) ; +int owlclient_create_trx_socket(const char *const dest_ip, + const uint_fast16_t dest_port, + struct sockaddr_in *const server, + const char *const iface) ; +void owlclient_use_iface(const int sockfd, const char *const iface) ; +void owlclient_send_request(const int sockfd, + const struct sockaddr_in *const server, + const void *const packet, + const uint_fast16_t packet_size, + const uint_fast16_t nb_pkt, + const uint_fast32_t delay) ; +void owlclient_send_packet(const int sockfd, + const struct sockaddr_in *const server, + const void *const packet, + const uint_fast16_t packet_size) ; #endif // _LIBOWLPS_CLIENT_