[lib-client] Use const arguments wherever possible

This commit is contained in:
Matteo Cypriani 2011-04-05 15:41:52 +02:00
parent dc9e5a72f4
commit ed6001a05b
3 changed files with 31 additions and 19 deletions

2
TODO
View File

@ -4,7 +4,7 @@
- Use string for network exchanges? - Use string for network exchanges?
- Mark arguments as const in function headers if needed - Mark arguments as const in function headers if needed
That is done in the owlps-positioning C++ code, but not constantly 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. - Allow to use hostnames instead of IP addresses.
- Use struct ether_addr to store MAC addresses? - Use struct ether_addr to store MAC addresses?
We could use the struct ether_addr to store binary MAC addresses, We could use the struct ether_addr to store binary MAC addresses,

View File

@ -16,9 +16,10 @@
* 'iface' if specified (if you want the interface to be selected, * 'iface' if specified (if you want the interface to be selected,
* automatically, this parameter should be NULL or an empty string). * automatically, this parameter should be NULL or an empty string).
*/ */
int owlclient_create_trx_socket(char *dest_ip, uint_fast16_t dest_port, int owlclient_create_trx_socket(const char *const dest_ip,
struct sockaddr_in *server, const uint_fast16_t dest_port,
char *iface) struct sockaddr_in *const server,
const char *const iface)
{ {
struct sockaddr_in client ; 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'. */ /* 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, if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, iface,
strlen(iface) + 1) == -1) 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 owlclient_send_request(const int sockfd,
void *packet, uint_fast16_t packet_size, const struct sockaddr_in *const server,
uint_fast16_t nb_pkt, uint_fast32_t delay) 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 ; 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 owlclient_send_packet(const int sockfd,
void *packet, uint_fast16_t packet_size) 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, ssize_t nsent = sendto(sockfd, packet, packet_size, 0,
(struct sockaddr *) server, (struct sockaddr *) server,

View File

@ -14,15 +14,21 @@
/* Function headers */ /* Function headers */
int owlclient_create_trx_socket(char *dest_ip, uint_fast16_t dest_port, int owlclient_create_trx_socket(const char *const dest_ip,
struct sockaddr_in *server, const uint_fast16_t dest_port,
char *iface) ; struct sockaddr_in *const server,
void owlclient_use_iface(int sockfd, char *iface) ; const char *const iface) ;
void owlclient_send_request(int sockfd, struct sockaddr_in *server, void owlclient_use_iface(const int sockfd, const char *const iface) ;
void *packet, uint_fast16_t packet_size, void owlclient_send_request(const int sockfd,
uint_fast16_t nb_pkt, uint_fast32_t delay) ; const struct sockaddr_in *const server,
void owlclient_send_packet(int sockfd, struct sockaddr_in *server, const void *const packet,
void *packet, uint_fast16_t packet_size) ; 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_ #endif // _LIBOWLPS_CLIENT_