-
Notifications
You must be signed in to change notification settings - Fork 21
/
IpInterface.php
209 lines (184 loc) · 4.88 KB
/
IpInterface.php
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
namespace Darsyn\IP;
interface IpInterface
{
/**
* @param string $ip
* @throws \Darsyn\IP\Exception\InvalidIpAddressException
* @throws \Darsyn\IP\Exception\WrongVersionException
* @return static
*/
public static function factory($ip);
/**
* Get Binary Representation
*
* @return string
*/
public function getBinary();
/**
* Do two IP objects represent the same IP address?
*
* @param \Darsyn\IP\IpInterface $ip
* @return bool
*/
public function equals(IpInterface $ip);
/**
* Get the IP version from the binary value
*
* @return int
*/
public function getVersion();
/**
* Is Version?
*
* @param int $version
* @return bool
*/
public function isVersion($version);
/**
* Whether the IP is version 4
*
* @return bool
*/
public function isVersion4();
/**
* Whether the IP is version 6
*
* @return bool
*/
public function isVersion6();
/**
* Get Network Address
*
* Get a new value object from the network address of the original IP.
*
* @param int $cidr
* @throws \Darsyn\IP\Exception\InvalidCidrException
* @return static
*/
public function getNetworkIp($cidr);
/**
* Get Broadcast Address
*
* Get a new value object from the broadcast address of the original IP.
*
* @param int $cidr
* @throws \Darsyn\IP\Exception\InvalidCidrException
* @return static
*/
public function getBroadcastIp($cidr);
/**
* Is IP Address In Range?
*
* Returns a boolean value depending on whether the IP address in question
* is within the range of the target IP/CIDR combination.
* Comparing two IPs of different byte-lengths (IPv4 vs IPv6/IPv4-embedded)
* will throw a WrongVersionException.
*
* @param \Darsyn\IP\IpInterface $ip
* @param int $cidr
* @throws \Darsyn\IP\Exception\InvalidCidrException
* @throws \Darsyn\IP\Exception\WrongVersionException
* @return bool
*/
public function inRange(IpInterface $ip, $cidr);
/**
* Get Common CIDR Between IP Addresses
*
* Returns the highest common CIDR between the current IP address and another
*
* @param \Darsyn\IP\IpInterface $ip
* @throws \Darsyn\IP\Exception\WrongVersionException
* @return int
*/
public function getCommonCidr(IpInterface $ip);
/**
* Whether the IP is an IPv4-mapped IPv6 address (eg, "::ffff:7f00:1").
*
* @return bool
*/
public function isMapped();
/**
* Whether the IP is a 6to4-derived address (eg, "2002:7f00:1::").
*
* @return bool
*/
public function isDerived();
/**
* Whether the IP is an IPv4-compatible IPv6 address (eg, `::7f00:1`).
*
* @return bool
*/
public function isCompatible();
/**
* Whether the IP is an IPv4-embedded IPv6 address (according to the
* embedding strategy used).
*
* @return bool
*/
public function isEmbedded();
/**
* Whether the IP is reserved for link-local usage, according to
* RFC 3927/RFC 4291 (IPv4/IPv6).
*
* @return bool
*/
public function isLinkLocal();
/**
* Whether the IP is a loopback address, according to RFC 2373/RFC 3330
* (IPv4/IPv6).
*
* @return bool
*/
public function isLoopback();
/**
* Whether the IP is a multicast address, according to RFC 3171/RFC 2373
* (IPv4/IPv6).
*
* @return bool
*/
public function isMulticast();
/**
* Whether the IP is for private use, according to RFC 1918/RFC 4193
* (IPv4/IPv6).
*
* @return bool
*/
public function isPrivateUse();
/**
* Whether the IP is unspecified, according to RFC 5735/RFC 2373 (IPv4/IPv6).
*
* @return bool
*/
public function isUnspecified();
/**
* Whether the IP is reserved for network devices benchmarking, according
* to RFC 2544/RFC 5180 (IPv4/IPv6).
*
* @return bool
*/
public function isBenchmarking();
/**
* Whether the IP is in range designated for documentation, according to
* RFC 5737/RFC 3849 (IPv4/IPv6).
*
* @return bool
*/
public function isDocumentation();
/**
* Whether the IP appears to be publicly/globally routable. Please refer to
* the IANA Special-Purpose Address Registry documents.
*
* @see https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
* @see https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv6-special-registry.xhtml
*
* @return bool
*/
public function isPublicUse();
/**
* Implement string casting for IP objects.
*
* @return string
*/
public function __toString();
}