int rtnl_rtprot_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_rtprot_initialize(); for (i = 0; i < 256; i++) { if (rtnl_rtprot_tab[i] && strcmp(rtnl_rtprot_tab[i], arg) == 0) { cache = rtnl_rtprot_tab[i]; res = i; *id = res; return 0; } } res = bb_strtoul(arg, NULL, 0); if (errno || res > 255) return -1; *id = res; return 0; }
int rtnl_rtprot_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_rtprot_init) rtnl_rtprot_initialize(); for (i=0; i<256; i++) { if (rtnl_rtprot_tab[i] && strcmp(rtnl_rtprot_tab[i], arg) == 0) { cache = rtnl_rtprot_tab[i]; res = i; *id = res; return 0; } } res = strtoul(arg, &end, 0); if (!end || end == arg || *end || res > 255) return -1; *id = res; return 0; }
const char* rtnl_rtprot_n2a(int id, char *buf, int len) { if (id < 0 || id >= 256) { snprintf(buf, len, "%d", id); return buf; } rtnl_rtprot_initialize(); if (rtnl_rtprot_tab[id]) return rtnl_rtprot_tab[id]; snprintf(buf, len, "%d", id); return buf; }