tos_values.c revision e37d45ce390c2f5a7f1e64742b9100ecef0def54
1#include <stdbool.h>
2#include <stdint.h>
3#include <stdio.h>
4#include <linux/ip.h>
5
6#ifndef IPTOS_NORMALSVC
7#	define IPTOS_NORMALSVC 0
8#endif
9
10struct tos_value_mask {
11	uint8_t value, mask;
12};
13
14static const struct tos_symbol_info {
15	unsigned char value;
16	const char *name;
17} tos_symbol_names[] = {
18	{IPTOS_LOWDELAY,    "Minimize-Delay"},
19	{IPTOS_THROUGHPUT,  "Maximize-Throughput"},
20	{IPTOS_RELIABILITY, "Maximize-Reliability"},
21	{IPTOS_MINCOST,     "Minimize-Cost"},
22	{IPTOS_NORMALSVC,   "Normal-Service"},
23	{},
24};
25
26static bool tos_try_print_symbolic(const char *prefix,
27    uint8_t value, uint8_t mask)
28{
29	const struct tos_symbol_info *symbol;
30
31	if (mask != 0x3F)
32		return false;
33
34	for (symbol = tos_symbol_names; symbol->name != NULL; ++symbol)
35		if (value == symbol->value) {
36			printf(" %s%s", prefix, symbol->name);
37			return true;
38		}
39
40	return false;
41}
42