ipmaddr: use preferred_family when given

When creating socket() AF_INET is used irrespective of the family
that is given at the command-line (with -4, -6, or -0). This change
will open the socket with the preferred family.

Signed-off-by: Mahesh Bandewar <maheshb@google.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Mahesh Bandewar 2018-08-22 18:01:34 -07:00 committed by Stephen Hemminger
parent 0ebb420929
commit a5aaca9be2
1 changed files with 12 additions and 1 deletions

View File

@ -289,6 +289,7 @@ static int multiaddr_list(int argc, char **argv)
static int multiaddr_modify(int cmd, int argc, char **argv)
{
struct ifreq ifr = {};
int family;
int fd;
if (cmd == RTM_NEWADDR)
@ -324,7 +325,17 @@ static int multiaddr_modify(int cmd, int argc, char **argv)
exit(-1);
}
fd = socket(AF_INET, SOCK_DGRAM, 0);
switch (preferred_family) {
case AF_INET6:
case AF_PACKET:
case AF_INET:
family = preferred_family;
break;
default:
family = AF_INET;
}
fd = socket(family, SOCK_DGRAM, 0);
if (fd < 0) {
perror("Cannot create socket");
exit(1);