Source for file NS_DHCP_Handler.php
Documentation is available at NS_DHCP_Handler.php
* nanoserv handlers - DHCP protocol handler
* Copyright (C) 2004-2010 Vincent Negrier aka. sIX <six@aegis-corp.org>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Require the nanoserv core
require_once "nanoserv-compat/nanoserv.php";
* DHCP message decoding exception
* DCHP message options parser and builder class
if ($magic !== self::MAGIC_COOKIE) throw new NS_DHCP_Exception("unable to decode options, wrong magic cookie 0x" . dechex($magic));
} else if ($code === 255) {
$opt = substr($data, $cur + 2, $len);
list (,$tmp) = unpack("N", $opt);
list (,$tmp) = unpack("N", $opt);
static public function Decode($data) {
static public function Encode() {
* DHCP message parser and builder class
$tmp = unpack("Cop/Chtype/Chlen/Chops/Nxid/nsecs/nflags/Nciaddr/Nyiaddr/Nsiaddr/Ngiaddr", $data);
$this->htype = $tmp["htype"];
$this->hlen = $tmp["hlen"];
$this->hops = $tmp["hops"];
$this->xid = $tmp["xid"];
$this->secs = $tmp["secs"];
$this->flags = $tmp["flags"];
case self::BOOTP_REQUEST: return "BOOTPREQUEST";
case self::BOOTP_REPLY: return "BOOTPREPLY";
default: return "unknown";
case self::HTYPE_ETHERNET: return "Ethernet";
default: return "unknown";
switch ($this->options->dhcp_msg_type) {
case self::DHCP_DISCOVER: return "DHCPDISCOVER";
case self::DHCP_OFFER: return "DHCPOFFER";
case self::DHCP_REQUEST: return "DHCPREQUEST";
case self::DHCP_DECLINE: return "DHCPDECLINE";
case self::DHCP_ACK: return "DHCPACK";
case self::DHCP_NAK: return "DHCPNAK";
case self::DHCP_RELEASE: return "DHCPRELEASE";
case self::DHCP_INFORM: return "DHCPINFORM";
default: return "unknown";
static public function Decode($data) {
static public function Encode() {
* DHCP protocol handler handler class
public function on_Read($from, $data) {
* Event called when a DHCP message is received
* @param string $from ip address and port of the sending side
* @param NS_DHCP_Message $msg
|