📄 conf.c
字号:
/* * * bootpd_nis: simple BOOTP server with NIS maps support * Copyright (C) 2005 <bfleisch@users.sourceforge.net> * * 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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * $Id: conf.c,v 1.2 2005/03/02 21:03:41 bfleisch Exp $ * */#include "conf.h" struct conf_map{ int id; char* key;};enum{ C_NETMASK, C_NAMESERV, C_GW_ADDR, C_BROADCAST, C_IFNAME, C_LOGFILE, C_BOOTFILE, C_KEY_NOT_FOUND};static struct conf_map maps[] ={ { C_NETMASK, "netmask" }, { C_NAMESERV, "nameserver" }, { C_GW_ADDR, "gateway" }, { C_BROADCAST, "broadcast" }, { C_IFNAME, "interface" }, { C_LOGFILE, "logfile" }, { C_BOOTFILE, "bootfile" }, { C_KEY_NOT_FOUND, NULL }};static int lookup_key(const char* kword){ int i; i=0; while ( maps[i].key) { if ( strcasecmp(kword, maps[i].key)==0) return maps[i].id; i++; } return C_KEY_NOT_FOUND;}int conf_parse_file(const char* filename){ FILE *f; char keyword[64], value[64]; char line[256]; int err; err=0; f = fopen(filename, "r"); if (!f) { log_perror(LOG_NOTICE, "%s:", filename); return -1;} while ( ! feof(f)) { if (! fgets(line, 256, f)) continue; if (sscanf(line, "%64s %64s", keyword, value) != 2) continue; if (keyword[0]=='#') continue; switch (lookup_key(keyword)) { case C_NETMASK: resolve_addr (value, &g_netmask); break; case C_NAMESERV: resolve_addr(value, &g_nameserv); break; case C_GW_ADDR: resolve_addr(value, &g_gw_addr); break; case C_BROADCAST: resolve_addr(value, &g_broadcast); break; case C_IFNAME: g_ifname = strdup(value); break; case C_LOGFILE: g_logfile = strdup(value); break; case C_BOOTFILE: g_bootfile = strdup(value); break; default: log_msg(LOG_ERR, "%s: unrecognized keyword."); err = -1; break; } } fclose(f); return err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -