summaryrefslogtreecommitdiff
path: root/libnetutils/ifc_utils.c
diff options
context:
space:
mode:
authorSteven Laver <lavers@google.com>2019-12-12 15:29:36 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-12-12 15:29:36 +0000
commita239544c7b06814b70fd970de7eaac234682fa52 (patch)
treea4298d61f9b73642f350799b1157e49b65f4e1e8 /libnetutils/ifc_utils.c
parent63de1e1c8d7824c241f22de67edf54f4f1eaeea5 (diff)
parent5319412e5305a3b4bcecf251a2955c09a6e9837e (diff)
Merge "Merge RP1A.191203.001" into r-keystone-qcom-dev
Diffstat (limited to 'libnetutils/ifc_utils.c')
-rw-r--r--libnetutils/ifc_utils.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index 6af49bbdb..8212eba29 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -113,6 +113,10 @@ int string_to_ip(const char *string, struct sockaddr_storage *ss) {
if (ret == 0) {
memcpy(ss, ai->ai_addr, ai->ai_addrlen);
freeaddrinfo(ai);
+ } else {
+ // Getaddrinfo has its own error codes. Convert to negative errno.
+ // There, the only thing that can reasonably happen is that the passed-in string is invalid.
+ ret = (ret == EAI_SYSTEM) ? -errno : -EINVAL;
}
return ret;
@@ -263,19 +267,13 @@ int ifc_act_on_address(int action, const char *name, const char *address,
struct {
struct nlmsghdr n;
struct ifaddrmsg r;
- // Allow for IPv6 address, headers, IPv4 broadcast addr and padding.
- char attrbuf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
- NLMSG_ALIGN(sizeof(struct rtattr)) +
- NLMSG_ALIGN(INET6_ADDRLEN) +
- NLMSG_ALIGN(sizeof(struct rtattr)) +
- NLMSG_ALIGN(INET_ADDRLEN)];
+ // Allow for IPv4 or IPv6 address, headers, IPv4 broadcast address and padding.
+ char attrbuf[NLMSG_ALIGN(sizeof(struct rtattr)) + NLMSG_ALIGN(INET6_ADDRLEN) +
+ NLMSG_ALIGN(sizeof(struct rtattr)) + NLMSG_ALIGN(INET_ADDRLEN)];
} req;
struct rtattr *rta;
struct nlmsghdr *nh;
struct nlmsgerr *err;
- char buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
- NLMSG_ALIGN(sizeof(struct nlmsgerr)) +
- NLMSG_ALIGN(sizeof(struct nlmsghdr))];
// Get interface ID.
ifindex = if_nametoindex(name);
@@ -344,6 +342,7 @@ int ifc_act_on_address(int action, const char *name, const char *address,
return -saved_errno;
}
+ char buf[NLMSG_ALIGN(sizeof(struct nlmsgerr)) + sizeof(req)];
len = recv(s, buf, sizeof(buf), 0);
saved_errno = errno;
close(s);