diff mbox series

[iproute2,1/6] utils: Always specify family for address in get_addr_1()

Message ID 1516299227-26724-2-git-send-email-serhe.popovych@gmail.com
State Accepted, archived
Delegated to: David Ahern
Headers show
Series utils: Get rid of inet_get_addr() | expand

Commit Message

Serhey Popovych Jan. 18, 2018, 6:13 p.m. UTC
Set ->family correctly when string representing address
is "default", "all" or "any": get_addr_1() might be called
with AF_UNSPEC (e.g. get_addr() -> get_addr_1()).

Extend support for zero address to all address families,
not only AF_INET and AF_INET6 when one explicitly given
as @family: use af_byte_len() to correctly set address length.

Still assume AF_INET when @family is AF_UNSPEC.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
 lib/utils.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/utils.c b/lib/utils.c
index 9fa5220..a023e74 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -543,8 +543,8 @@  int get_addr_1(inet_prefix *addr, const char *name, int family)
 	    strcmp(name, "any") == 0) {
 		if ((family == AF_DECnet) || (family == AF_MPLS))
 			return -1;
-		addr->family = family;
-		addr->bytelen = (family == AF_INET6 ? 16 : 4);
+		addr->family = (family != AF_UNSPEC) ? family : AF_INET;
+		addr->bytelen = af_byte_len(addr->family);
 		addr->bitlen = -1;
 		return 0;
 	}