* 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 */
| 46 | * array variable |
| 47 | */ |
| 48 | static int |
| 49 | parse_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 |
no test coverage detected