dhcp-server-control.c

来自「this is sample about DHCP-agent」· C语言 代码 · 共 95 行

C
95
字号
/* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-server-control.c,v 1.3 2003/07/08 07:05:07 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-control"#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"dhcp_server_control_t *dhcp_server_control_create(const char *interface){    int dport, sport;    stringbuffer_t *filter;    dhcp_server_control_t *dhcp_server_control;    dhcp_server_control = xcalloc(sizeof(dhcp_server_control_t));    dhcp_server_control->interface = xstrdup(interface);    /* read configuration information. */    if((dhcp_server_control->server_conf = server_conf_create(interface)) == NULL) {        FATAL_MESSAGE("could not read configuration file");    }    /* get the source port and destination port for BOOTP. */    dport = rawnet_port_for_service("bootps", "udp");    sport = rawnet_port_for_service("bootpc", "udp");    dport = ntohs(dport);    sport = ntohs(sport);    if(dport == -1 || sport == -1) {        WARN_MESSAGE            ("could not lookup dhcp services in service db (%s) will use reasonable defaults.");        sport = BOOTP_CLIENT;        dport = BOOTP_SERVER;    }    /* Create filter. */    filter = stringbuffer_create();    stringbuffer_aprintf(filter, "arp or icmp or (udp and src port %d)", sport);    /* create rawnet handler. */    if((dhcp_server_control->rawnet = rawnet_create(interface, stringbuffer_getstring(filter), -1, sport,                                                     dport, 0, 0)) == NULL) {        FATAL_MESSAGE("could not create raw network handler.");    }    stringbuffer_destroy(filter);        return dhcp_server_control;}void dhcp_server_control_destroy(dhcp_server_control_t *sc){    if(sc->interface)        xfree(sc->interface);    if(sc->server_conf)        server_conf_destroy(sc->server_conf);    if(sc->rawnet)        rawnet_destroy(sc->rawnet);    xfree(sc);    return;}

⌨️ 快捷键说明

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