-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathNames.php
More file actions
108 lines (90 loc) · 2.26 KB
/
Copy pathNames.php
File metadata and controls
108 lines (90 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare(strict_types=1);
/**
* DNS Library for handling lookups and updates.
*
* Copyright (c) 2022, Mike Pultz <mike@mikepultz.com>. All rights reserved.
*
* See LICENSE for more details.
*
* @category Networking
* @package Net_DNS2
* @author Mike Pultz <mike@mikepultz.com>
* @copyright 2022 Mike Pultz <mike@mikepultz.com>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link https://netdns2.com/
* @since File available since Release 1.5.3
*
*/
/**
* text compression/expansion and labeling class
*
*/
class Net_DNS2_Names
{
/**
* pack a text string
*
* @param string $name a name to be packed
*
* @return string
* @access public
*
*/
public static function pack($name)
{
return (is_null($name) == true) ? null : pack('Ca*', strlen($name), $name);
}
/**
* returns the canonical wire-format representation of the domain name
*
* @param string $name a name to be packed
*
* @return string
* @access public
*
*/
public static function canonical($name)
{
$names = explode('.', $name);
$compname = '';
while (!empty($names)) {
$first = array_shift($names);
$length = strlen($first);
$compname .= pack('Ca*', $length, $first);
}
$compname .= "\0";
return $compname;
}
/**
* parses a domain string into a single string
*
* @param string $rdata the DNS packet to look in for the domain name
* @param integer &$offset the offset into the given packet object
*
* @return mixed either a name string or null if it's not found.
* @access public
*
*/
public static function unpack($rdata, &$offset)
{
if ($offset > strlen($rdata))
{
return null;
}
$name = '';
$len = ord($rdata[$offset]);
if ($len == 0)
{
return null;
}
$offset++;
if ( ($len + $offset) > strlen($rdata)) {
$name = substr($rdata, $offset);
} else {
$name = substr($rdata, $offset, $len);
}
$offset += strlen($name);
return $name;
}
}