Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit ec41145

Browse files
committedNov 24, 2009
Add beginning code for the DHCPLEASEQUERY command. Currently, it doesn't seem to want to work. Also add licensing info.
1 parent e343367 commit ec41145

File tree

7 files changed

+338
-2
lines changed

7 files changed

+338
-2
lines changed
 

‎LICENSE

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
2+
3+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
4+
5+
1. Definitions.
6+
7+
"License" shall mean the terms and conditions for use, reproduction, and
8+
distribution as defined by Sections 1 through 9 of this document.
9+
10+
"Licensor" shall mean the copyright owner or entity authorized by the
11+
copyright owner that is granting the License.
12+
13+
"Legal Entity" shall mean the union of the acting entity and all other
14+
entities that control, are controlled by, or are under common control with
15+
that entity. For the purposes of this definition, "control" means (i) the
16+
power, direct or indirect, to cause the direction or management of such
17+
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
18+
(50%) or more of the outstanding shares, or (iii) beneficial ownership of such
19+
entity.
20+
21+
"You" (or "Your") shall mean an individual or Legal Entity exercising
22+
permissions granted by this License.
23+
24+
"Source" form shall mean the preferred form for making modifications,
25+
including but not limited to software source code, documentation source, and
26+
configuration files.
27+
28+
"Object" form shall mean any form resulting from mechanical transformation or
29+
translation of a Source form, including but not limited to compiled object
30+
code, generated documentation, and conversions to other media types.
31+
32+
"Work" shall mean the work of authorship, whether in Source or Object form,
33+
made available under the License, as indicated by a copyright notice that is
34+
included in or attached to the work (an example is provided in the Appendix
35+
below).
36+
37+
"Derivative Works" shall mean any work, whether in Source or Object form, that
38+
is based on (or derived from) the Work and for which the editorial revisions,
39+
annotations, elaborations, or other modifications represent, as a whole, an
40+
original work of authorship. For the purposes of this License, Derivative
41+
Works shall not include works that remain separable from, or merely link (or
42+
bind by name) to the interfaces of, the Work and Derivative Works thereof.
43+
44+
"Contribution" shall mean any work of authorship, including the original
45+
version of the Work and any modifications or additions to that Work or
46+
Derivative Works thereof, that is intentionally submitted to Licensor for
47+
inclusion in the Work by the copyright owner or by an individual or Legal
48+
Entity authorized to submit on behalf of the copyright owner. For the purposes
49+
of this definition, "submitted" means any form of electronic, verbal, or
50+
written communication sent to the Licensor or its representatives, including
51+
but not limited to communication on electronic mailing lists, source code
52+
control systems, and issue tracking systems that are managed by, or on behalf
53+
of, the Licensor for the purpose of discussing and improving the Work, but
54+
excluding communication that is conspicuously marked or otherwise designated
55+
in writing by the copyright owner as "Not a Contribution."
56+
57+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58+
of whom a Contribution has been received by Licensor and subsequently
59+
incorporated within the Work.
60+
61+
2. Grant of Copyright License. Subject to the terms and conditions of this
62+
License, each Contributor hereby grants to You a perpetual, worldwide,
63+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
65+
sublicense, and distribute the Work and such Derivative Works in Source or
66+
Object form.
67+
68+
3. Grant of Patent License. Subject to the terms and conditions of this
69+
License, each Contributor hereby grants to You a perpetual, worldwide,
70+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
71+
section) patent license to make, have made, use, offer to sell, sell, import,
72+
and otherwise transfer the Work, where such license applies only to those
73+
patent claims licensable by such Contributor that are necessarily infringed by
74+
their Contribution(s) alone or by combination of their Contribution(s) with
75+
the Work to which such Contribution(s) was submitted. If You institute patent
76+
litigation against any entity (including a cross-claim or counterclaim in a
77+
lawsuit) alleging that the Work or a Contribution incorporated within the Work
78+
constitutes direct or contributory patent infringement, then any patent
79+
licenses granted to You under this License for that Work shall terminate as of
80+
the date such litigation is filed.
81+
82+
4. Redistribution. You may reproduce and distribute copies of the Work or
83+
Derivative Works thereof in any medium, with or without modifications, and in
84+
Source or Object form, provided that You meet the following conditions:
85+
86+
You must give any other recipients of the Work or Derivative Works a copy of
87+
this License; and
88+
89+
You must cause any modified files to carry prominent notices stating that You
90+
changed the files; and
91+
92+
You must retain, in the Source form of any Derivative Works that You
93+
distribute, all copyright, patent, trademark, and attribution notices from the
94+
Source form of the Work, excluding those notices that do not pertain to any
95+
part of the Derivative Works; and
96+
97+
If the Work includes a "NOTICE" text file as part of its distribution, then
98+
any Derivative Works that You distribute must include a readable copy of the
99+
attribution notices contained within such NOTICE file, excluding those notices
100+
that do not pertain to any part of the Derivative Works, in at least one of
101+
the following places: within a NOTICE text file distributed as part of the
102+
Derivative Works; within the Source form or documentation, if provided along
103+
with the Derivative Works; or, within a display generated by the Derivative
104+
Works, if and wherever such third-party notices normally appear. The contents
105+
of the NOTICE file are for informational purposes only and do not modify the
106+
License. You may add Your own attribution notices within Derivative Works that
107+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
108+
provided that such additional attribution notices cannot be construed as
109+
modifying the License. You may add Your own copyright statement to Your
110+
modifications and may provide additional or different license terms and
111+
conditions for use, reproduction, or distribution of Your modifications, or
112+
for any such Derivative Works as a whole, provided Your use, reproduction, and
113+
distribution of the Work otherwise complies with the conditions stated in this
114+
License. 5. Submission of Contributions. Unless You explicitly state
115+
otherwise, any Contribution intentionally submitted for inclusion in the Work
116+
by You to the Licensor shall be under the terms and conditions of this
117+
License, without any additional terms or conditions. Notwithstanding the
118+
above, nothing herein shall supersede or modify the terms of any separate
119+
license agreement you may have executed with Licensor regarding such
120+
Contributions.
121+
122+
6. Trademarks. This License does not grant permission to use the trade names,
123+
trademarks, service marks, or product names of the Licensor, except as
124+
required for reasonable and customary use in describing the origin of the Work
125+
and reproducing the content of the NOTICE file.
126+
127+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
128+
writing, Licensor provides the Work (and each Contributor provides its
129+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
130+
KIND, either express or implied, including, without limitation, any warranties
131+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
132+
PARTICULAR PURPOSE. You are solely responsible for determining the
133+
appropriateness of using or redistributing the Work and assume any risks
134+
associated with Your exercise of permissions under this License.
135+
136+
8. Limitation of Liability. In no event and under no legal theory, whether in
137+
tort (including negligence), contract, or otherwise, unless required by
138+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
139+
writing, shall any Contributor be liable to You for damages, including any
140+
direct, indirect, special, incidental, or consequential damages of any
141+
character arising as a result of this License or out of the use or inability
142+
to use the Work (including but not limited to damages for loss of goodwill,
143+
work stoppage, computer failure or malfunction, or any and all other
144+
commercial damages or losses), even if such Contributor has been advised of
145+
the possibility of such damages.
146+
147+
9. Accepting Warranty or Additional Liability. While redistributing the Work
148+
or Derivative Works thereof, You may choose to offer, and charge a fee for,
149+
acceptance of support, warranty, indemnity, or other liability obligations
150+
and/or rights consistent with this License. However, in accepting such
151+
obligations, You may act only on Your own behalf and on Your sole
152+
responsibility, not on behalf of any other Contributor, and only if You agree
153+
to indemnify, defend, and hold each Contributor harmless for any liability
154+
incurred by, or claims asserted against, such Contributor by reason of your
155+
accepting any such warranty or additional liability.
156+
157+
END OF TERMS AND CONDITIONS

‎leasequery.php

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/*
3+
Copyright 2009 Angelo R. DiNardi (angelo@dinardi.name)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
require_once "packet.php";
19+
20+
class dhcpQuery {
21+
private $socket = null;
22+
private $responseSocket = null;
23+
private $storage = null;
24+
25+
function __construct() {
26+
// $this->storage = new dhcpStorage();
27+
28+
$this->socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
29+
socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1);
30+
// socket_set_option($this->socket, SOL_SOCKET, SO_BROADCAST, 1);
31+
socket_bind($this->socket, "129.21.50.223", 68);
32+
33+
}
34+
35+
function listen() {
36+
$this->send();
37+
while(1) {
38+
print('waiting...' . "\n");
39+
$data = socket_read($this->socket, 4608);
40+
print('got data' . "\n");
41+
$this->processPacket($data);
42+
}
43+
}
44+
45+
function send() {
46+
$response = new dhcpPacket();
47+
48+
$response->setData('op', dhcpPacket::int2hex(1));
49+
$response->setData('xid', '12345678');
50+
// $response->setData('chaddr', );
51+
$response->setData('htype', '00');
52+
$response->setData('hlen', '00');
53+
$response->setData('ciaddr', dhcpPacket::ip2hex(array(129, 21, 50, 223)));
54+
55+
$response->setData('message_type', 'DHCPLEASEQUERY');
56+
57+
$responseData = $response->build();
58+
59+
$error = socket_sendto($this->socket, $responseData, strlen($responseData), 0, '129.21.49.137', 67);
60+
print_r($error);
61+
if ($error === FALSE) {
62+
print("Send failed for address");
63+
}
64+
}
65+
66+
function processPacket($packetData) {
67+
$packet = new dhcpPacket();
68+
$packet->parse($packetData);
69+
70+
print_r($packet);
71+
// $processor = new dhcpRequestProcessor($this->storage, $packet);
72+
//
73+
// $responsePacket = $processor->getResponse();
74+
// $responseData = $responsePacket->build();
75+
// print("sending response" . "\n");
76+
// $ciaddr = $packet->getClientAddress();
77+
// if ($ciaddr == '0.0.0.0') {
78+
// print("Switching to broadcast address...\n");
79+
// $ciaddr = '255.255.255.255';
80+
// }
81+
// print("attempting to send packet to " . $ciaddr . "\n");
82+
// $error = socket_sendto($this->socket, $responseData, strlen($responseData), 0, $ciaddr, 68);
83+
// if ($error === FALSE) {
84+
// print("send failed for specific address, broadcast.\n");
85+
// $error = socket_sendto($this->socket, $responseData, strlen($responseData), 0, "255.255.255.255", 68);
86+
// }
87+
// print('socket send error: ' . $error . "\n");
88+
}
89+
}
90+
91+
92+
require_once "packet.php";
93+
require_once "server.php";
94+
require_once "requestProcessor.php";
95+
require_once "storage.php";
96+
97+
$server = new dhcpQuery();
98+
$server->listen();

‎listen.php

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
Copyright 2009 Angelo R. DiNardi (angelo@dinardi.name)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
217

318
require_once "packet.php";
419
require_once "server.php";

‎packet.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
Copyright 2009 Angelo R. DiNardi (angelo@dinardi.name)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
217

318
class dhcpPacket {
419
public static $options = array(
@@ -17,7 +32,9 @@ class dhcpPacket {
1732
57 => array('name' => 'max_message_size', 'type' => 'int'),
1833
58 => array('name' => 'renewal_time', 'type' => 'int'),
1934
59 => array('name' => 'rebinding_time', 'type' => 'int'),
20-
61 => array('name' => 'client_id', 'type' => 'mac')
35+
61 => array('name' => 'client_id', 'type' => 'mac'),
36+
91 => array('name' => 'client-last-transaction-time', 'type' => 'int'),
37+
92 => array('name' => 'associated-ip', 'type' => 'string')
2138
);
2239
public static $messageTypes = array(
2340
1 => 'discover',
@@ -27,7 +44,11 @@ class dhcpPacket {
2744
5 => 'ack',
2845
6 => 'nak',
2946
7 => 'release',
30-
8 => 'inform'
47+
8 => 'inform',
48+
10 => 'DHCPLEASEQUERY',
49+
11 => 'DHCPLEASEUNASSIGNED',
50+
12 => 'DHCPLEASEUNKNOWN',
51+
13 => 'DHCPLEASEACTIVE'
3152
);
3253
public $packetData = array(
3354
'op' => '02',

‎requestProcessor.php

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
Copyright 2009 Angelo R. DiNardi (angelo@dinardi.name)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
217

318
class dhcpRequestProcessor {
419
private $packet = null;

‎server.php

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
Copyright 2009 Angelo R. DiNardi (angelo@dinardi.name)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
217

318
require_once "packet.php";
419

‎storage.php

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
Copyright 2009 Angelo R. DiNardi (angelo@dinardi.name)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
217

318
class dhcpStorage {
419
function getAttributesForClient($mac) {

0 commit comments

Comments
 (0)
This repository has been archived.