int rtnl_dsfield_a2n(uint32_t *id, char *arg) { static const char *cache = NULL; static unsigned long res; int i; if (cache && strcmp(cache, arg) == 0) { *id = res; return 0; } rtnl_rtdsfield_initialize(); for (i = 0; i < 256; i++) { if (rtnl_rtdsfield_tab[i] && strcmp(rtnl_rtdsfield_tab[i], arg) == 0) { cache = rtnl_rtdsfield_tab[i]; res = i; *id = res; return 0; } } res = bb_strtoul(arg, NULL, 16); if (errno || res > 255) return -1; *id = res; return 0; }
int rtnl_dsfield_a2n(__u32 *id, char *arg) { static char *cache = NULL; static unsigned long res; char *end; int i; if (cache && strcmp(cache, arg) == 0) { *id = res; return 0; } if (!rtnl_rtdsfield_init) rtnl_rtdsfield_initialize(); for (i=0; i<256; i++) { if (rtnl_rtdsfield_tab[i] && strcmp(rtnl_rtdsfield_tab[i], arg) == 0) { cache = rtnl_rtdsfield_tab[i]; res = i; *id = res; return 0; } } res = strtoul(arg, &end, 16); if (!end || end == arg || *end || res > 255) return -1; *id = res; return 0; }
const char * rtnl_dsfield_n2a(int id, char *buf, int len) { if (id < 0 || id >= 256) { snprintf(buf, len, "%d", id); return buf; } rtnl_rtdsfield_initialize(); if (rtnl_rtdsfield_tab[id]) return rtnl_rtdsfield_tab[id]; snprintf(buf, len, "0x%02x", id); return buf; }