MCPcopy Create free account
hub / github.com/F-Stack/f-stack / parse_range

Function parse_range

dpdk/examples/ipsec-secgw/parser.c:108–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108int
109parse_range(const char *token, uint16_t *low, uint16_t *high)
110{
111 char ch;
112 char num_str[20];
113 uint32_t pos;
114 int range_low = -1;
115 int range_high = -1;
116
117 if (!low || !high)
118 return -1;
119
120 memset(num_str, 0, 20);
121 pos = 0;
122
123 while ((ch = *token++) != '\0') {
124 if (isdigit(ch)) {
125 if (pos >= 19)
126 return -1;
127 num_str[pos++] = ch;
128 } else if (ch == ':') {
129 if (range_low != -1)
130 return -1;
131 range_low = atoi(num_str);
132 memset(num_str, 0, 20);
133 pos = 0;
134 }
135 }
136
137 if (strlen(num_str) == 0)
138 return -1;
139
140 range_high = atoi(num_str);
141
142 *low = (uint16_t)range_low;
143 *high = (uint16_t)range_high;
144
145 return 0;
146}
147
148/*
149 * helper function for parse_mac, parse one section of the ether addr.

Callers 2

parse_sp6_tokensFunction · 0.70
parse_sp4_tokensFunction · 0.70

Calls 2

memsetFunction · 0.85
isdigitFunction · 0.85

Tested by

no test coverage detected