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

Function parse_portmask

dpdk/examples/server_node_efd/efd_server/args.c:48–77  ·  view source on GitHub ↗

* The ports to be used by the application are passed in * the form of a bitmask. This function parses the bitmask * and places the port numbers to be used into the port[] * array variable */

Source from the content-addressed store, hash-verified

46 * array variable
47 */
48static int
49parse_portmask(uint8_t max_ports, const char *portmask)
50{
51 char *end = NULL;
52 unsigned long pm;
53 uint8_t count = 0;
54
55 if (portmask == NULL || *portmask == '\0')
56 return -1;
57
58 /* convert parameter to a number and verify */
59 pm = strtoul(portmask, &end, 16);
60 if (end == NULL || *end != '\0' || pm == 0)
61 return -1;
62
63 /* loop through bits of the mask and mark ports */
64 while (pm != 0) {
65 if (pm & 0x01) { /* bit is set in mask, use port */
66 if (count >= max_ports)
67 printf("WARNING: requested port %u not present"
68 " - ignoring\n", (unsigned int)count);
69 else
70 info->id[info->num_ports++] = count;
71 }
72 pm = (pm >> 1);
73 count++;
74 }
75
76 return 0;
77}
78
79/**
80 * Take the number of nodes parameter passed to the app

Callers 1

parse_app_argsFunction · 0.70

Calls 2

strtoulFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected