summaryrefslogtreecommitdiff
path: root/src/inet.c
diff options
context:
space:
mode:
authorGrant Erickson <marathon96@gmail.com>2011-06-10 13:54:23 (GMT)
committerSamuel Ortiz <sameo@linux.intel.com>2011-06-14 09:26:27 (GMT)
commit6996a25658098d3a2133b0388fd6c4c1de61bf4d (patch)
tree2c627364377108cffd2ecbb210d9a17dd379c708 /src/inet.c
parent17776e39bb138bfd48971826d97e4e556dffb7bd (diff)
downloadconnman-6996a25658098d3a2133b0388fd6c4c1de61bf4d.zip
connman-6996a25658098d3a2133b0388fd6c4c1de61bf4d.tar.gz
connman-6996a25658098d3a2133b0388fd6c4c1de61bf4d.tar.bz2
inet: Standardize error codes and messages
Return and pass a consistent set of informative error codes and display a consistent set of error messages for connman_inet_modify_address and connman_{clear,set}_*_address.
Diffstat (limited to 'src/inet.c')
-rw-r--r--src/inet.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/inet.c b/src/inet.c
index 12c87e7..e3adb7e 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -88,13 +88,15 @@ int __connman_inet_modify_address(int cmd, int flags,
struct in_addr ipv4_addr, ipv4_dest, ipv4_bcast;
int sk, err;
- DBG("");
+ DBG("cmd %#x flags %#x index %d family %d address %s peer %s "
+ "prefixlen %hhu broadcast %s", cmd, flags, index, family,
+ address, peer, prefixlen, broadcast);
if (address == NULL)
- return -1;
+ return -EINVAL;
if (family != AF_INET && family != AF_INET6)
- return -1;
+ return -EINVAL;
memset(&request, 0, sizeof(request));
@@ -150,7 +152,7 @@ int __connman_inet_modify_address(int cmd, int flags,
sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
if (sk < 0)
- return -1;
+ return -errno;
memset(&nl_addr, 0, sizeof(nl_addr));
nl_addr.nl_family = AF_NETLINK;
@@ -541,6 +543,7 @@ struct in6_ifreq {
int connman_inet_set_ipv6_address(int index,
struct connman_ipaddress *ipaddress)
{
+ int err;
unsigned char prefix_len;
const char *address;
@@ -552,11 +555,12 @@ int connman_inet_set_ipv6_address(int index,
DBG("index %d address %s prefix_len %d", index, address, prefix_len);
- if ((__connman_inet_modify_address(RTM_NEWADDR,
- NLM_F_REPLACE | NLM_F_ACK, index, AF_INET6,
- address, NULL, prefix_len, NULL)) < 0) {
- connman_error("Set IPv6 address error");
- return -1;
+ err = __connman_inet_modify_address(RTM_NEWADDR,
+ NLM_F_REPLACE | NLM_F_ACK, index, AF_INET6,
+ address, NULL, prefix_len, NULL);
+ if (err < 0) {
+ connman_error("%s: %s", __func__, strerror(-err));
+ return err;
}
return 0;
@@ -564,6 +568,7 @@ int connman_inet_set_ipv6_address(int index,
int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress)
{
+ int err;
unsigned char prefix_len;
const char *address, *broadcast, *peer;
@@ -577,11 +582,12 @@ int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress)
DBG("index %d address %s prefix_len %d", index, address, prefix_len);
- if ((__connman_inet_modify_address(RTM_NEWADDR,
- NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
- address, peer, prefix_len, broadcast)) < 0) {
- DBG("address setting failed");
- return -1;
+ err = __connman_inet_modify_address(RTM_NEWADDR,
+ NLM_F_REPLACE | NLM_F_ACK, index, AF_INET,
+ address, peer, prefix_len, broadcast);
+ if (err < 0) {
+ connman_error("%s: %s", __func__, strerror(-err));
+ return err;
}
return 0;
@@ -590,12 +596,15 @@ int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress)
int connman_inet_clear_ipv6_address(int index, const char *address,
int prefix_len)
{
+ int err;
+
DBG("index %d address %s prefix_len %d", index, address, prefix_len);
- if ((__connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET6,
- address, NULL, prefix_len, NULL)) < 0) {
- connman_error("Clear IPv6 address error");
- return -1;
+ err = __connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET6,
+ address, NULL, prefix_len, NULL);
+ if (err < 0) {
+ connman_error("%s: %s", __func__, strerror(-err));
+ return err;
}
return 0;
@@ -603,6 +612,7 @@ int connman_inet_clear_ipv6_address(int index, const char *address,
int connman_inet_clear_address(int index, struct connman_ipaddress *ipaddress)
{
+ int err;
unsigned char prefix_len;
const char *address, *broadcast, *peer;
@@ -613,10 +623,11 @@ int connman_inet_clear_address(int index, struct connman_ipaddress *ipaddress)
DBG("index %d address %s prefix_len %d", index, address, prefix_len);
- if ((__connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET,
- address, peer, prefix_len, broadcast)) < 0) {
- DBG("address removal failed");
- return -1;
+ err = __connman_inet_modify_address(RTM_DELADDR, 0, index, AF_INET,
+ address, peer, prefix_len, broadcast);
+ if (err < 0) {
+ connman_error("%s: %s", __func__, strerror(-err));
+ return err;
}
return 0;