diff options
author | Thomas Graf <tgr@lsx.localdomain> | 2008-05-22 22:02:02 (GMT) |
---|---|---|
committer | Thomas Graf <tgr@lsx.localdomain> | 2008-05-22 22:02:02 (GMT) |
commit | 10cf5a586c149fdb7e2639000dbfae5e6f8522a5 (patch) | |
tree | 399a15d767fd15b85c92be2e70b748645eeb983e /src/nl-route-get.c | |
parent | 337fbd24cad1f5cf9c8b4287a75f2c69f088adce (diff) | |
download | libnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.zip libnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.tar.gz libnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.tar.bz2 |
New set of libnl tools
Converts all tools to the API changes and improves the useability by
introducing regular options and long options.
Diffstat (limited to 'src/nl-route-get.c')
-rw-r--r-- | src/nl-route-get.c | 85 |
1 files changed, 31 insertions, 54 deletions
diff --git a/src/nl-route-get.c b/src/nl-route-get.c index dbd8648..ce267ec 100644 --- a/src/nl-route-get.c +++ b/src/nl-route-get.c @@ -6,7 +6,7 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch> + * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch> */ #include "utils.h" @@ -17,48 +17,43 @@ static void print_usage(void) exit(1); } +static void parse_cb(struct nl_object *obj, void *arg) +{ + //struct rtnl_route *route = (struct rtnl_route *) obj; + struct nl_dump_params params = { + .dp_fd = stdout, + .dp_type = NL_DUMP_DETAILS, + }; + + nl_object_dump(obj, ¶ms); +} + static int cb(struct nl_msg *msg, void *arg) { - nl_cache_parse_and_add(arg, msg); + int err; + + if ((err = nl_msg_parse(msg, &parse_cb, NULL)) < 0) + fatal(err, "Unable to parse object: %s", nl_geterror(err)); return 0; } int main(int argc, char *argv[]) { - struct nl_handle *nlh; + struct nl_sock *sock; struct nl_cache *link_cache, *route_cache; struct nl_addr *dst; - struct nl_dump_params params = { - .dp_fd = stdout, - .dp_type = NL_DUMP_BRIEF - }; int err = 1; if (argc < 2 || !strcmp(argv[1], "-h")) print_usage(); - if (nltool_init(argc, argv) < 0) - goto errout; - - nlh = nltool_alloc_handle(); - if (!nlh) - goto errout; - - if (nltool_connect(nlh, NETLINK_ROUTE) < 0) - goto errout_free_handle; - - link_cache = nltool_alloc_link_cache(nlh); - if (!link_cache) - goto errout_close; + sock = nlt_alloc_socket(); + nlt_connect(sock, NETLINK_ROUTE); + link_cache = nlt_alloc_link_cache(sock); + route_cache = nlt_alloc_route_cache(sock, 0); - dst = nltool_addr_parse(argv[1]); - if (!dst) - goto errout_link_cache; - - route_cache = nltool_alloc_route_cache(nlh, 0); - if (!route_cache) - goto errout_addr_put; + dst = nlt_addr_parse(argv[1], AF_INET); { struct nl_msg *m; @@ -71,36 +66,18 @@ int main(int argc, char *argv[]) nlmsg_append(m, &rmsg, sizeof(rmsg), NLMSG_ALIGNTO); nla_put_addr(m, RTA_DST, dst); - if ((err = nl_send_auto_complete(nlh, m)) < 0) { - nlmsg_free(m); - fprintf(stderr, "%s\n", nl_geterror()); - goto errout_route_cache; - } - + err = nl_send_auto_complete(sock, m); nlmsg_free(m); + if (err < 0) + fatal(err, "%s", nl_geterror(err)); - nl_socket_modify_cb(nlh, NL_CB_VALID, NL_CB_CUSTOM, cb, - route_cache); + nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, cb, NULL); - if (nl_recvmsgs_default(nlh) < 0) { - fprintf(stderr, "%s\n", nl_geterror()); - goto errout_route_cache; - } + if (nl_recvmsgs_default(sock) < 0) + fatal(err, "%s", nl_geterror(err)); } - nl_cache_dump(route_cache, ¶ms); - - err = 0; -errout_route_cache: - nl_cache_free(route_cache); -errout_addr_put: - nl_addr_put(dst); -errout_link_cache: - nl_cache_free(link_cache); -errout_close: - nl_close(nlh); -errout_free_handle: - nl_handle_destroy(nlh); -errout: - return err; + //nl_cache_dump(route_cache, ¶ms); + + return 0; } |