diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2010-07-10 14:34:33 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2010-07-10 14:34:33 +0200 |
commit | c7e8539340bd5dd6a099303bda6dead9063e6333 (patch) | |
tree | 7a870f7afbeb8ac15954c45a4fa7ff2e551cae9a | |
parent | 5d51315f5263f9cbda18f70e2d340a66cf1bf1f9 (diff) | |
download | libmnl-c7e8539340bd5dd6a099303bda6dead9063e6333.tar.gz libmnl-c7e8539340bd5dd6a099303bda6dead9063e6333.zip |
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 <pablo@netfilter.org>
-rw-r--r-- | examples/rtnl-link-set.c | 21 |
1 files changed, 12 insertions, 9 deletions
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); |