diff options
author | Rohan Joyce <rojoyce.github@gmail.com> | 2015-02-13 18:26:01 +0800 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-02-16 11:20:18 +0100 |
commit | 6f891f6c0c9ca68658491fe3b959613809309027 (patch) | |
tree | b0a8b5a03fba2b80729a06d1dde413084cac5e7b /lib/addr.c | |
parent | e75a1c373ad447ddf376b77f36c8e4ef039de3b5 (diff) | |
download | libnl-6f891f6c0c9ca68658491fe3b959613809309027.tar.gz |
lib: add const-ness to appropriate parameters in addr, attr, data
This patch changes the signatures of some functions to allow const pointers in
places where a const qualified pointer is enough access for what the function
does (e.g. nla_get_u8). It also changes some functions that take a pointer
parameter and return a pointer derived from it to use the strchr idiom.
This is not exhaustive in terms of places where const can be added, but it's
a decent chunk that should not make the external api any more restrictive.
http://lists.infradead.org/pipermail/libnl/2015-February/001826.html
Signed-off-by: Rohan Joyce <rojoyce.github@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'lib/addr.c')
-rw-r--r-- | lib/addr.c | 40 |
1 files changed, 20 insertions, 20 deletions
@@ -65,7 +65,7 @@ static inline int do_digit(char *str, uint16_t *addr, uint16_t scale, return 0; } -static const char *dnet_ntop(char *addrbuf, size_t addrlen, char *str, +static const char *dnet_ntop(const char *addrbuf, size_t addrlen, char *str, size_t len) { uint16_t addr = dn_ntohs(*(uint16_t *)addrbuf); @@ -213,7 +213,7 @@ struct nl_addr *nl_addr_alloc(size_t maxsize) * * @return Allocated address object or NULL upon failure. */ -struct nl_addr *nl_addr_build(int family, void *buf, size_t size) +struct nl_addr *nl_addr_build(int family, const void *buf, size_t size) { struct nl_addr *addr; @@ -252,7 +252,7 @@ struct nl_addr *nl_addr_build(int family, void *buf, size_t size) * * @return Allocated address object or NULL upon failure. */ -struct nl_addr *nl_addr_alloc_attr(struct nlattr *nla, int family) +struct nl_addr *nl_addr_alloc_attr(const struct nlattr *nla, int family) { return nl_addr_build(family, nla_data(nla), nla_len(nla)); } @@ -468,7 +468,7 @@ errout: * * @return Allocated abstract address or NULL upon failure. */ -struct nl_addr *nl_addr_clone(struct nl_addr *addr) +struct nl_addr *nl_addr_clone(const struct nl_addr *addr) { struct nl_addr *new; @@ -531,7 +531,7 @@ void nl_addr_put(struct nl_addr *addr) * * @return Non-zero if the abstract address is shared, otherwise 0. */ -int nl_addr_shared(struct nl_addr *addr) +int nl_addr_shared(const struct nl_addr *addr) { return addr->a_refcnt > 1; } @@ -560,7 +560,7 @@ int nl_addr_shared(struct nl_addr *addr) * @return Integer less than, equal to or greather than zero if the two * addresses match. */ -int nl_addr_cmp(struct nl_addr *a, struct nl_addr *b) +int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b) { int d = a->a_family - b->a_family; @@ -591,7 +591,7 @@ int nl_addr_cmp(struct nl_addr *a, struct nl_addr *b) * @return Integer less than, equal to or greather than zero if the two * addresses match. */ -int nl_addr_cmp_prefix(struct nl_addr *a, struct nl_addr *b) +int nl_addr_cmp_prefix(const struct nl_addr *a, const struct nl_addr *b) { int d = a->a_family - b->a_family; @@ -617,7 +617,7 @@ int nl_addr_cmp_prefix(struct nl_addr *a, struct nl_addr *b) * * @return 1 if the binary address consists of all zeros, 0 otherwise. */ -int nl_addr_iszero(struct nl_addr *addr) +int nl_addr_iszero(const struct nl_addr *addr) { unsigned int i; @@ -636,7 +636,7 @@ int nl_addr_iszero(struct nl_addr *addr) * @return 1 if the address is parseable assuming the specified address family, * otherwise 0 is returned. */ -int nl_addr_valid(char *addr, int family) +int nl_addr_valid(const char *addr, int family) { int ret; char buf[32]; @@ -670,7 +670,7 @@ int nl_addr_valid(char *addr, int family) * * @return Numeric address family or AF_UNSPEC */ -int nl_addr_guess_family(struct nl_addr *addr) +int nl_addr_guess_family(const struct nl_addr *addr) { switch (addr->a_len) { case 4: @@ -697,7 +697,7 @@ int nl_addr_guess_family(struct nl_addr *addr) * * @return 0 on success or a negative error code */ -int nl_addr_fill_sockaddr(struct nl_addr *addr, struct sockaddr *sa, +int nl_addr_fill_sockaddr(const struct nl_addr *addr, struct sockaddr *sa, socklen_t *salen) { switch (addr->a_family) { @@ -753,7 +753,7 @@ int nl_addr_fill_sockaddr(struct nl_addr *addr, struct sockaddr *sa, * * @return 0 on success or a negative error code. */ -int nl_addr_info(struct nl_addr *addr, struct addrinfo **result) +int nl_addr_info(const struct nl_addr *addr, struct addrinfo **result) { int err; char buf[INET6_ADDRSTRLEN+5]; @@ -797,7 +797,7 @@ int nl_addr_info(struct nl_addr *addr, struct addrinfo **result) * * @return 0 on success or a negative error code. */ -int nl_addr_resolve(struct nl_addr *addr, char *host, size_t hostlen) +int nl_addr_resolve(const struct nl_addr *addr, char *host, size_t hostlen) { int err; struct sockaddr_in6 buf; @@ -842,7 +842,7 @@ void nl_addr_set_family(struct nl_addr *addr, int family) * * @return The numeric address family or `AF_UNSPEC` */ -int nl_addr_get_family(struct nl_addr *addr) +int nl_addr_get_family(const struct nl_addr *addr) { return addr->a_family; } @@ -867,7 +867,7 @@ int nl_addr_get_family(struct nl_addr *addr) * * @return 0 on success or a negative error code. */ -int nl_addr_set_binary_addr(struct nl_addr *addr, void *buf, size_t len) +int nl_addr_set_binary_addr(struct nl_addr *addr, const void *buf, size_t len) { if (len > addr->a_maxsize) return -NLE_RANGE; @@ -890,9 +890,9 @@ int nl_addr_set_binary_addr(struct nl_addr *addr, void *buf, size_t len) * * @return Pointer to binary address of length nl_addr_get_len() */ -void *nl_addr_get_binary_addr(struct nl_addr *addr) +void *nl_addr_get_binary_addr(const struct nl_addr *addr) { - return addr->a_addr; + return (void*)addr->a_addr; } /** @@ -902,7 +902,7 @@ void *nl_addr_get_binary_addr(struct nl_addr *addr) * @see nl_addr_get_binary_addr() * @see nl_addr_set_binary_addr() */ -unsigned int nl_addr_get_len(struct nl_addr *addr) +unsigned int nl_addr_get_len(const struct nl_addr *addr) { return addr->a_len; } @@ -925,7 +925,7 @@ void nl_addr_set_prefixlen(struct nl_addr *addr, int prefixlen) * * @see nl_addr_set_prefixlen() */ -unsigned int nl_addr_get_prefixlen(struct nl_addr *addr) +unsigned int nl_addr_get_prefixlen(const struct nl_addr *addr) { return addr->a_prefixlen; } @@ -948,7 +948,7 @@ unsigned int nl_addr_get_prefixlen(struct nl_addr *addr) * * @return Address represented in ASCII stored in destination buffer. */ -char *nl_addr2str(struct nl_addr *addr, char *buf, size_t size) +char *nl_addr2str(const struct nl_addr *addr, char *buf, size_t size) { unsigned int i; char tmp[16]; |