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;
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();
79 nl_cli_fatal(err,
"Unable to parse address \"%s\": %s\n",
80 argv[optind], nl_geterror(err));
86 request = flnl_request_alloc();
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);
104 nl_cli_fatal(err,
"Unable to lookup: %s\n", nl_geterror(err));