Mirror of git://git.busybox.net/busybox with our patches on top
Source
/* vi: set sw=4 ts=4: */
/*
* rt_names.c rtnetlink names DB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
*/
static void rtnl_tab_initialize(const char *file, const char **tab, int size)
{
char buf[512];
FILE *fp;
fp = fopen(file, "r");
if (!fp)
return;
while (fgets(buf, sizeof(buf), fp)) {
char *p = buf;
int id;
char namebuf[512];
while (*p == ' ' || *p == '\t')
p++;
if (*p == '#' || *p == '\n' || *p == 0)
continue;
if (sscanf(p, "0x%x %s\n", &id, namebuf) != 2
&& sscanf(p, "0x%x %s #", &id, namebuf) != 2
&& sscanf(p, "%d %s\n", &id, namebuf) != 2
&& sscanf(p, "%d %s #", &id, namebuf) != 2
) {
bb_error_msg("database %s is corrupted at %s",
file, p);
return;
}
if (id < 0 || id > size)
continue;
tab[id] = xstrdup(namebuf);
}
fclose(fp);
}
static const char **rtnl_rtprot_tab; /* [256] */
static void rtnl_rtprot_initialize(void)
{
static const char *const init_tab[] = {
"none",
"redirect",
"kernel",
"boot",
"static",
NULL,
NULL,