⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhcp-server-conf.c

📁 this is sample about DHCP-agent
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-conf.c,v 1.8 2003/07/15 10:56:34 actmodern Exp $ *  * Copyright 2002 Thamer Alharbash <tmh@whitefang.com> *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. *  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *  */#define MODULE_NAME "dhcp-server-conf"#include "dhcp-local.h"#include "dhcp-limits.h"#include "dhcp-libutil.h"#include "dhcp-librawnet.h"#include "dhcp-option.h"#include "dhcp-lease.h"#include "dhcp-conf.h"#include "dhcp-conf-var.h"#include "dhcp-server-conf.h"#include "dhcp-server-defaults.h"#include "dhcp-options-strings.h"static const char *var_strings[] = {    "default-renew-percent",    "default-rebind-percent",    "poll-timeout"};static const arg_symbol_t var_symbols[] = {    SERVER_VAR_RENEW_PERCENT,    SERVER_VAR_REBIND_PERCENT,    SERVER_VAR_POLL_TIMEOUT,};static const arg_type_t     var_arg_types[] = { CONF_IDENTIFIER, CONF_ASSIGNMENT, CONF_STRING };static const char         **var_arg_strings[] = { var_strings, NULL, NULL };static const arg_symbol_t  *var_arg_symbols[] = { var_symbols, NULL, NULL };static const arg_type_t     range_lease_arg_types[] = {  CONF_ADDRESS, CONF_ADDRESS, CONF_GROUP};static const char         **range_lease_arg_strings[] = { NULL, NULL, NULL };static const arg_symbol_t  *range_lease_arg_symbols[] = { NULL, NULL, NULL };static const arg_type_t     hostname_lease_arg_types[] = {  CONF_STRING, CONF_ADDRESS, CONF_GROUP};static const char         **hostname_lease_arg_strings[] = { NULL, NULL, NULL };static const arg_symbol_t  *hostname_lease_arg_symbols[] = { NULL, NULL, NULL };static const arg_type_t     mac_lease_arg_types[] = {  CONF_MAC_ADDRESS, CONF_ADDRESS, CONF_GROUP};static const char         **mac_lease_arg_strings[] = { NULL, NULL, NULL };static const arg_symbol_t  *mac_lease_arg_symbols[] = { NULL, NULL, NULL };static const arg_type_t     option_arg_types[] = {  CONF_STRING, CONF_ASSIGNMENT, CONF_STRING_LIST };static const char         **option_arg_strings[] = { NULL, NULL, NULL };static const arg_symbol_t  *option_arg_symbols[] = { NULL, NULL, NULL };/* command structures. *//* set command. */static const command_t command_set = {    DIRECTIVE_SET,    "set",    3,    var_arg_strings,    var_arg_types,    var_arg_symbols,};/* range-lease command. */static const command_t command_range_lease = {    DIRECTIVE_RANGE_LEASE,    "range-lease",    3,    range_lease_arg_strings,    range_lease_arg_types,    range_lease_arg_symbols,};/* hostname-lease command. */static const command_t command_hostname_lease = {    DIRECTIVE_HOSTNAME_LEASE,    "hostname-lease",    3,    hostname_lease_arg_strings,    hostname_lease_arg_types,    hostname_lease_arg_symbols,};/* mac-lease command. */static const command_t command_mac_lease = {    DIRECTIVE_MAC_LEASE,    "mac-lease",    3,    mac_lease_arg_strings,    mac_lease_arg_types,    mac_lease_arg_symbols,};static const command_t command_option = {    DIRECTIVE_OPTION,    "option",    3,    option_arg_strings,    option_arg_types,    option_arg_symbols,};static const command_t *commands[] = {    &command_set,    &command_range_lease,    &command_hostname_lease,    &command_mac_lease,    &command_option,    NULL,};/* forward declaration of directive handlers. */static int directive_set_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data);static int directive_range_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data);static int directive_option_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data);static int directive_hostname_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data);static int directive_hw_address_handler(server_conf_t *server_conf, directive_t *directive, int group_type, void *group_data);/* indexed by directive types in dhcp-client-conf.h . */directive_handler_t directive_handlers[] = {    directive_set_handler,    directive_range_handler,    directive_hostname_handler,    directive_hw_address_handler,    directive_option_handler,};/* accessors. */uint16_t server_conf_get_poll_timeout(server_conf_t *sc){    return sc->poll_timeout;}/* * * * * * * * * * * * utility routines. * * * * * * * * * * * *//* get name of configuration file for server. */static char *get_conf_options_fname(const char *interface){    char *fname;    stringbuffer_t *sb;    sb = stringbuffer_create();    stringbuffer_aprintf(sb, "%s/default.conf", DHCPSYSCONF_SERVERDIR);    if(file_exists(stringbuffer_getstring(sb))) {        fname = xstrdup(stringbuffer_getstring(sb));        stringbuffer_destroy(sb);        return fname;    }    stringbuffer_clear(sb);    stringbuffer_aprintf(sb, "%s/%s.conf", DHCPSYSCONF_SERVERDIR, interface);    if(file_exists(stringbuffer_getstring(sb))) {        fname = xstrdup(stringbuffer_getstring(sb));        stringbuffer_destroy(sb);        return fname;    }    /* otherwise there is no configuration file and this is     * bad. signal a fatal error. */    FATAL_MESSAGE("configuration file missing -- looked for default.conf and <interface>.conf. exiting...");    exit(1); /* get rid of compiler warning. */}/* set variable. */static int server_conf_set_variable(server_conf_t *server_conf, arg_symbol_t var_symbol, const char *var_value){    switch(var_symbol) {    case SERVER_VAR_RENEW_PERCENT:        if(!is_unsigned_numeric(var_value))  {            ERROR_MESSAGE("value not unsigned numeric as expected : %s\n", var_value);            return 1;        }        sscanf(var_value, "%"SCNu16, &server_conf->default_renew_percent);        if(server_conf->default_renew_percent > 100) { /* check if the percent is higher than it should be. */            FATAL_MESSAGE("value specified for default-renew-percent is an illegal percent (over 100)");        }        break;    case SERVER_VAR_REBIND_PERCENT:        if(!is_unsigned_numeric(var_value))  {            ERROR_MESSAGE("value not unsigned numeric as expected : %s", var_value);            return 1;        }        sscanf(var_value, "%"SCNu16, &server_conf->default_rebind_percent);        if(server_conf->default_renew_percent > 100) { /* check if the percent is higher than it should be. */            FATAL_MESSAGE("value specified for default-rebind-percent is an illegal percent (over 100)");        }        break;    case SERVER_VAR_POLL_TIMEOUT:        if(!is_unsigned_numeric(var_value))  {            ERROR_MESSAGE("value not unsigned numeric as expected : %s\n", var_value);            return 1;        }        sscanf(var_value, "%"SCNu16, &server_conf->poll_timeout);        break;    default:                ERROR_MESSAGE("unable to understand assignment value of : %s", var_value);        return 1;    }    return 0;}/* load server options. */static int server_conf_load_options(server_conf_t *sc){    conf_t *conf;    list_t *directives;    directive_t *directive;    conf = conf_create(commands, sc->conf_file);    if(conf_compile_directives(conf) == CONF_ERROR) {        ERROR_MESSAGE("error reading conf file: %s at line %d", sc->conf_file, conf_get_line_no(conf));        conf_destroy(conf);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -