Merge "Return a valid error code when adding an invalid IP address." am: f3ff94b702 am: 1de06e942f
am: c1d14c69cc
Change-Id: I12b08c7bc320eb6cbbb8c0cafbe1e24d5f6ea41f
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index 6af49bb..4e73401 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -113,6 +113,10 @@
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;