2 * src/nl-fib-lookup.c FIB Route Lookup
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>
14 static void print_usage(void)
17 "Usage: nl-fib-lookup [options] <addr>\n"
19 " -t, --table <table> Table id\n"
20 " -f, --fwmark <int> Firewall mark\n"
21 " -s, --scope <scope> Routing scope\n"
22 " -T, --tos <int> Type of Service\n");
26 int main(int argc, char *argv[])
29 struct nl_cache *result;
30 struct flnl_request *request;
32 struct nl_dump_params params = {
34 .dp_type = NL_DUMP_DETAILS,
36 int table = RT_TABLE_UNSPEC, scope = RT_SCOPE_UNIVERSE;
41 static struct option long_opts[] = {
43 {"fwmark", 1, 0, 'f'},
51 c = getopt_long(argc, argv, "t:f:s:T:h", long_opts, &idx);
57 table = strtoul(optarg, NULL, 0);
60 fwmark = strtoul(optarg, NULL, 0);
63 scope = strtoul(optarg, NULL, 0);
66 tos = strtoul(optarg, NULL, 0);
76 nlh = nl_cli_alloc_socket();
78 if ((err = nl_addr_parse(argv[optind], AF_INET, &addr)) < 0)
79 nl_cli_fatal(err, "Unable to parse address \"%s\": %s\n",
80 argv[optind], nl_geterror(err));
82 result = flnl_result_alloc_cache();
84 nl_cli_fatal(ENOMEM, "Unable to allocate cache");
86 request = flnl_request_alloc();
88 nl_cli_fatal(ENOMEM, "Unable to allocate request");
90 flnl_request_set_table(request, table);
91 flnl_request_set_fwmark(request, fwmark);
92 flnl_request_set_scope(request, scope);
93 flnl_request_set_tos(request, tos);
95 err = flnl_request_set_addr(request, addr);
98 nl_cli_fatal(err, "Unable to send request: %s", nl_geterror(err));
100 nl_cli_connect(nlh, NETLINK_FIB_LOOKUP);
102 err = flnl_lookup(nlh, request, result);
104 nl_cli_fatal(err, "Unable to lookup: %s\n", nl_geterror(err));
106 nl_cache_dump(result, ¶ms);