From df36c25bbfb864d8ecf040163e91bbf363f0bf93 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Mon, 1 Nov 2010 15:20:43 +0100 Subject: [PATCH] nl-classid-lookup: Added --raw option to print classid without pretty printing it --- man/nl-classid-lookup.8 | 4 ++++ src/nl-classid-lookup.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/man/nl-classid-lookup.8 b/man/nl-classid-lookup.8 index f447461..d48e9eb 100644 --- a/man/nl-classid-lookup.8 +++ b/man/nl-classid-lookup.8 @@ -6,6 +6,7 @@ nl\-classid\-lookup - Lookup classid definitions .B nl\-classid\-lookup .RB [ \-hv ] .RB [ \-r ] +.RB [ \-\-raw ] .I name .SH DESCRIPTION @@ -23,6 +24,9 @@ Print versioning information to console and exit. .TP .BR \-\^r " or " \-\-reverse Do a reverse lookup. Lookup a classid and print its name. +.TP +.B \-\-raw +Print the raw classid in hexadecimal format, do not pretty print it. .SH USAGE .PP diff --git a/src/nl-classid-lookup.c b/src/nl-classid-lookup.c index faa65dd..1d45d0b 100644 --- a/src/nl-classid-lookup.c +++ b/src/nl-classid-lookup.c @@ -20,6 +20,7 @@ static void print_usage(void) " -h, --help Show this help text.\n" " -v, --version Show versioning information.\n" " -r, --reverse Do a reverse lookup, i.e. classid to name.\n" +" --raw Print the raw classid, not pretty printed.\n" "\n" "EXAMPLE\n" " $ nl-classid-lookup low_latency\n" @@ -33,14 +34,18 @@ int main(int argc, char *argv[]) { uint32_t classid; char *name; - int err, reverse = 0; + int err, reverse = 0, raw = 0; for (;;) { int c, optidx = 0; + enum { + ARG_RAW = 257, + }; static struct option long_opts[] = { { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "reverse", 0, 0, 'r' }, + { "raw", 0, 0, ARG_RAW }, { 0, 0, 0, 0 } }; @@ -52,6 +57,7 @@ int main(int argc, char *argv[]) case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'r': reverse = 1; break; + case ARG_RAW: raw = 1; break; } } @@ -72,7 +78,9 @@ int main(int argc, char *argv[]) if (reverse) { char buf[64]; printf("%s\n", rtnl_tc_handle2str(classid, buf, sizeof(buf))); - } else + } else if (raw) + printf("%#x\n", classid); + else printf("%x:%x\n", TC_H_MAJ(classid) >> 16, TC_H_MIN(classid)); return 0;