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-2006 Thomas Graf <tgraf@suug.ch>
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[])
28 struct nl_handle *nlh;
29 struct nl_cache *result;
30 struct flnl_request *request;
32 struct nl_dump_params params = {
34 .dp_type = NL_DUMP_FULL,
36 int table = RT_TABLE_UNSPEC, scope = RT_SCOPE_UNIVERSE;
40 if (nltool_init(argc, argv) < 0)
44 static struct option long_opts[] = {
46 {"fwmark", 1, 0, 'f'},
54 c = getopt_long(argc, argv, "t:f:s:T:h", long_opts, &idx);
60 table = strtoul(optarg, NULL, 0);
63 fwmark = strtoul(optarg, NULL, 0);
66 scope = strtoul(optarg, NULL, 0);
69 tos = strtoul(optarg, NULL, 0);
79 nlh = nltool_alloc_handle();
83 addr = nl_addr_parse(argv[optind], AF_INET);
85 fprintf(stderr, "Unable to parse address \"%s\": %s\n",
86 argv[optind], nl_geterror());
90 result = flnl_result_alloc_cache();
94 request = flnl_request_alloc();
98 flnl_request_set_table(request, table);
99 flnl_request_set_fwmark(request, fwmark);
100 flnl_request_set_scope(request, scope);
101 flnl_request_set_tos(request, tos);
103 err = flnl_request_set_addr(request, addr);
108 if (nltool_connect(nlh, NETLINK_FIB_LOOKUP) < 0)
111 err = flnl_lookup(nlh, request, result);
113 fprintf(stderr, "Unable to lookup: %s\n", nl_geterror());
117 nl_cache_dump(result, ¶ms);
121 nl_object_put(OBJ_CAST(request));
123 nl_cache_free(result);
128 nl_handle_destroy(nlh);