5 struct tos_value_mask {
9 static const struct tos_symbol_info {
12 } tos_symbol_names[] = {
13 {IPTOS_LOWDELAY, "Minimize-Delay"},
14 {IPTOS_THROUGHPUT, "Maximize-Throughput"},
15 {IPTOS_RELIABILITY, "Maximize-Reliability"},
16 {IPTOS_MINCOST, "Minimize-Cost"},
17 {IPTOS_NORMALSVC, "Normal-Service"},
22 * tos_parse_numeric - parse sth. like "15/255"
25 * @info: accompanying structure
26 * @bits: number of bits that are allowed
27 * (8 for IPv4 TOS field, 4 for IPv6 Priority Field)
29 static bool tos_parse_numeric(const char *str, struct tos_value_mask *tvm,
32 const unsigned int max = (1 << bits) - 1;
36 strtonum(str, &end, &value, 0, max);
41 const char *p = end + 1;
43 if (!strtonum(p, &end, &value, 0, max))
44 exit_error(PARAMETER_PROBLEM, "Illegal value: \"%s\"",
50 exit_error(PARAMETER_PROBLEM, "Illegal value: \"%s\"", str);
54 static bool tos_parse_symbolic(const char *str, struct tos_value_mask *tvm,
55 unsigned int def_mask)
57 const unsigned int max = 255;
58 const struct tos_symbol_info *symbol;
60 if (strtonum(str, NULL, NULL, 0, max))
61 return tos_parse_numeric(str, tvm, max);
63 /* Do not consider ECN bits */
65 for (symbol = tos_symbol_names; symbol->name != NULL; ++symbol)
66 if (strcasecmp(str, symbol->name) == 0) {
67 tvm->value = symbol->value;
71 exit_error(PARAMETER_PROBLEM, "Symbolic name \"%s\" is unknown", str);
75 static bool tos_try_print_symbolic(const char *prefix,
76 u_int8_t value, u_int8_t mask)
78 const struct tos_symbol_info *symbol;
83 for (symbol = tos_symbol_names; symbol->name != NULL; ++symbol)
84 if (value == symbol->value) {
85 printf("%s%s ", prefix, symbol->name);