2 * src/nl-classid-lookup.c Lookup classid
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) 2010 Thomas Graf <tgraf@suug.ch>
12 #include <netlink/cli/utils.h>
14 static void print_usage(void)
17 "Usage: nl-classid-lookup [OPTIONS]... NAME\n"
20 " -h, --help Show this help text.\n"
21 " -v, --version Show versioning information.\n"
22 " -r, --reverse Do a reverse lookup, i.e. classid to name.\n"
23 " --raw Print the raw classid, not pretty printed.\n"
26 " $ nl-classid-lookup low_latency\n"
27 " $ nl-classid-lookup -r 1:12\n"
33 int main(int argc, char *argv[])
37 int err, reverse = 0, raw = 0;
44 static struct option long_opts[] = {
45 { "help", 0, 0, 'h' },
46 { "version", 0, 0, 'v' },
47 { "reverse", 0, 0, 'r' },
48 { "raw", 0, 0, ARG_RAW },
52 c = getopt_long(argc, argv, "hvr", long_opts, &optidx);
57 case 'h': print_usage(); break;
58 case 'v': nl_cli_print_version(); break;
59 case 'r': reverse = 1; break;
60 case ARG_RAW: raw = 1; break;
67 name = argv[optind++];
70 * We use rtnl_tc_str2handle() even while doing a reverse lookup. This
71 * allows for name -> name lookups. This is intentional, it does not
72 * do any harm and avoids duplicating a lot of code.
74 if ((err = rtnl_tc_str2handle(name, &classid)) < 0)
75 nl_cli_fatal(err, "Unable to lookup classid \"%s\": %s",
76 name, nl_geterror(err));
80 printf("%s\n", rtnl_tc_handle2str(classid, buf, sizeof(buf)));
82 printf("%#x\n", classid);
84 printf("%x:%x\n", TC_H_MAJ(classid) >> 16, TC_H_MIN(classid));