* A utility function to extract unit numbers from interface names of * the form name###. * * Returns 0 on success and an error on failure. */
| 576 | * Returns 0 on success and an error on failure. |
| 577 | */ |
| 578 | int |
| 579 | ifc_name2unit(const char *name, int *unit) |
| 580 | { |
| 581 | const char *cp; |
| 582 | int cutoff = INT_MAX / 10; |
| 583 | int cutlim = INT_MAX % 10; |
| 584 | |
| 585 | for (cp = name; *cp != '\0' && (*cp < '0' || *cp > '9'); cp++) |
| 586 | ; |
| 587 | if (*cp == '\0') { |
| 588 | *unit = -1; |
| 589 | } else if (cp[0] == '0' && cp[1] != '\0') { |
| 590 | /* Disallow leading zeroes. */ |
| 591 | return (EINVAL); |
| 592 | } else { |
| 593 | for (*unit = 0; *cp != '\0'; cp++) { |
| 594 | if (*cp < '0' || *cp > '9') { |
| 595 | /* Bogus unit number. */ |
| 596 | return (EINVAL); |
| 597 | } |
| 598 | if (*unit > cutoff || |
| 599 | (*unit == cutoff && *cp - '0' > cutlim)) |
| 600 | return (EINVAL); |
| 601 | *unit = (*unit * 10) + (*cp - '0'); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | return (0); |
| 606 | } |
| 607 | |
| 608 | static int |
| 609 | ifc_alloc_unit_specific(struct if_clone *ifc, int *unit) |
no outgoing calls
no test coverage detected