1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5 <title>Reference</title>
6 <link rel="stylesheet" href="../luadoc.css" type="text/css" />
7 <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
14 <div id="product_logo"></div>
15 <div id="product_name"><big><b></b></big></div>
16 <div id="product_description"></div>
17 </div> <!-- id="product" -->
27 <li><a href="../index.html">Index</a></li>
38 <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
42 <a href="../modules/luci.http.html">luci.http</a>
46 <a href="../modules/luci.http.protocol.html">luci.http.protocol</a>
50 <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
54 <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
58 <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
62 <a href="../modules/luci.i18n.html">luci.i18n</a>
66 <a href="../modules/luci.ip.html">luci.ip</a>
69 <li><strong>luci.ip.cidr</strong></li>
72 <a href="../modules/luci.json.html">luci.json</a>
76 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
80 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
84 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
88 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
92 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
96 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
100 <a href="../modules/luci.sys.html">luci.sys</a>
104 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
108 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
112 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
116 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
120 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
124 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
128 <a href="../modules/luci.util.html">luci.util</a>
132 <a href="../modules/nixio.html">nixio</a>
136 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
140 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
144 <a href="../modules/nixio.File.html">nixio.File</a>
148 <a href="../modules/nixio.README.html">nixio.README</a>
152 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
156 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
160 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
164 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
168 <a href="../modules/nixio.bin.html">nixio.bin</a>
172 <a href="../modules/nixio.bit.html">nixio.bit</a>
176 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
180 <a href="../modules/nixio.fs.html">nixio.fs</a>
195 </div><!-- id="navigation" -->
199 <h1>Object Instance <code>luci.ip.cidr</code></h1>
203 Represents an IPv4 or IPv6 address range.</p>
212 <table class="function_list">
215 <td class="name" nowrap><a href="#cidr.is4">cidr:is4</a> ()</td>
218 Checks whether the CIDR instance is an IPv4 address range
223 <td class="name" nowrap><a href="#cidr.is4rfc1918">cidr:is4rfc1918</a> ()</td>
226 Checks whether the CIDR instance is within the private RFC1918 address space
231 <td class="name" nowrap><a href="#cidr.is4linklocal">cidr:is4linklocal</a> ()</td>
234 Checks whether the CIDR instance is an IPv4 link local (Zeroconf) address
239 <td class="name" nowrap><a href="#cidr.is6">cidr:is6</a> ()</td>
242 Checks whether the CIDR instance is an IPv6 address range
247 <td class="name" nowrap><a href="#cidr.is6linklocal">cidr:is6linklocal</a> ()</td>
250 Checks whether the CIDR instance is an IPv6 link local address
255 <td class="name" nowrap><a href="#cidr.is6mapped4">cidr:is6mapped4</a> ()</td>
258 Checks whether the CIDR instance is an IPv6 mapped IPv4 address
263 <td class="name" nowrap><a href="#cidr.ismac">cidr:ismac</a> ()</td>
266 Checks whether the CIDR instance is an ethernet MAC address range
271 <td class="name" nowrap><a href="#cidr.ismaclocal">cidr:ismaclocal</a> ()</td>
274 Checks whether the CIDR instance is a locally administered (LAA) MAC address
279 <td class="name" nowrap><a href="#cidr.ismacmcast">cidr:ismacmcast</a> ()</td>
282 Checks whether the CIDR instance is a multicast MAC address
287 <td class="name" nowrap><a href="#cidr.lower">cidr:lower</a> (addr)</td>
290 Checks whether this CIDR instance is lower than the given argument.</td>
294 <td class="name" nowrap><a href="#cidr.higher">cidr:higher</a> (addr)</td>
297 Checks whether this CIDR instance is higher than the given argument.</td>
301 <td class="name" nowrap><a href="#cidr.equal">cidr:equal</a> (addr)</td>
304 Checks whether this CIDR instance is equal to the given argument.</td>
308 <td class="name" nowrap><a href="#cidr.prefix">cidr:prefix</a> (mask)</td>
311 Get or set prefix size of CIDR instance.</td>
315 <td class="name" nowrap><a href="#cidr.network">cidr:network</a> (mask)</td>
318 Derive network address of CIDR instance.</td>
322 <td class="name" nowrap><a href="#cidr.host">cidr:host</a> ()</td>
325 Derive host address of CIDR instance.</td>
329 <td class="name" nowrap><a href="#cidr.mask">cidr:mask</a> (mask)</td>
332 Derive netmask of CIDR instance.</td>
336 <td class="name" nowrap><a href="#cidr.broadcast">cidr:broadcast</a> (mask)</td>
339 Derive broadcast address of CIDR instance.</td>
343 <td class="name" nowrap><a href="#cidr.mapped4">cidr:mapped4</a> ()</td>
346 Derive mapped IPv4 address of CIDR instance.</td>
350 <td class="name" nowrap><a href="#cidr.tomac">cidr:tomac</a> ()</td>
353 Derive MAC address of IPv6 link local CIDR instance.</td>
357 <td class="name" nowrap><a href="#cidr.tolinklocal">cidr:tolinklocal</a> ()</td>
360 Derive IPv6 link local address from MAC address CIDR instance.</td>
364 <td class="name" nowrap><a href="#cidr.contains">cidr:contains</a> (addr)</td>
367 Test whether CIDR contains given range.</td>
371 <td class="name" nowrap><a href="#cidr.add">cidr:add</a> (amount, inplace)</td>
374 Add given amount to CIDR instance.</td>
378 <td class="name" nowrap><a href="#cidr.sub">cidr:sub</a> (amount, inplace)</td>
381 Subtract given amount from CIDR instance.</td>
385 <td class="name" nowrap><a href="#cidr.minhost">cidr:minhost</a> ()</td>
388 Calculate the lowest possible host address within this CIDR instance.</td>
392 <td class="name" nowrap><a href="#cidr.maxhost">cidr:maxhost</a> ()</td>
395 Calculate the highest possible host address within this CIDR instance.</td>
399 <td class="name" nowrap><a href="#cidr.string">cidr:string</a> ()</td>
402 Convert CIDR instance into string representation.</td>
416 <h2><a name="functions"></a>Functions</h2>
417 <dl class="function">
421 <dt><a name="cidr.is4"></a><strong>cidr:is4</strong> ()</dt>
425 Checks whether the CIDR instance is an IPv4 address range
434 <h3>Return value:</h3>
435 <code>true</code> if the CIDR is an IPv4 range, else <code>false</code>
442 <li><a href="#cidr.is6">
446 <li><a href="#cidr.ismac">
457 <dt><a name="cidr.is4rfc1918"></a><strong>cidr:is4rfc1918</strong> ()</dt>
461 Checks whether the CIDR instance is within the private RFC1918 address space
469 <pre>local addr = luci.ip.new("192.168.45.2/24")
470 if addr:is4rfc1918() then
471 print("Is a private address")
476 <h3>Return value:</h3>
477 <code>true</code> if the entire range of this CIDR lies within one of
478 the ranges <code>10.0.0.0-10.255.255.255</code>,
479 <code>172.16.0.0-172.31.0.0</code> or
480 <code>192.168.0.0-192.168.255.255</code>, else <code>false</code>.
489 <dt><a name="cidr.is4linklocal"></a><strong>cidr:is4linklocal</strong> ()</dt>
493 Checks whether the CIDR instance is an IPv4 link local (Zeroconf) address
501 <pre>local addr = luci.ip.new("169.254.34.125")
502 if addr:is4linklocal() then
503 print("Is a zeroconf address")
508 <h3>Return value:</h3>
509 <code>true</code> if the entire range of this CIDR lies within the range
510 the range <code>169.254.0.0-169.254.255.255</code>, else <code>false</code>.
519 <dt><a name="cidr.is6"></a><strong>cidr:is6</strong> ()</dt>
523 Checks whether the CIDR instance is an IPv6 address range
532 <h3>Return value:</h3>
533 <code>true</code> if the CIDR is an IPv6 range, else <code>false</code>
540 <li><a href="#cidr.is4">
544 <li><a href="#cidr.ismac">
555 <dt><a name="cidr.is6linklocal"></a><strong>cidr:is6linklocal</strong> ()</dt>
559 Checks whether the CIDR instance is an IPv6 link local address
567 <pre>local addr = luci.ip.new("fe92:53a:3216:af01:221:63ff:fe75:aa17/64")
568 if addr:is6linklocal() then
569 print("Is a linklocal address")
574 <h3>Return value:</h3>
575 <code>true</code> if the entire range of this CIDR lies within the range
576 the <code>fe80::/10</code> range, else <code>false</code>.
585 <dt><a name="cidr.is6mapped4"></a><strong>cidr:is6mapped4</strong> ()</dt>
589 Checks whether the CIDR instance is an IPv6 mapped IPv4 address
597 <pre>local addr = luci.ip.new("::ffff:192.168.1.1")
598 if addr:is6mapped4() then
599 print("Is a mapped IPv4 address")
604 <h3>Return value:</h3>
605 <code>true</code> if the address is an IPv6 mapped IPv4 address in the
606 form <code>::ffff:1.2.3.4</code>.
615 <dt><a name="cidr.ismac"></a><strong>cidr:ismac</strong> ()</dt>
619 Checks whether the CIDR instance is an ethernet MAC address range
628 <h3>Return value:</h3>
629 <code>true</code> if the CIDR is a MAC address range, else <code>false</code>
636 <li><a href="#cidr.is4">
640 <li><a href="#cidr.is6">
651 <dt><a name="cidr.ismaclocal"></a><strong>cidr:ismaclocal</strong> ()</dt>
655 Checks whether the CIDR instance is a locally administered (LAA) MAC address
663 <pre>local mac = luci.ip.new("02:C0:FF:EE:00:01")
664 if mac:ismaclocal() then
665 print("Is an LAA MAC address")
670 <h3>Return value:</h3>
671 <code>true</code> if the MAC address sets the locally administered bit.
680 <dt><a name="cidr.ismacmcast"></a><strong>cidr:ismacmcast</strong> ()</dt>
684 Checks whether the CIDR instance is a multicast MAC address
692 <pre>local mac = luci.ip.new("01:00:5E:7F:00:10")
693 if addr:ismacmcast() then
694 print("Is a multicast MAC address")
699 <h3>Return value:</h3>
700 <code>true</code> if the MAC address sets the multicast bit.
709 <dt><a name="cidr.lower"></a><strong>cidr:lower</strong> (addr)</dt>
713 Checks whether this CIDR instance is lower than the given argument.
714 The comparisation follows these rules:
715 <ul><li>An IPv4 address is always lower than an IPv6 address and IPv6 addresses
716 are considered lower than MAC addresses</li>
717 <li>Prefix sizes are ignored</li></ul>
725 addr: A <code>luci.ip.cidr</code> instance or a string convertable by
726 <code>luci.ip.new()</code> to compare against.
735 <pre>local addr = luci.ip.new("192.168.1.1")
736 print(addr:lower(addr)) -- false
737 print(addr:lower("10.10.10.10/24")) -- false
738 print(addr:lower(luci.ip.new("::1"))) -- true
739 print(addr:lower(luci.ip.new("192.168.200.1"))) -- true
740 print(addr:lower(luci.ip.new("00:14:22:01:23:45"))) -- true</pre>
744 <h3>Return value:</h3>
745 <code>true</code> if this CIDR is lower than the given address,
746 else <code>false</code>.
753 <li><a href="#cidr.higher">
757 <li><a href="#cidr.equal">
768 <dt><a name="cidr.higher"></a><strong>cidr:higher</strong> (addr)</dt>
772 Checks whether this CIDR instance is higher than the given argument.
773 The comparisation follows these rules:
774 <ul><li>An IPv4 address is always lower than an IPv6 address and IPv6 addresses
775 are considered lower than MAC addresses</li>
776 <li>Prefix sizes are ignored</li></ul>
784 addr: A <code>luci.ip.cidr</code> instance or a string convertable by
785 <code>luci.ip.new()</code> to compare against.
794 <pre>local addr = luci.ip.new("192.168.1.1")
795 print(addr:higher(addr)) -- false
796 print(addr:higher("10.10.10.10/24")) -- true
797 print(addr:higher(luci.ip.new("::1"))) -- false
798 print(addr:higher(luci.ip.new("192.168.200.1"))) -- false
799 print(addr:higher(luci.ip.new("00:14:22:01:23:45"))) -- false</pre>
803 <h3>Return value:</h3>
804 <code>true</code> if this CIDR is higher than the given address,
805 else <code>false</code>.
812 <li><a href="#cidr.lower">
816 <li><a href="#cidr.equal">
827 <dt><a name="cidr.equal"></a><strong>cidr:equal</strong> (addr)</dt>
831 Checks whether this CIDR instance is equal to the given argument.
839 addr: A <code>luci.ip.cidr</code> instance or a string convertable by
840 <code>luci.ip.new()</code> to compare against.
849 <pre>local addr = luci.ip.new("192.168.1.1")
850 print(addr:equal(addr)) -- true
851 print(addr:equal("192.168.1.1")) -- true
852 print(addr:equal(luci.ip.new("::1"))) -- false
854 local addr6 = luci.ip.new("::1")
855 print(addr6:equal("0:0:0:0:0:0:0:1/64")) -- true
856 print(addr6:equal(luci.ip.new("fe80::221:63ff:fe75:aa17"))) -- false
858 local mac = luci.ip.new("00:14:22:01:23:45")
859 print(mac:equal("0:14:22:1:23:45")) -- true
860 print(mac:equal(luci.ip.new("01:23:45:67:89:AB")) -- false</pre>
864 <h3>Return value:</h3>
865 <code>true</code> if this CIDR is equal to the given address,
866 else <code>false</code>.
873 <li><a href="#cidr.lower">
877 <li><a href="#cidr.higher">
888 <dt><a name="cidr.prefix"></a><strong>cidr:prefix</strong> (mask)</dt>
892 Get or set prefix size of CIDR instance.
893 If the optional mask parameter is given, the prefix size of this CIDR is altered
894 else the current prefix size is returned.
902 mask: Either a number containing the number of bits (<code>0..32</code>
903 for IPv4, <code>0..128</code> for IPv6 or <code>0..48</code> for MAC addresses) or a string
904 containing a valid netmask (optional)
913 <pre>local range = luci.ip.new("192.168.1.1/255.255.255.0")
914 print(range:prefix()) -- 24
917 print(range:prefix()) -- 16
919 range:prefix("255.255.255.255")
920 print(range:prefix()) -- 32</pre>
924 <h3>Return value:</h3>
925 Bit count of the current prefix size
934 <dt><a name="cidr.network"></a><strong>cidr:network</strong> (mask)</dt>
938 Derive network address of CIDR instance.
940 Returns a new CIDR instance representing the network address of this instance
941 with all host parts masked out. The used prefix size can be overridden by the
942 optional mask parameter.
950 mask: Either a number containing the number of bits (<code>0..32</code>
951 for IPv4, <code>0..128</code> for IPv6 or <code>0..48</code> for MAC addresses) or a string
952 containing a valid netmask (optional)
961 <pre>local range = luci.ip.new("192.168.62.243/255.255.0.0")
962 print(range:network()) -- "192.168.0.0"
963 print(range:network(24)) -- "192.168.62.0"
964 print(range:network("255.255.255.0")) -- "192.168.62.0"
966 local range6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
967 print(range6:network()) -- "fd9b:62b3:9cc5::"</pre>
971 <h3>Return value:</h3>
972 CIDR instance representing the network address
981 <dt><a name="cidr.host"></a><strong>cidr:host</strong> ()</dt>
985 Derive host address of CIDR instance.
987 This function essentially constructs a copy of this CIDR with the prefix size
988 set to <code>32</code> for IPv4, <code>128</code> for IPv6 or <code>48</code> for MAC addresses.
996 <pre>local range = luci.ip.new("172.19.37.45/16")
997 print(range) -- "172.19.37.45/16"
998 print(range:host()) -- "172.19.37.45"</pre>
1002 <h3>Return value:</h3>
1003 CIDR instance representing the host address
1012 <dt><a name="cidr.mask"></a><strong>cidr:mask</strong> (mask)</dt>
1016 Derive netmask of CIDR instance.
1018 Constructs a CIDR instance representing the netmask of this instance. The used
1019 prefix size can be overridden by the optional mask parameter.
1027 mask: Either a number containing the number of bits (<code>0..32</code>
1028 for IPv4, <code>0..128</code> for IPv6 or <code>0..48</code> for MAC addresses) or a string
1029 containing a valid netmask (optional)
1038 <pre>local range = luci.ip.new("172.19.37.45/16")
1039 print(range:mask()) -- "255.255.0.0"
1040 print(range:mask(24)) -- "255.255.255.0"
1041 print(range:mask("255.0.0.0")) -- "255.0.0.0"</pre>
1045 <h3>Return value:</h3>
1046 CIDR instance representing the netmask
1055 <dt><a name="cidr.broadcast"></a><strong>cidr:broadcast</strong> (mask)</dt>
1059 Derive broadcast address of CIDR instance.
1061 Constructs a CIDR instance representing the broadcast address of this instance.
1062 The used prefix size can be overridden by the optional mask parameter.
1064 This function has no effect on IPv6 or MAC address instances, it will return
1065 nothing in this case.
1073 mask: Either a number containing the number of bits (<code>0..32</code> for IPv4) or
1074 a string containing a valid netmask (optional)
1083 <pre>local range = luci.ip.new("172.19.37.45/16")
1084 print(range:broadcast()) -- "172.19.255.255"
1085 print(range:broadcast(24)) -- "172.19.37.255"
1086 print(range:broadcast("255.0.0.0")) -- "172.255.255.255"</pre>
1090 <h3>Return value:</h3>
1091 Return a new CIDR instance representing the broadcast address if this
1092 instance is an IPv4 range, else return nothing.
1101 <dt><a name="cidr.mapped4"></a><strong>cidr:mapped4</strong> ()</dt>
1105 Derive mapped IPv4 address of CIDR instance.
1107 Constructs a CIDR instance representing the IPv4 address of the IPv6 mapped
1108 IPv4 address in this instance.
1110 This function has no effect on IPv4 instances, MAC address instances or IPv6
1111 instances which are not a mapped address, it will return nothing in this case.
1119 <pre>local addr = luci.ip.new("::ffff:172.16.19.1")
1120 print(addr:mapped4()) -- "172.16.19.1"</pre>
1124 <h3>Return value:</h3>
1125 Return a new CIDR instance representing the IPv4 address if this
1126 instance is an IPv6 mapped IPv4 address, else return nothing.
1135 <dt><a name="cidr.tomac"></a><strong>cidr:tomac</strong> ()</dt>
1139 Derive MAC address of IPv6 link local CIDR instance.
1141 Constructs a CIDR instance representing the MAC address contained in the IPv6
1142 link local address of this instance.
1144 This function has no effect on IPv4 instances, MAC address instances or IPv6
1145 instances which are not a link local address, it will return nothing in this
1154 <pre>local addr = luci.ip.new("fe80::6666:b3ff:fe47:e1b9")
1155 print(addr:tomac()) -- "64:66:B3:47:E1:B9"</pre>
1159 <h3>Return value:</h3>
1160 Return a new CIDR instance representing the MAC address if this
1161 instance is an IPv6 link local address, else return nothing.
1170 <dt><a name="cidr.tolinklocal"></a><strong>cidr:tolinklocal</strong> ()</dt>
1174 Derive IPv6 link local address from MAC address CIDR instance.
1176 Constructs a CIDR instance representing the IPv6 link local address of the
1177 MAC address represented by this instance.
1179 This function has no effect on IPv4 instances or IPv6 instances, it will return
1180 nothing in this case.
1188 <pre>local mac = luci.ip.new("64:66:B3:47:E1:B9")
1189 print(mac:tolinklocal()) -- "fe80::6666:b3ff:fe47:e1b9"</pre>
1193 <h3>Return value:</h3>
1194 Return a new CIDR instance representing the IPv6 link local address.
1203 <dt><a name="cidr.contains"></a><strong>cidr:contains</strong> (addr)</dt>
1207 Test whether CIDR contains given range.
1215 addr: A <code>luci.ip.cidr</code> instance or a string convertable by
1216 <code>luci.ip.new()</code> to test.
1225 <pre>local range = luci.ip.new("10.24.0.0/255.255.0.0")
1226 print(range:contains("10.24.5.1")) -- true
1227 print(range:contains("::1")) -- false
1228 print(range:contains("10.0.0.0/8")) -- false
1230 local range6 = luci.ip.new("fe80::/10")
1231 print(range6:contains("fe80::221:63f:fe75:aa17/64")) -- true
1232 print(range6:contains("fd9b:6b3:c5:0:221:63f:fe75:aa17/64")) -- false
1234 local intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/24")
1235 print(intel_macs:contains("C0:B6:F9:A3:C:11")) -- true
1236 print(intel_macs:contains("64:66:B3:47:E1:B9")) -- false</pre>
1240 <h3>Return value:</h3>
1241 <code>true</code> if this instance fully contains the given address else
1251 <dt><a name="cidr.add"></a><strong>cidr:add</strong> (amount, inplace)</dt>
1255 Add given amount to CIDR instance. If the result would overflow the maximum
1256 address space, the result is set to the highest possible address.
1264 amount: A numeric value between 0 and 0xFFFFFFFF, a
1265 <code>luci.ip.cidr</code> instance or a string convertable by
1266 <code>luci.ip.new()</code>.
1270 inplace: If <code>true</code>, modify this instance instead of returning
1271 a new derived CIDR instance.
1280 <pre>local addr = luci.ip.new("192.168.1.1/24")
1281 print(addr:add(250)) -- "192.168.1.251/24"
1282 print(addr:add("0.0.99.0")) -- "192.168.100.1/24"
1284 addr:add(256, true) -- true
1285 print(addr) -- "192.168.2.1/24
1287 addr:add("255.0.0.0", true) -- false (overflow)
1288 print(addr) -- "255.255.255.255/24
1290 local addr6 = luci.ip.new("fe80::221:63f:fe75:aa17/64")
1291 print(addr6:add(256)) -- "fe80::221:63f:fe75:ab17/64"
1292 print(addr6:add("::ffff:0")) -- "fe80::221:640:fe74:aa17/64"
1294 addr6:add(256, true) -- true
1295 print(addr6) -- "fe80::221:63f:fe75:ab17/64
1297 addr6:add("ffff::", true) -- false (overflow)
1298 print(addr6) -- "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/64"
1300 local mac = luci.ip.new("00:14:22:01:23:45")
1301 print(mac:add(256)) -- "00:14:22:01:24:45"
1302 print(mac:add("0:0:0:0:FF:0") -- "00:14:22:02:22:45"
1304 mac:add(256, true) -- true
1305 print(mac) -- "00:14:22:01:24:45"
1307 mac:add("FF:FF:0:0:0:0", true) -- false (overflow)
1308 print(mac) -- "FF:FF:FF:FF:FF:FF"</pre>
1312 <h3>Return value:</h3>
1314 <li>When adding inplace: Return <code>true</code> if the addition succeded
1315 or <code>false</code> when the addition overflowed.</li>
1316 <li>When deriving new CIDR: Return new instance representing the value of
1317 this instance plus the added amount or the highest possible address if
1318 the addition overflowed the available address space.</li></ul>
1327 <dt><a name="cidr.sub"></a><strong>cidr:sub</strong> (amount, inplace)</dt>
1331 Subtract given amount from CIDR instance. If the result would under, the lowest
1332 possible address is returned.
1340 amount: A numeric value between 0 and 0xFFFFFFFF, a
1341 <code>luci.ip.cidr</code> instance or a string convertable by
1342 <code>luci.ip.new()</code>.
1346 inplace: If <code>true</code>, modify this instance instead of returning
1347 a new derived CIDR instance.
1356 <pre>local addr = luci.ip.new("192.168.1.1/24")
1357 print(addr:sub(256)) -- "192.168.0.1/24"
1358 print(addr:sub("0.168.0.0")) -- "192.0.1.1/24"
1360 addr:sub(256, true) -- true
1361 print(addr) -- "192.168.0.1/24
1363 addr:sub("255.0.0.0", true) -- false (underflow)
1364 print(addr) -- "0.0.0.0/24
1366 local addr6 = luci.ip.new("fe80::221:63f:fe75:aa17/64")
1367 print(addr6:sub(256)) -- "fe80::221:63f:fe75:a917/64"
1368 print(addr6:sub("::ffff:0")) -- "fe80::221:63e:fe76:aa17/64"
1370 addr:sub(256, true) -- true
1371 print(addr) -- "fe80::221:63f:fe75:a917/64"
1373 addr:sub("ffff::", true) -- false (underflow)
1374 print(addr) -- "::/64"
1376 local mac = luci.ip.new("00:14:22:01:23:45")
1377 print(mac:sub(256)) -- "00:14:22:01:22:45"
1378 print(mac:sub("0:0:0:0:FF:0") -- "00:14:22:00:24:45"
1380 mac:sub(256, true) -- true
1381 print(mac) -- "00:14:22:01:22:45"
1383 mac:sub("FF:FF:0:0:0:0", true) -- false (overflow)
1384 print(mac) -- "00:00:00:00:00:00"</pre>
1388 <h3>Return value:</h3>
1390 <li>When subtracting inplace: Return <code>true</code> if the subtraction
1391 succeeded or <code>false</code> when the subtraction underflowed.</li>
1392 <li>When deriving new CIDR: Return new instance representing the value of
1393 this instance minus the subtracted amount or the lowest address if
1394 the subtraction underflowed.</li></ul>
1403 <dt><a name="cidr.minhost"></a><strong>cidr:minhost</strong> ()</dt>
1407 Calculate the lowest possible host address within this CIDR instance.
1415 <pre>local addr = luci.ip.new("192.168.123.56/24")
1416 print(addr:minhost()) -- "192.168.123.1"
1418 local addr6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
1419 print(addr6:minhost()) -- "fd9b:62b3:9cc5::1"
1421 local mac = luci.ip.new("00:14:22:01:22:45/32")
1422 print(mac:minhost()) -- "00:14:22:01:00:01"</pre>
1426 <h3>Return value:</h3>
1427 Returns a new CIDR instance representing the lowest host address
1437 <dt><a name="cidr.maxhost"></a><strong>cidr:maxhost</strong> ()</dt>
1441 Calculate the highest possible host address within this CIDR instance.
1449 <pre>local addr = luci.ip.new("192.168.123.56/24")
1450 print(addr:maxhost()) -- "192.168.123.254" (.255 is broadcast)
1452 local addr6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
1453 print(addr6:maxhost()) -- "fd9b:62b3:9cc5:0:ffff:ffff:ffff:ffff"
1455 local mac = luci.ip.new("00:14:22:01:22:45/32")
1456 print(mac:maxhost()) -- "00:14:22:01:FF:FF"</pre>
1460 <h3>Return value:</h3>
1461 Returns a new CIDR instance representing the highest host address
1471 <dt><a name="cidr.string"></a><strong>cidr:string</strong> ()</dt>
1475 Convert CIDR instance into string representation.
1477 If the prefix size of instance is less than 32 for IPv4, 128 for IPv6 or 48 for
1478 MACs, the address is returned in the form "address/prefix" otherwise just
1481 It is usually not required to call this function directly as CIDR objects
1482 define it as __tostring function in the associated metatable.
1491 <h3>Return value:</h3>
1492 Returns a string representing the range or address of this CIDR instance
1505 </div> <!-- id="content" -->
1507 </div> <!-- id="main" -->
1510 <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
1511 </div> <!-- id="about" -->
1513 </div> <!-- id="container" -->