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

Function my_ether_aton

dpdk/examples/ip_pipeline/parser.c:334–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332}
333
334static struct rte_ether_addr *
335my_ether_aton(const char *a)
336{
337 int i;
338 char *end;
339 unsigned long o[RTE_ETHER_ADDR_LEN];
340 static struct rte_ether_addr ether_addr;
341
342 i = 0;
343 do {
344 errno = 0;
345 o[i] = strtoul(a, &end, 16);
346 if (errno != 0 || end == a || (end[0] != ':' && end[0] != 0))
347 return NULL;
348 a = end + 1;
349 } while (++i != RTE_DIM(o) && end[0] != 0);
350
351 /* Junk at the end of line */
352 if (end[0] != 0)
353 return NULL;
354
355 /* Support the format XX:XX:XX:XX:XX:XX */
356 if (i == RTE_ETHER_ADDR_LEN) {
357 while (i-- != 0) {
358 if (o[i] > UINT8_MAX)
359 return NULL;
360 ether_addr.addr_bytes[i] = (uint8_t)o[i];
361 }
362 /* Support the format XXXX:XXXX:XXXX */
363 } else if (i == RTE_ETHER_ADDR_LEN / 2) {
364 while (i-- != 0) {
365 if (o[i] > UINT16_MAX)
366 return NULL;
367 ether_addr.addr_bytes[i * 2] = (uint8_t)(o[i] >> 8);
368 ether_addr.addr_bytes[i * 2 + 1] = (uint8_t)(o[i] & 0xff);
369 }
370 /* unknown format */
371 } else
372 return NULL;
373
374 return (struct rte_ether_addr *)&ether_addr;
375}
376
377int
378parse_ipv4_addr(const char *token, struct in_addr *ipv4)

Callers 1

parse_mac_addrFunction · 0.85

Calls 1

strtoulFunction · 0.85

Tested by

no test coverage detected