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.conditionals.html">luci.http.conditionals</a>
50 <a href="../modules/luci.http.date.html">luci.http.date</a>
54 <a href="../modules/luci.http.mime.html">luci.http.mime</a>
58 <a href="../modules/luci.i18n.html">luci.i18n</a>
62 <a href="../modules/luci.ip.html">luci.ip</a>
65 <li><strong>luci.ip.cidr</strong></li>
68 <a href="../modules/luci.json.html">luci.json</a>
72 <a href="../modules/luci.jsonc.html">luci.jsonc</a>
76 <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
80 <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
84 <a href="../modules/luci.model.uci.html">luci.model.uci</a>
88 <a href="../modules/luci.rpcc.html">luci.rpcc</a>
92 <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
96 <a href="../modules/luci.sys.html">luci.sys</a>
100 <a href="../modules/luci.sys.init.html">luci.sys.init</a>
104 <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
108 <a href="../modules/luci.sys.net.html">luci.sys.net</a>
112 <a href="../modules/luci.sys.process.html">luci.sys.process</a>
116 <a href="../modules/luci.sys.user.html">luci.sys.user</a>
120 <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
124 <a href="../modules/luci.util.html">luci.util</a>
128 <a href="../modules/nixio.html">nixio</a>
132 <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
136 <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
140 <a href="../modules/nixio.File.html">nixio.File</a>
144 <a href="../modules/nixio.README.html">nixio.README</a>
148 <a href="../modules/nixio.Socket.html">nixio.Socket</a>
152 <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
156 <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
160 <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
164 <a href="../modules/nixio.bin.html">nixio.bin</a>
168 <a href="../modules/nixio.bit.html">nixio.bit</a>
172 <a href="../modules/nixio.crypto.html">nixio.crypto</a>
176 <a href="../modules/nixio.fs.html">nixio.fs</a>
191 </div><!-- id="navigation" -->
195 <h1>Object Instance <code>luci.ip.cidr</code></h1>
199 Represents an IPv4 or IPv6 address range.</p>
208 <table class="function_list">
211 <td class="name" nowrap><a href="#cidr.is4">cidr:is4</a> ()</td>
214 Checks whether the CIDR instance is an IPv4 address range
219 <td class="name" nowrap><a href="#cidr.is4rfc1918">cidr:is4rfc1918</a> ()</td>
222 Checks whether the CIDR instance is within the private RFC1918 address space
227 <td class="name" nowrap><a href="#cidr.is4linklocal">cidr:is4linklocal</a> ()</td>
230 Checks whether the CIDR instance is an IPv4 link local (Zeroconf) address
235 <td class="name" nowrap><a href="#cidr.is6">cidr:is6</a> ()</td>
238 Checks whether the CIDR instance is an IPv6 address range
243 <td class="name" nowrap><a href="#cidr.is6linklocal">cidr:is6linklocal</a> ()</td>
246 Checks whether the CIDR instance is an IPv6 link local address
251 <td class="name" nowrap><a href="#cidr.is6mapped4">cidr:is6mapped4</a> ()</td>
254 Checks whether the CIDR instance is an IPv6 mapped IPv4 address
259 <td class="name" nowrap><a href="#cidr.ismac">cidr:ismac</a> ()</td>
262 Checks whether the CIDR instance is an ethernet MAC address range
267 <td class="name" nowrap><a href="#cidr.ismaclocal">cidr:ismaclocal</a> ()</td>
270 Checks whether the CIDR instance is a locally administered (LAA) MAC address
275 <td class="name" nowrap><a href="#cidr.ismacmcast">cidr:ismacmcast</a> ()</td>
278 Checks whether the CIDR instance is a multicast MAC address
283 <td class="name" nowrap><a href="#cidr.lower">cidr:lower</a> (addr)</td>
286 Checks whether this CIDR instance is lower than the given argument.</td>
290 <td class="name" nowrap><a href="#cidr.higher">cidr:higher</a> (addr)</td>
293 Checks whether this CIDR instance is higher than the given argument.</td>
297 <td class="name" nowrap><a href="#cidr.equal">cidr:equal</a> (addr)</td>
300 Checks whether this CIDR instance is equal to the given argument.</td>
304 <td class="name" nowrap><a href="#cidr.prefix">cidr:prefix</a> (mask)</td>
307 Get or set prefix size of CIDR instance.</td>
311 <td class="name" nowrap><a href="#cidr.network">cidr:network</a> (mask)</td>
314 Derive network address of CIDR instance.</td>
318 <td class="name" nowrap><a href="#cidr.host">cidr:host</a> ()</td>
321 Derive host address of CIDR instance.</td>
325 <td class="name" nowrap><a href="#cidr.mask">cidr:mask</a> (mask)</td>
328 Derive netmask of CIDR instance.</td>
332 <td class="name" nowrap><a href="#cidr.broadcast">cidr:broadcast</a> (mask)</td>
335 Derive broadcast address of CIDR instance.</td>
339 <td class="name" nowrap><a href="#cidr.mapped4">cidr:mapped4</a> ()</td>
342 Derive mapped IPv4 address of CIDR instance.</td>
346 <td class="name" nowrap><a href="#cidr.tomac">cidr:tomac</a> ()</td>
349 Derive MAC address of IPv6 link local CIDR instance.</td>
353 <td class="name" nowrap><a href="#cidr.tolinklocal">cidr:tolinklocal</a> ()</td>
356 Derive IPv6 link local address from MAC address CIDR instance.</td>
360 <td class="name" nowrap><a href="#cidr.contains">cidr:contains</a> (addr)</td>
363 Test whether CIDR contains given range.</td>
367 <td class="name" nowrap><a href="#cidr.add">cidr:add</a> (amount, inplace)</td>
370 Add given amount to CIDR instance.</td>
374 <td class="name" nowrap><a href="#cidr.sub">cidr:sub</a> (amount, inplace)</td>
377 Subtract given amount from CIDR instance.</td>
381 <td class="name" nowrap><a href="#cidr.minhost">cidr:minhost</a> ()</td>
384 Calculate the lowest possible host address within this CIDR instance.</td>
388 <td class="name" nowrap><a href="#cidr.maxhost">cidr:maxhost</a> ()</td>
391 Calculate the highest possible host address within this CIDR instance.</td>
395 <td class="name" nowrap><a href="#cidr.string">cidr:string</a> ()</td>
398 Convert CIDR instance into string representation.</td>
412 <h2><a name="functions"></a>Functions</h2>
413 <dl class="function">
417 <dt><a name="cidr.is4"></a><strong>cidr:is4</strong> ()</dt>
421 Checks whether the CIDR instance is an IPv4 address range
430 <h3>Return value:</h3>
431 <code>true</code> if the CIDR is an IPv4 range, else <code>false</code>
438 <li><a href="#cidr.is6">
442 <li><a href="#cidr.ismac">
453 <dt><a name="cidr.is4rfc1918"></a><strong>cidr:is4rfc1918</strong> ()</dt>
457 Checks whether the CIDR instance is within the private RFC1918 address space
465 <pre>local addr = luci.ip.new("192.168.45.2/24")
466 if addr:is4rfc1918() then
467 print("Is a private address")
472 <h3>Return value:</h3>
473 <code>true</code> if the entire range of this CIDR lies within one of
474 the ranges <code>10.0.0.0-10.255.255.255</code>,
475 <code>172.16.0.0-172.31.0.0</code> or
476 <code>192.168.0.0-192.168.255.255</code>, else <code>false</code>.
485 <dt><a name="cidr.is4linklocal"></a><strong>cidr:is4linklocal</strong> ()</dt>
489 Checks whether the CIDR instance is an IPv4 link local (Zeroconf) address
497 <pre>local addr = luci.ip.new("169.254.34.125")
498 if addr:is4linklocal() then
499 print("Is a zeroconf address")
504 <h3>Return value:</h3>
505 <code>true</code> if the entire range of this CIDR lies within the range
506 the range <code>169.254.0.0-169.254.255.255</code>, else <code>false</code>.
515 <dt><a name="cidr.is6"></a><strong>cidr:is6</strong> ()</dt>
519 Checks whether the CIDR instance is an IPv6 address range
528 <h3>Return value:</h3>
529 <code>true</code> if the CIDR is an IPv6 range, else <code>false</code>
536 <li><a href="#cidr.is4">
540 <li><a href="#cidr.ismac">
551 <dt><a name="cidr.is6linklocal"></a><strong>cidr:is6linklocal</strong> ()</dt>
555 Checks whether the CIDR instance is an IPv6 link local address
563 <pre>local addr = luci.ip.new("fe92:53a:3216:af01:221:63ff:fe75:aa17/64")
564 if addr:is6linklocal() then
565 print("Is a linklocal address")
570 <h3>Return value:</h3>
571 <code>true</code> if the entire range of this CIDR lies within the range
572 the <code>fe80::/10</code> range, else <code>false</code>.
581 <dt><a name="cidr.is6mapped4"></a><strong>cidr:is6mapped4</strong> ()</dt>
585 Checks whether the CIDR instance is an IPv6 mapped IPv4 address
593 <pre>local addr = luci.ip.new("::ffff:192.168.1.1")
594 if addr:is6mapped4() then
595 print("Is a mapped IPv4 address")
600 <h3>Return value:</h3>
601 <code>true</code> if the address is an IPv6 mapped IPv4 address in the
602 form <code>::ffff:1.2.3.4</code>.
611 <dt><a name="cidr.ismac"></a><strong>cidr:ismac</strong> ()</dt>
615 Checks whether the CIDR instance is an ethernet MAC address range
624 <h3>Return value:</h3>
625 <code>true</code> if the CIDR is a MAC address range, else <code>false</code>
632 <li><a href="#cidr.is4">
636 <li><a href="#cidr.is6">
647 <dt><a name="cidr.ismaclocal"></a><strong>cidr:ismaclocal</strong> ()</dt>
651 Checks whether the CIDR instance is a locally administered (LAA) MAC address
659 <pre>local mac = luci.ip.new("02:C0:FF:EE:00:01")
660 if mac:ismaclocal() then
661 print("Is an LAA MAC address")
666 <h3>Return value:</h3>
667 <code>true</code> if the MAC address sets the locally administered bit.
676 <dt><a name="cidr.ismacmcast"></a><strong>cidr:ismacmcast</strong> ()</dt>
680 Checks whether the CIDR instance is a multicast MAC address
688 <pre>local mac = luci.ip.new("01:00:5E:7F:00:10")
689 if addr:ismacmcast() then
690 print("Is a multicast MAC address")
695 <h3>Return value:</h3>
696 <code>true</code> if the MAC address sets the multicast bit.
705 <dt><a name="cidr.lower"></a><strong>cidr:lower</strong> (addr)</dt>
709 Checks whether this CIDR instance is lower than the given argument.
710 The comparisation follows these rules:
711 <ul><li>An IPv4 address is always lower than an IPv6 address and IPv6 addresses
712 are considered lower than MAC addresses</li>
713 <li>Prefix sizes are ignored</li></ul>
721 addr: A <code>luci.ip.cidr</code> instance or a string convertable by
722 <code>luci.ip.new()</code> to compare against.
731 <pre>local addr = luci.ip.new("192.168.1.1")
732 print(addr:lower(addr)) -- false
733 print(addr:lower("10.10.10.10/24")) -- false
734 print(addr:lower(luci.ip.new("::1"))) -- true
735 print(addr:lower(luci.ip.new("192.168.200.1"))) -- true
736 print(addr:lower(luci.ip.new("00:14:22:01:23:45"))) -- true</pre>
740 <h3>Return value:</h3>
741 <code>true</code> if this CIDR is lower than the given address,
742 else <code>false</code>.
749 <li><a href="#cidr.higher">
753 <li><a href="#cidr.equal">
764 <dt><a name="cidr.higher"></a><strong>cidr:higher</strong> (addr)</dt>
768 Checks whether this CIDR instance is higher than the given argument.
769 The comparisation follows these rules:
770 <ul><li>An IPv4 address is always lower than an IPv6 address and IPv6 addresses
771 are considered lower than MAC addresses</li>
772 <li>Prefix sizes are ignored</li></ul>
780 addr: A <code>luci.ip.cidr</code> instance or a string convertable by
781 <code>luci.ip.new()</code> to compare against.
790 <pre>local addr = luci.ip.new("192.168.1.1")
791 print(addr:higher(addr)) -- false
792 print(addr:higher("10.10.10.10/24")) -- true
793 print(addr:higher(luci.ip.new("::1"))) -- false
794 print(addr:higher(luci.ip.new("192.168.200.1"))) -- false
795 print(addr:higher(luci.ip.new("00:14:22:01:23:45"))) -- false</pre>
799 <h3>Return value:</h3>
800 <code>true</code> if this CIDR is higher than the given address,
801 else <code>false</code>.
808 <li><a href="#cidr.lower">
812 <li><a href="#cidr.equal">
823 <dt><a name="cidr.equal"></a><strong>cidr:equal</strong> (addr)</dt>
827 Checks whether this CIDR instance is equal to the given argument.
835 addr: A <code>luci.ip.cidr</code> instance or a string convertable by
836 <code>luci.ip.new()</code> to compare against.
845 <pre>local addr = luci.ip.new("192.168.1.1")
846 print(addr:equal(addr)) -- true
847 print(addr:equal("192.168.1.1")) -- true
848 print(addr:equal(luci.ip.new("::1"))) -- false
850 local addr6 = luci.ip.new("::1")
851 print(addr6:equal("0:0:0:0:0:0:0:1/64")) -- true
852 print(addr6:equal(luci.ip.new("fe80::221:63ff:fe75:aa17"))) -- false
854 local mac = luci.ip.new("00:14:22:01:23:45")
855 print(mac:equal("0:14:22:1:23:45")) -- true
856 print(mac:equal(luci.ip.new("01:23:45:67:89:AB")) -- false</pre>
860 <h3>Return value:</h3>
861 <code>true</code> if this CIDR is equal to the given address,
862 else <code>false</code>.
869 <li><a href="#cidr.lower">
873 <li><a href="#cidr.higher">
884 <dt><a name="cidr.prefix"></a><strong>cidr:prefix</strong> (mask)</dt>
888 Get or set prefix size of CIDR instance.
889 If the optional mask parameter is given, the prefix size of this CIDR is altered
890 else the current prefix size is returned.
898 mask: Either a number containing the number of bits (<code>0..32</code>
899 for IPv4, <code>0..128</code> for IPv6 or <code>0..48</code> for MAC addresses) or a string
900 containing a valid netmask (optional)
909 <pre>local range = luci.ip.new("192.168.1.1/255.255.255.0")
910 print(range:prefix()) -- 24
913 print(range:prefix()) -- 16
915 range:prefix("255.255.255.255")
916 print(range:prefix()) -- 32</pre>
920 <h3>Return value:</h3>
921 Bit count of the current prefix size
930 <dt><a name="cidr.network"></a><strong>cidr:network</strong> (mask)</dt>
934 Derive network address of CIDR instance.
936 Returns a new CIDR instance representing the network address of this instance
937 with all host parts masked out. The used prefix size can be overridden by the
938 optional mask parameter.
946 mask: Either a number containing the number of bits (<code>0..32</code>
947 for IPv4, <code>0..128</code> for IPv6 or <code>0..48</code> for MAC addresses) or a string
948 containing a valid netmask (optional)
957 <pre>local range = luci.ip.new("192.168.62.243/255.255.0.0")
958 print(range:network()) -- "192.168.0.0"
959 print(range:network(24)) -- "192.168.62.0"
960 print(range:network("255.255.255.0")) -- "192.168.62.0"
962 local range6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
963 print(range6:network()) -- "fd9b:62b3:9cc5::"</pre>
967 <h3>Return value:</h3>
968 CIDR instance representing the network address
977 <dt><a name="cidr.host"></a><strong>cidr:host</strong> ()</dt>
981 Derive host address of CIDR instance.
983 This function essentially constructs a copy of this CIDR with the prefix size
984 set to <code>32</code> for IPv4, <code>128</code> for IPv6 or <code>48</code> for MAC addresses.
992 <pre>local range = luci.ip.new("172.19.37.45/16")
993 print(range) -- "172.19.37.45/16"
994 print(range:host()) -- "172.19.37.45"</pre>
998 <h3>Return value:</h3>
999 CIDR instance representing the host address
1008 <dt><a name="cidr.mask"></a><strong>cidr:mask</strong> (mask)</dt>
1012 Derive netmask of CIDR instance.
1014 Constructs a CIDR instance representing the netmask of this instance. The used
1015 prefix size can be overridden by the optional mask parameter.
1023 mask: Either a number containing the number of bits (<code>0..32</code>
1024 for IPv4, <code>0..128</code> for IPv6 or <code>0..48</code> for MAC addresses) or a string
1025 containing a valid netmask (optional)
1034 <pre>local range = luci.ip.new("172.19.37.45/16")
1035 print(range:mask()) -- "255.255.0.0"
1036 print(range:mask(24)) -- "255.255.255.0"
1037 print(range:mask("255.0.0.0")) -- "255.0.0.0"</pre>
1041 <h3>Return value:</h3>
1042 CIDR instance representing the netmask
1051 <dt><a name="cidr.broadcast"></a><strong>cidr:broadcast</strong> (mask)</dt>
1055 Derive broadcast address of CIDR instance.
1057 Constructs a CIDR instance representing the broadcast address of this instance.
1058 The used prefix size can be overridden by the optional mask parameter.
1060 This function has no effect on IPv6 or MAC address instances, it will return
1061 nothing in this case.
1069 mask: Either a number containing the number of bits (<code>0..32</code> for IPv4) or
1070 a string containing a valid netmask (optional)
1079 <pre>local range = luci.ip.new("172.19.37.45/16")
1080 print(range:broadcast()) -- "172.19.255.255"
1081 print(range:broadcast(24)) -- "172.19.37.255"
1082 print(range:broadcast("255.0.0.0")) -- "172.255.255.255"</pre>
1086 <h3>Return value:</h3>
1087 Return a new CIDR instance representing the broadcast address if this
1088 instance is an IPv4 range, else return nothing.
1097 <dt><a name="cidr.mapped4"></a><strong>cidr:mapped4</strong> ()</dt>
1101 Derive mapped IPv4 address of CIDR instance.
1103 Constructs a CIDR instance representing the IPv4 address of the IPv6 mapped
1104 IPv4 address in this instance.
1106 This function has no effect on IPv4 instances, MAC address instances or IPv6
1107 instances which are not a mapped address, it will return nothing in this case.
1115 <pre>local addr = luci.ip.new("::ffff:172.16.19.1")
1116 print(addr:mapped4()) -- "172.16.19.1"</pre>
1120 <h3>Return value:</h3>
1121 Return a new CIDR instance representing the IPv4 address if this
1122 instance is an IPv6 mapped IPv4 address, else return nothing.
1131 <dt><a name="cidr.tomac"></a><strong>cidr:tomac</strong> ()</dt>
1135 Derive MAC address of IPv6 link local CIDR instance.
1137 Constructs a CIDR instance representing the MAC address contained in the IPv6
1138 link local address of this instance.
1140 This function has no effect on IPv4 instances, MAC address instances or IPv6
1141 instances which are not a link local address, it will return nothing in this
1150 <pre>local addr = luci.ip.new("fe80::6666:b3ff:fe47:e1b9")
1151 print(addr:tomac()) -- "64:66:B3:47:E1:B9"</pre>
1155 <h3>Return value:</h3>
1156 Return a new CIDR instance representing the MAC address if this
1157 instance is an IPv6 link local address, else return nothing.
1166 <dt><a name="cidr.tolinklocal"></a><strong>cidr:tolinklocal</strong> ()</dt>
1170 Derive IPv6 link local address from MAC address CIDR instance.
1172 Constructs a CIDR instance representing the IPv6 link local address of the
1173 MAC address represented by this instance.
1175 This function has no effect on IPv4 instances or IPv6 instances, it will return
1176 nothing in this case.
1184 <pre>local mac = luci.ip.new("64:66:B3:47:E1:B9")
1185 print(mac:tolinklocal()) -- "fe80::6666:b3ff:fe47:e1b9"</pre>
1189 <h3>Return value:</h3>
1190 Return a new CIDR instance representing the IPv6 link local address.
1199 <dt><a name="cidr.contains"></a><strong>cidr:contains</strong> (addr)</dt>
1203 Test whether CIDR contains given range.
1211 addr: A <code>luci.ip.cidr</code> instance or a string convertable by
1212 <code>luci.ip.new()</code> to test.
1221 <pre>local range = luci.ip.new("10.24.0.0/255.255.0.0")
1222 print(range:contains("10.24.5.1")) -- true
1223 print(range:contains("::1")) -- false
1224 print(range:contains("10.0.0.0/8")) -- false
1226 local range6 = luci.ip.new("fe80::/10")
1227 print(range6:contains("fe80::221:63f:fe75:aa17/64")) -- true
1228 print(range6:contains("fd9b:6b3:c5:0:221:63f:fe75:aa17/64")) -- false
1230 local intel_macs = luci.ip.MAC("C0:B6:F9:00:00:00/24")
1231 print(intel_macs:contains("C0:B6:F9:A3:C:11")) -- true
1232 print(intel_macs:contains("64:66:B3:47:E1:B9")) -- false</pre>
1236 <h3>Return value:</h3>
1237 <code>true</code> if this instance fully contains the given address else
1247 <dt><a name="cidr.add"></a><strong>cidr:add</strong> (amount, inplace)</dt>
1251 Add given amount to CIDR instance. If the result would overflow the maximum
1252 address space, the result is set to the highest possible address.
1260 amount: A numeric value between 0 and 0xFFFFFFFF, a
1261 <code>luci.ip.cidr</code> instance or a string convertable by
1262 <code>luci.ip.new()</code>.
1266 inplace: If <code>true</code>, modify this instance instead of returning
1267 a new derived CIDR instance.
1276 <pre>local addr = luci.ip.new("192.168.1.1/24")
1277 print(addr:add(250)) -- "192.168.1.251/24"
1278 print(addr:add("0.0.99.0")) -- "192.168.100.1/24"
1280 addr:add(256, true) -- true
1281 print(addr) -- "192.168.2.1/24
1283 addr:add("255.0.0.0", true) -- false (overflow)
1284 print(addr) -- "255.255.255.255/24
1286 local addr6 = luci.ip.new("fe80::221:63f:fe75:aa17/64")
1287 print(addr6:add(256)) -- "fe80::221:63f:fe75:ab17/64"
1288 print(addr6:add("::ffff:0")) -- "fe80::221:640:fe74:aa17/64"
1290 addr6:add(256, true) -- true
1291 print(addr6) -- "fe80::221:63f:fe75:ab17/64
1293 addr6:add("ffff::", true) -- false (overflow)
1294 print(addr6) -- "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/64"
1296 local mac = luci.ip.new("00:14:22:01:23:45")
1297 print(mac:add(256)) -- "00:14:22:01:24:45"
1298 print(mac:add("0:0:0:0:FF:0") -- "00:14:22:02:22:45"
1300 mac:add(256, true) -- true
1301 print(mac) -- "00:14:22:01:24:45"
1303 mac:add("FF:FF:0:0:0:0", true) -- false (overflow)
1304 print(mac) -- "FF:FF:FF:FF:FF:FF"</pre>
1308 <h3>Return value:</h3>
1310 <li>When adding inplace: Return <code>true</code> if the addition succeded
1311 or <code>false</code> when the addition overflowed.</li>
1312 <li>When deriving new CIDR: Return new instance representing the value of
1313 this instance plus the added amount or the highest possible address if
1314 the addition overflowed the available address space.</li></ul>
1323 <dt><a name="cidr.sub"></a><strong>cidr:sub</strong> (amount, inplace)</dt>
1327 Subtract given amount from CIDR instance. If the result would under, the lowest
1328 possible address is returned.
1336 amount: A numeric value between 0 and 0xFFFFFFFF, a
1337 <code>luci.ip.cidr</code> instance or a string convertable by
1338 <code>luci.ip.new()</code>.
1342 inplace: If <code>true</code>, modify this instance instead of returning
1343 a new derived CIDR instance.
1352 <pre>local addr = luci.ip.new("192.168.1.1/24")
1353 print(addr:sub(256)) -- "192.168.0.1/24"
1354 print(addr:sub("0.168.0.0")) -- "192.0.1.1/24"
1356 addr:sub(256, true) -- true
1357 print(addr) -- "192.168.0.1/24
1359 addr:sub("255.0.0.0", true) -- false (underflow)
1360 print(addr) -- "0.0.0.0/24
1362 local addr6 = luci.ip.new("fe80::221:63f:fe75:aa17/64")
1363 print(addr6:sub(256)) -- "fe80::221:63f:fe75:a917/64"
1364 print(addr6:sub("::ffff:0")) -- "fe80::221:63e:fe76:aa17/64"
1366 addr:sub(256, true) -- true
1367 print(addr) -- "fe80::221:63f:fe75:a917/64"
1369 addr:sub("ffff::", true) -- false (underflow)
1370 print(addr) -- "::/64"
1372 local mac = luci.ip.new("00:14:22:01:23:45")
1373 print(mac:sub(256)) -- "00:14:22:01:22:45"
1374 print(mac:sub("0:0:0:0:FF:0") -- "00:14:22:00:24:45"
1376 mac:sub(256, true) -- true
1377 print(mac) -- "00:14:22:01:22:45"
1379 mac:sub("FF:FF:0:0:0:0", true) -- false (overflow)
1380 print(mac) -- "00:00:00:00:00:00"</pre>
1384 <h3>Return value:</h3>
1386 <li>When subtracting inplace: Return <code>true</code> if the subtraction
1387 succeeded or <code>false</code> when the subtraction underflowed.</li>
1388 <li>When deriving new CIDR: Return new instance representing the value of
1389 this instance minus the subtracted amount or the lowest address if
1390 the subtraction underflowed.</li></ul>
1399 <dt><a name="cidr.minhost"></a><strong>cidr:minhost</strong> ()</dt>
1403 Calculate the lowest possible host address within this CIDR instance.
1411 <pre>local addr = luci.ip.new("192.168.123.56/24")
1412 print(addr:minhost()) -- "192.168.123.1"
1414 local addr6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
1415 print(addr6:minhost()) -- "fd9b:62b3:9cc5::1"
1417 local mac = luci.ip.new("00:14:22:01:22:45/32")
1418 print(mac:minhost()) -- "00:14:22:01:00:01"</pre>
1422 <h3>Return value:</h3>
1423 Returns a new CIDR instance representing the lowest host address
1433 <dt><a name="cidr.maxhost"></a><strong>cidr:maxhost</strong> ()</dt>
1437 Calculate the highest possible host address within this CIDR instance.
1445 <pre>local addr = luci.ip.new("192.168.123.56/24")
1446 print(addr:maxhost()) -- "192.168.123.254" (.255 is broadcast)
1448 local addr6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
1449 print(addr6:maxhost()) -- "fd9b:62b3:9cc5:0:ffff:ffff:ffff:ffff"
1451 local mac = luci.ip.new("00:14:22:01:22:45/32")
1452 print(mac:maxhost()) -- "00:14:22:01:FF:FF"</pre>
1456 <h3>Return value:</h3>
1457 Returns a new CIDR instance representing the highest host address
1467 <dt><a name="cidr.string"></a><strong>cidr:string</strong> ()</dt>
1471 Convert CIDR instance into string representation.
1473 If the prefix size of instance is less than 32 for IPv4, 128 for IPv6 or 48 for
1474 MACs, the address is returned in the form "address/prefix" otherwise just
1477 It is usually not required to call this function directly as CIDR objects
1478 define it as __tostring function in the associated metatable.
1487 <h3>Return value:</h3>
1488 Returns a string representing the range or address of this CIDR instance
1501 </div> <!-- id="content" -->
1503 </div> <!-- id="main" -->
1506 <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>
1507 </div> <!-- id="about" -->
1509 </div> <!-- id="container" -->