dhcp-server.c
来自「this is sample about DHCP-agent」· C语言 代码 · 共 237 行
C
237 行
/* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server.c,v 1.8 2003/07/15 10:57:18 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * 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"#include "dhcp-local.h"#include "dhcp-libutil.h"#include "dhcp-librawnet.h"#include "dhcp-lease.h"#include "dhcp-server-conf.h"#include "dhcp-server.h"#include "dhcp-server-guile.h"/* global vars affecting other code. */char *work_dir = DHCPLOCALSTATE_SERVERDIR; /* our default working directory */#if !defined(HAVE_PROGNAME)const char *__progname;#endif /* HAVE_PROGNAME */static unsigned char want_background = 1; /* whether we should go into the background. */static void do_version(char *interface);static void do_status(char *interface_name);static void do_kill(char *interface_name);static void do_server(char *interface_name);static void do_check_config(char *interface_name);static const char *command_string[] = { "version", "kill", "status", "do server", "checkconfig"};/* table of functions indexed by command codes. */server_command commands[] = { do_version, /* print out version information. */ do_kill, /* kill server. */ do_status, /* do status. */ do_server, /* do server. */ do_check_config, /* check configuration. */};server_state server_states[] = { NULL, server_shutdown,};/* print usage info. */static void usage(char *s){ INFO_MESSAGE("usage: %s [-caks] [-l verbosity level]\n", s); exit(0);}/* print out version information and exit. */static void do_version(char *interface){ INFO_MESSAGE("%s version: %s\n", getprogname(), VERSION);}static void do_status(char *interface_name){ INFO_MESSAGE("not implemented yet."); return;}static void do_kill(char *interface_name){ INFO_MESSAGE("not implemented yet."); return;}static void do_server(char *interface){ dhcp_server_control_t *dhcp_server_control; INFO_MESSAGE("DHCP server starting"); /* we go into the background immediately. */ if(want_background) { INFO_MESSAGE("going into the background"); set_interactive(0); go_background(work_dir); } dhcp_server_control = dhcp_server_control_create(interface); if(file_create_pid(interface)) { ERROR_MESSAGE("could not create PID file for interface: %s", interface); server_states[STATE_SHUTDOWN](dhcp_server_control); } server_states[STATE_SHUTDOWN](dhcp_server_control);}static void do_check_config(char *interface){ server_conf_t *server_conf; lease_definition_t *lease_def; server_conf = server_conf_create(interface); if(server_conf == NULL) { FATAL_MESSAGE("error while reading server conf."); } /* dump out configuration information. */ INFO_MESSAGE("Server configuration:"); INFO_MESSAGE(" "); INFO_MESSAGE("default-rebind-percent: %d", server_conf->default_rebind_percent); INFO_MESSAGE("default-renew-percent: %d", server_conf->default_renew_percent); INFO_MESSAGE(" "); INFO_MESSAGE("Lease definitions:"); INFO_MESSAGE(" "); list_rewind(server_conf->lease_defs); while((lease_def = list_next(server_conf->lease_defs)) != NULL) { pretty_print_lease_def(lease_def); }}/* main function: called from scm_boot_guile */static void real_main(void *closure, int argc, char *argv[]){ int c, command_code = DO_SERVER; char *interface_name = NULL; list_t *interface_list; INFO_MESSAGE("(C) 2003 Thamer Al-Harbash <tmh@whitefang.com>"); INFO_MESSAGE("See LICENSE file for details."); INFO_MESSAGE(" "); while((c = getopt(argc, argv, "cvskai:l:")) != -1) { switch(c) { case 'k': /* kill server. */ command_code = DO_KILL; break; case 's': command_code = DO_STATUS; break; case 'c': command_code = DO_CHECK_CONFIG; break; case 'v': command_code = DO_VERSION; break; case 'i': interface_name = xstrdup(optarg); break; case 'a': /* don't fork into the background. */ want_background = 0; break; case 'l': if(!is_signed_numeric(optarg) || set_verbosity_level(atoi(optarg))) { ERROR_MESSAGE("illegal verbosity level: %s", optarg); exit(1); } break; default: usage(argv[0]); } } /* if all the user wants is version information, give it to him. */ if(command_code == DO_VERSION) { do_version(NULL); exit(0); } /* otherwise anything else requires an up interface. */ if(interface_name == NULL) { interface_list = rawnet_list_active_interfaces(); if(list_get_len(interface_list) == 0) { ERROR_MESSAGE("could not find suitable interface to use while running command: %s", command_string[command_code]); } interface_name = xstrdup(list_first(interface_list)); list_destroy(interface_list, xfree); } do_change_work_dir(work_dir); /* now that we have an active interface name, go ahead * and run the server command. */ commands[command_code](interface_name); exit(0);}/* actual main: boot guile up so it knows where the bottom of the stack is. */int main(int argc, char *argv[]){ scm_boot_guile(argc, argv, real_main, NULL); /* get rid of compiler warning. */ exit(1);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?