int rtnl_rttable_a2n(uint32_t * id, char *arg) { static char *cache = NULL; static unsigned long res; int i; if (cache && strcmp(cache, arg) == 0) { *id = res; return 0; } rtnl_rttable_initialize(); for (i = 0; i < 256; i++) { if (rtnl_rttable_tab[i] && strcmp(rtnl_rttable_tab[i], arg) == 0) { cache = (char*)rtnl_rttable_tab[i]; res = i; *id = res; return 0; } } i = bb_strtoul(arg, NULL, 0); if (errno || i > 255) return -1; *id = i; return 0; }
int rtnl_rttable_a2n(__u32 *id, char *arg) { static char *cache = NULL; static unsigned long res; struct rtnl_hash_entry *entry; char *end; __u32 i; if (cache && strcmp(cache, arg) == 0) { *id = res; return 0; } if (!rtnl_rttable_init) rtnl_rttable_initialize(); for (i=0; i<256; i++) { entry = rtnl_rttable_hash[i]; while (entry && strcmp(entry->name, arg)) entry = entry->next; if (entry) { cache = entry->name; res = entry->id; *id = res; return 0; } } i = strtoul(arg, &end, 0); if (!end || end == arg || *end || i > RT_TABLE_MAX) return -1; *id = i; return 0; }
const char *rtnl_rttable_n2a(int id, char *buf, int len) { if (id < 0 || id >= 256) { snprintf(buf, len, "%d", id); return buf; } rtnl_rttable_initialize(); if (rtnl_rttable_tab[id]) return rtnl_rttable_tab[id]; snprintf(buf, len, "%d", id); return buf; }
char * rtnl_rttable_n2a(__u32 id, char *buf, int len) { struct rtnl_hash_entry *entry; if (id > RT_TABLE_MAX) { snprintf(buf, len, "%u", id); return buf; } if (!rtnl_rttable_init) rtnl_rttable_initialize(); entry = rtnl_rttable_hash[id & 255]; while (entry && entry->id != id) entry = entry->next; if (entry) return entry->name; snprintf(buf, len, "%u", id); return buf; }