1db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf/*
2db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf * src/nl-pktloc-lookup.c     Lookup packet location alias
3db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf *
4db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf *	This library is free software; you can redistribute it and/or
5db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf *	modify it under the terms of the GNU Lesser General Public
6db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf *	License as published by the Free Software Foundation version 2.1
7db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf *	of the License.
8db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf *
9db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
10db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf */
11db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf
12db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf#include <netlink/cli/utils.h>
13db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf#include <netlink/route/pktloc.h>
14db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf
15db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Grafstatic void print_usage(void)
16db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf{
17db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf	printf("Usage: nl-pktloc-lookup <name>\n");
18db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf	exit(0);
19db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf}
20db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf
21db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Grafint main(int argc, char *argv[])
22db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf{
23db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf	struct rtnl_pktloc *loc;
24db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf	int err;
25db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf
26db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf	if (argc < 2)
27db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf		print_usage();
28db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf
29db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf	if ((err = rtnl_pktloc_lookup(argv[1], &loc)) < 0)
30db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf		nl_cli_fatal(err, "Unable to lookup packet location: %s",
31db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf			nl_geterror(err));
32db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf
33db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf	printf("%s: %u %u+%u 0x%x %u\n", loc->name, loc->align,
34db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf		loc->layer, loc->offset, loc->mask, loc->flags);
35db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf
36db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf	return 0;
37db5bd57899affbcaf42ac0b93c5c7be8f51ca390Thomas Graf}
38