[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?
- 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,

View File

@ -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,

View File

@ -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_