Logo Search packages:      
Sourcecode: libnl2 version File versions  Download package

int rtnl_tc_str2handle ( const char *  name,
uint32_t *  res 
)

Convert a charactering strint to a traffic control handle

  • name traffic control handle as character string
  • res destination buffer
Converts the provided character string specifying a traffic control handle to the corresponding numeric value.

The handle must be provided in one of the following formats:

  • root
  • none
  • XXXX:
  • :YYYY
  • XXXX:YYYY
  • XXXXYYYY

Returns:
0 on success or a negative error code

Definition at line 520 of file tc.c.

{
      char *colon, *end;
      uint32_t h;

      if (!strcasecmp(name, "root")) {
            *res = TC_H_ROOT;
            return 0;
      }

      if (!strcasecmp(name, "none")) {
            *res = TC_H_UNSPEC;
            return 0;
      }

      h = strtoul(name, &colon, 16);

      if (colon == name) {
            /* :YYYY */
            h = 0;
            if (':' != *colon)
                  return -NLE_INVAL;
      }

      if (':' == *colon) {
            /* check if we would lose bits */
            if (TC_H_MAJ(h))
                  return -NLE_RANGE;
            h <<= 16;

            if ('\0' == colon[1]) {
                  /* XXXX: */
                  *res = h;
            } else {
                  /* XXXX:YYYY */
                  uint32_t l = strtoul(colon+1, &end, 16);

                  /* check if we overlap with major part */
                  if (TC_H_MAJ(l))
                        return -NLE_RANGE;

                  if ('\0' != *end)
                        return -NLE_INVAL;

                  *res = (h | l);
            }
      } else if ('\0' == *colon) {
            /* XXXXYYYY */
            *res = h;
      } else
            return -NLE_INVAL;

      return 0;
}


Generated by  Doxygen 1.6.0   Back to index