2 * src/nl-route-get.c Get Route Attributes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/route.h>
14 #include <netlink/cli/link.h>
16 static void print_usage(void)
18 printf("Usage: nl-route-get <addr>\n");
22 static void parse_cb(struct nl_object *obj, void *arg)
24 //struct rtnl_route *route = (struct rtnl_route *) obj;
25 struct nl_dump_params params = {
27 .dp_type = NL_DUMP_DETAILS,
30 nl_object_dump(obj, ¶ms);
33 static int cb(struct nl_msg *msg, void *arg)
37 if ((err = nl_msg_parse(msg, &parse_cb, NULL)) < 0)
38 nl_cli_fatal(err, "Unable to parse object: %s", nl_geterror(err));
43 int main(int argc, char *argv[])
46 struct nl_cache *link_cache, *route_cache;
50 if (argc < 2 || !strcmp(argv[1], "-h"))
53 sock = nl_cli_alloc_socket();
54 nl_cli_connect(sock, NETLINK_ROUTE);
55 link_cache = nl_cli_link_alloc_cache(sock);
56 route_cache = nl_cli_route_alloc_cache(sock, 0);
58 dst = nl_cli_addr_parse(argv[1], AF_INET);
63 .rtm_family = nl_addr_get_family(dst),
64 .rtm_dst_len = nl_addr_get_prefixlen(dst),
67 m = nlmsg_alloc_simple(RTM_GETROUTE, 0);
68 nlmsg_append(m, &rmsg, sizeof(rmsg), NLMSG_ALIGNTO);
69 nla_put_addr(m, RTA_DST, dst);
71 err = nl_send_auto_complete(sock, m);
74 nl_cli_fatal(err, "%s", nl_geterror(err));
76 nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, cb, NULL);
78 if (nl_recvmsgs_default(sock) < 0)
79 nl_cli_fatal(err, "%s", nl_geterror(err));
82 //nl_cache_dump(route_cache, ¶ms);