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

Function ifc_name2unit

freebsd/net/if_clone.c:578–606  ·  view source on GitHub ↗

* A utility function to extract unit numbers from interface names of * the form name###. * * Returns 0 on success and an error on failure. */

Source from the content-addressed store, hash-verified

576 * Returns 0 on success and an error on failure.
577 */
578int
579ifc_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
608static int
609ifc_alloc_unit_specific(struct if_clone *ifc, int *unit)

Callers 4

stf_clone_createFunction · 0.85
ifc_simple_createFunction · 0.85
epair_clone_createFunction · 0.85
vlan_clone_createFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected