From c7e8539340bd5dd6a099303bda6dead9063e6333 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sat, 10 Jul 2010 14:34:33 +0200 Subject: examples: fix rtnl-set-link This patch fixes the example that allows to set up/down the network interface. Signed-off-by: Pablo Neira Ayuso --- examples/rtnl-link-set.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'examples/rtnl-link-set.c') diff --git a/examples/rtnl-link-set.c b/examples/rtnl-link-set.c index 0dcd6ce..d5cf9b1 100644 --- a/examples/rtnl-link-set.c +++ b/examples/rtnl-link-set.c @@ -22,30 +22,33 @@ int main(int argc, char *argv[]) struct nlmsghdr *nlh; struct ifinfomsg *ifm; int ret; - unsigned int seq, portid, oper; + unsigned int seq, portid, change = 0, flags = 0; if (argc != 3) { printf("Usage: %s [ifname] [up|down]\n", argv[0]); exit(EXIT_FAILURE); } - if (strncasecmp(argv[2], "up", strlen("up")) == 0) - oper = IF_OPER_UP; - else if (strncasecmp(argv[2], "down", strlen("down")) == 0) - oper = IF_OPER_DOWN; - else { + if (strncasecmp(argv[2], "up", strlen("up")) == 0) { + change |= IFF_UP; + flags |= IFF_UP; + } else if (strncasecmp(argv[2], "down", strlen("down")) == 0) { + change |= IFF_UP; + flags &= ~IFF_UP; + } else { fprintf(stderr, "%s is not `up' nor `down'\n", argv[2]); exit(EXIT_FAILURE); } nlh = mnl_nlmsg_put_header(buf); - nlh->nlmsg_type = RTM_SETLINK; + nlh->nlmsg_type = RTM_NEWLINK; nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; nlh->nlmsg_seq = seq = time(NULL); ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm)); - ifm->ifi_family = AF_PACKET; + ifm->ifi_family = AF_UNSPEC; + ifm->ifi_change = change; + ifm->ifi_flags = flags; - mnl_attr_put_u8(nlh, IFLA_OPERSTATE, oper); mnl_attr_put_str(nlh, IFLA_IFNAME, argv[1]); nl = mnl_socket_open(NETLINK_ROUTE); -- cgit v1.2.3