123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <title>Reference</title>
- <link rel="stylesheet" href="../luadoc.css" type="text/css" />
- <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
- </head>
- <body>
- <div id="container">
- <div id="product">
- <div id="product_logo"></div>
- <div id="product_name"><big><b></b></big></div>
- <div id="product_description"></div>
- </div> <!-- id="product" -->
- <div id="main">
- <div id="navigation">
- <h1>LuaDoc</h1>
- <ul>
-
- <li><a href="../index.html">Index</a></li>
-
- </ul>
- <!-- Module list -->
- <h1>Modules</h1>
- <ul>
- <li>
- <a href="../modules/luci.dispatcher.html">luci.dispatcher</a>
- </li>
- <li>
- <a href="../modules/luci.http.html">luci.http</a>
- </li>
- <li>
- <a href="../modules/luci.http.protocol.html">luci.http.protocol</a>
- </li>
- <li>
- <a href="../modules/luci.http.protocol.conditionals.html">luci.http.protocol.conditionals</a>
- </li>
- <li>
- <a href="../modules/luci.http.protocol.date.html">luci.http.protocol.date</a>
- </li>
- <li>
- <a href="../modules/luci.http.protocol.mime.html">luci.http.protocol.mime</a>
- </li>
- <li>
- <a href="../modules/luci.i18n.html">luci.i18n</a>
- </li>
- <li>
- <a href="../modules/luci.ip.html">luci.ip</a>
- </li>
- <li><strong>luci.ip.cidr</strong></li>
-
- <li>
- <a href="../modules/luci.json.html">luci.json</a>
- </li>
- <li>
- <a href="../modules/luci.jsonc.html">luci.jsonc</a>
- </li>
- <li>
- <a href="../modules/luci.jsonc.parser.html">luci.jsonc.parser</a>
- </li>
- <li>
- <a href="../modules/luci.model.ipkg.html">luci.model.ipkg</a>
- </li>
- <li>
- <a href="../modules/luci.model.uci.html">luci.model.uci</a>
- </li>
- <li>
- <a href="../modules/luci.rpcc.html">luci.rpcc</a>
- </li>
- <li>
- <a href="../modules/luci.rpcc.ruci.html">luci.rpcc.ruci</a>
- </li>
- <li>
- <a href="../modules/luci.sys.html">luci.sys</a>
- </li>
- <li>
- <a href="../modules/luci.sys.init.html">luci.sys.init</a>
- </li>
- <li>
- <a href="../modules/luci.sys.iptparser.html">luci.sys.iptparser</a>
- </li>
- <li>
- <a href="../modules/luci.sys.net.html">luci.sys.net</a>
- </li>
- <li>
- <a href="../modules/luci.sys.process.html">luci.sys.process</a>
- </li>
- <li>
- <a href="../modules/luci.sys.user.html">luci.sys.user</a>
- </li>
- <li>
- <a href="../modules/luci.sys.wifi.html">luci.sys.wifi</a>
- </li>
- <li>
- <a href="../modules/luci.util.html">luci.util</a>
- </li>
- <li>
- <a href="../modules/nixio.html">nixio</a>
- </li>
- <li>
- <a href="../modules/nixio.CHANGELOG.html">nixio.CHANGELOG</a>
- </li>
- <li>
- <a href="../modules/nixio.CryptoHash.html">nixio.CryptoHash</a>
- </li>
- <li>
- <a href="../modules/nixio.File.html">nixio.File</a>
- </li>
- <li>
- <a href="../modules/nixio.README.html">nixio.README</a>
- </li>
- <li>
- <a href="../modules/nixio.Socket.html">nixio.Socket</a>
- </li>
- <li>
- <a href="../modules/nixio.TLSContext.html">nixio.TLSContext</a>
- </li>
- <li>
- <a href="../modules/nixio.TLSSocket.html">nixio.TLSSocket</a>
- </li>
- <li>
- <a href="../modules/nixio.UnifiedIO.html">nixio.UnifiedIO</a>
- </li>
- <li>
- <a href="../modules/nixio.bin.html">nixio.bin</a>
- </li>
- <li>
- <a href="../modules/nixio.bit.html">nixio.bit</a>
- </li>
- <li>
- <a href="../modules/nixio.crypto.html">nixio.crypto</a>
- </li>
- <li>
- <a href="../modules/nixio.fs.html">nixio.fs</a>
- </li>
- </ul>
- <!-- File list -->
- </div><!-- id="navigation" -->
- <div id="content">
- <h1>Object Instance <code>luci.ip.cidr</code></h1>
- <p>
- IP CIDR Object.
- Represents an IPv4 or IPv6 address range.</p>
- <h2>Functions</h2>
- <table class="function_list">
- <tr>
- <td class="name" nowrap><a href="#cidr.is4">cidr:is4</a> ()</td>
- <td class="summary">
-
- Checks whether the CIDR instance is an IPv4 address range
- </td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.is4rfc1918">cidr:is4rfc1918</a> ()</td>
- <td class="summary">
-
- Checks whether the CIDR instance is within the private RFC1918 address space
- </td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.is4linklocal">cidr:is4linklocal</a> ()</td>
- <td class="summary">
-
- Checks whether the CIDR instance is an IPv4 link local (Zeroconf) address
- </td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.is6">cidr:is6</a> ()</td>
- <td class="summary">
-
- Checks whether the CIDR instance is an IPv6 address range
- </td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.is6linklocal">cidr:is6linklocal</a> ()</td>
- <td class="summary">
-
- Checks whether the CIDR instance is an IPv6 link local address
- </td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.is6mapped4">cidr:is6mapped4</a> ()</td>
- <td class="summary">
-
- Checks whether the CIDR instance is an IPv6 mapped IPv4 address
- </td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.lower">cidr:lower</a> (addr)</td>
- <td class="summary">
-
- Checks whether this CIDR instance is lower than the given argument.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.higher">cidr:higher</a> (addr)</td>
- <td class="summary">
-
- Checks whether this CIDR instance is higher than the given argument.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.equal">cidr:equal</a> (addr)</td>
- <td class="summary">
-
- Checks whether this CIDR instance is equal to the given argument.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.prefix">cidr:prefix</a> (mask)</td>
- <td class="summary">
-
- Get or set prefix size of CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.network">cidr:network</a> (mask)</td>
- <td class="summary">
-
- Derive network address of CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.host">cidr:host</a> ()</td>
- <td class="summary">
-
- Derive host address of CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.mask">cidr:mask</a> (mask)</td>
- <td class="summary">
-
- Derive netmask of CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.broadcast">cidr:broadcast</a> (mask)</td>
- <td class="summary">
-
- Derive broadcast address of CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.mapped4">cidr:mapped4</a> ()</td>
- <td class="summary">
-
- Derive mapped IPv4 address of CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.contains">cidr:contains</a> (addr)</td>
- <td class="summary">
-
- Test whether CIDR contains given range.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.add">cidr:add</a> (amount, inplace)</td>
- <td class="summary">
-
- Add given amount to CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.sub">cidr:sub</a> (amount, inplace)</td>
- <td class="summary">
-
- Subtract given amount from CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.minhost">cidr:minhost</a> ()</td>
- <td class="summary">
-
- Calculate the lowest possible host address within this CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.maxhost">cidr:maxhost</a> ()</td>
- <td class="summary">
-
- Calculate the highest possible host address within this CIDR instance.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#cidr.string">cidr:string</a> ()</td>
- <td class="summary">
-
- Convert CIDR instance into string representation.</td>
- </tr>
- </table>
- <br/>
- <br/>
- <h2><a name="functions"></a>Functions</h2>
- <dl class="function">
- <dt><a name="cidr.is4"></a><strong>cidr:is4</strong> ()</dt>
- <dd>
-
- Checks whether the CIDR instance is an IPv4 address range
- <h3>Return value:</h3>
- <code>true</code> if the CIDR is an IPv4 range, else <code>false</code>
- <h3>See also:</h3>
- <ul>
-
- <li><a href="#cidr.is6">
- cidr:is6
- </a>
-
- </ul>
- </dd>
- <dt><a name="cidr.is4rfc1918"></a><strong>cidr:is4rfc1918</strong> ()</dt>
- <dd>
-
- Checks whether the CIDR instance is within the private RFC1918 address space
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("192.168.45.2/24")
- if addr:is4rfc1918() then
- print("Is a private address")
- end</pre>
- <h3>Return value:</h3>
- <code>true</code> if the entire range of this CIDR lies within one of
- the ranges <code>10.0.0.0-10.255.255.255</code>,
- <code>172.16.0.0-172.31.0.0</code> or
- <code>192.168.0.0-192.168.255.255</code>, else <code>false</code>.
- </dd>
- <dt><a name="cidr.is4linklocal"></a><strong>cidr:is4linklocal</strong> ()</dt>
- <dd>
-
- Checks whether the CIDR instance is an IPv4 link local (Zeroconf) address
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("169.254.34.125")
- if addr:is4linklocal() then
- print("Is a zeroconf address")
- end</pre>
- <h3>Return value:</h3>
- <code>true</code> if the entire range of this CIDR lies within the range
- the range <code>169.254.0.0-169.254.255.255</code>, else <code>false</code>.
- </dd>
- <dt><a name="cidr.is6"></a><strong>cidr:is6</strong> ()</dt>
- <dd>
-
- Checks whether the CIDR instance is an IPv6 address range
- <h3>Return value:</h3>
- <code>true</code> if the CIDR is an IPv6 range, else <code>false</code>
- <h3>See also:</h3>
- <ul>
-
- <li><a href="#cidr.is4">
- cidr:is4
- </a>
-
- </ul>
- </dd>
- <dt><a name="cidr.is6linklocal"></a><strong>cidr:is6linklocal</strong> ()</dt>
- <dd>
-
- Checks whether the CIDR instance is an IPv6 link local address
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("fe92:53a:3216:af01:221:63ff:fe75:aa17/64")
- if addr:is6linklocal() then
- print("Is a linklocal address")
- end</pre>
- <h3>Return value:</h3>
- <code>true</code> if the entire range of this CIDR lies within the range
- the <code>fe80::/10</code> range, else <code>false</code>.
- </dd>
- <dt><a name="cidr.is6mapped4"></a><strong>cidr:is6mapped4</strong> ()</dt>
- <dd>
-
- Checks whether the CIDR instance is an IPv6 mapped IPv4 address
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("::ffff:192.168.1.1")
- if addr:is6mapped4() then
- print("Is a mapped IPv4 address")
- end</pre>
- <h3>Return value:</h3>
- <code>true</code> if the address is an IPv6 mapped IPv4 address in the
- form <code>::ffff:1.2.3.4</code>.
- </dd>
- <dt><a name="cidr.lower"></a><strong>cidr:lower</strong> (addr)</dt>
- <dd>
-
- Checks whether this CIDR instance is lower than the given argument.
- The comparisation follows these rules:
- <ul><li>An IPv4 address is always lower than an IPv6 address</li>
- <li>Prefix sizes are ignored</li></ul>
- <h3>Parameters</h3>
- <ul>
-
- <li>
- addr: A <code>luci.ip.cidr</code> instance or a string convertable by
- <code>luci.ip.new()</code> to compare against.
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("192.168.1.1")
- print(addr:lower(addr)) -- false
- print(addr:lower("10.10.10.10/24")) -- false
- print(addr:lower(luci.ip.new("::1"))) -- true
- print(addr:lower(luci.ip.new("192.168.200.1"))) -- true</pre>
- <h3>Return value:</h3>
- <code>true</code> if this CIDR is lower than the given address,
- else <code>false</code>.
- <h3>See also:</h3>
- <ul>
-
- <li><a href="#cidr.higher">
- cidr:higher
- </a>
-
- <li><a href="#cidr.equal">
- cidr:equal
- </a>
-
- </ul>
- </dd>
- <dt><a name="cidr.higher"></a><strong>cidr:higher</strong> (addr)</dt>
- <dd>
-
- Checks whether this CIDR instance is higher than the given argument.
- The comparisation follows these rules:
- <ul><li>An IPv4 address is always lower than an IPv6 address</li>
- <li>Prefix sizes are ignored</li></ul>
- <h3>Parameters</h3>
- <ul>
-
- <li>
- addr: A <code>luci.ip.cidr</code> instance or a string convertable by
- <code>luci.ip.new()</code> to compare against.
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("192.168.1.1")
- print(addr:higher(addr)) -- false
- print(addr:higher("10.10.10.10/24")) -- true
- print(addr:higher(luci.ip.new("::1"))) -- false
- print(addr:higher(luci.ip.new("192.168.200.1"))) -- false</pre>
- <h3>Return value:</h3>
- <code>true</code> if this CIDR is higher than the given address,
- else <code>false</code>.
- <h3>See also:</h3>
- <ul>
-
- <li><a href="#cidr.lower">
- cidr:lower
- </a>
-
- <li><a href="#cidr.equal">
- cidr:equal
- </a>
-
- </ul>
- </dd>
- <dt><a name="cidr.equal"></a><strong>cidr:equal</strong> (addr)</dt>
- <dd>
-
- Checks whether this CIDR instance is equal to the given argument.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- addr: A <code>luci.ip.cidr</code> instance or a string convertable by
- <code>luci.ip.new()</code> to compare against.
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("192.168.1.1")
- print(addr:equal(addr)) -- true
- print(addr:equal("192.168.1.1")) -- true
- print(addr:equal(luci.ip.new("::1"))) -- false
-
- local addr6 = luci.ip.new("::1")
- print(addr6:equal("0:0:0:0:0:0:0:1/64")) -- true
- print(addr6:equal(luci.ip.new("fe80::221:63ff:fe75:aa17"))) -- false</pre>
- <h3>Return value:</h3>
- <code>true</code> if this CIDR is equal to the given address,
- else <code>false</code>.
- <h3>See also:</h3>
- <ul>
-
- <li><a href="#cidr.lower">
- cidr:lower
- </a>
-
- <li><a href="#cidr.higher">
- cidr:higher
- </a>
-
- </ul>
- </dd>
- <dt><a name="cidr.prefix"></a><strong>cidr:prefix</strong> (mask)</dt>
- <dd>
-
- Get or set prefix size of CIDR instance.
- If the optional mask parameter is given, the prefix size of this CIDR is altered
- else the current prefix size is returned.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- mask: Either a number containing the number of bits (<code>0..32</code>
- for IPv4, <code>0..128</code> for IPv6) or a string containing a valid
- netmask (optional)
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local range = luci.ip.new("192.168.1.1/255.255.255.0")
- print(range:prefix()) -- 24
-
- range:prefix(16)
- print(range:prefix()) -- 16
-
- range:prefix("255.255.255.255")
- print(range:prefix()) -- 32</pre>
- <h3>Return value:</h3>
- Bit count of the current prefix size
- </dd>
- <dt><a name="cidr.network"></a><strong>cidr:network</strong> (mask)</dt>
- <dd>
-
- Derive network address of CIDR instance.
-
- Returns a new CIDR instance representing the network address of this instance
- with all host parts masked out. The used prefix size can be overridden by the
- optional mask parameter.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- mask: Either a number containing the number of bits (<code>0..32</code>
- for IPv4, <code>0..128</code> for IPv6) or a string containing a valid
- netmask (optional)
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local range = luci.ip.new("192.168.62.243/255.255.0.0")
- print(range:network()) -- "192.168.0.0"
- print(range:network(24)) -- "192.168.62.0"
- print(range:network("255.255.255.0")) -- "192.168.62.0"
-
- local range6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
- print(range6:network()) -- "fd9b:62b3:9cc5::"</pre>
- <h3>Return value:</h3>
- CIDR instance representing the network address
- </dd>
- <dt><a name="cidr.host"></a><strong>cidr:host</strong> ()</dt>
- <dd>
-
- Derive host address of CIDR instance.
-
- This function essentially constructs a copy of this CIDR with the prefix size
- set to <code>32</code> for IPv4 and <code>128</code> for IPv6.
- <h3>Usage:</h3>
- <pre>local range = luci.ip.new("172.19.37.45/16")
- print(range) -- "172.19.37.45/16"
- print(range:host()) -- "172.19.37.45"</pre>
- <h3>Return value:</h3>
- CIDR instance representing the host address
- </dd>
- <dt><a name="cidr.mask"></a><strong>cidr:mask</strong> (mask)</dt>
- <dd>
-
- Derive netmask of CIDR instance.
-
- Constructs a CIDR instance representing the netmask of this instance. The used
- prefix size can be overridden by the optional mask parameter.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- mask: Either a number containing the number of bits (<code>0..32</code>
- for IPv4, <code>0..128</code> for IPv6) or a string containing a valid
- netmask (optional)
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local range = luci.ip.new("172.19.37.45/16")
- print(range:mask()) -- "255.255.0.0"
- print(range:mask(24)) -- "255.255.255.0"
- print(range:mask("255.0.0.0")) -- "255.0.0.0"</pre>
- <h3>Return value:</h3>
- CIDR instance representing the netmask
- </dd>
- <dt><a name="cidr.broadcast"></a><strong>cidr:broadcast</strong> (mask)</dt>
- <dd>
-
- Derive broadcast address of CIDR instance.
-
- Constructs a CIDR instance representing the broadcast address of this instance.
- The used prefix size can be overridden by the optional mask parameter.
-
- This function has no effect on IPv6 instances, it will return nothing in this
- case.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- mask: Either a number containing the number of bits (<code>0..32</code>
- for IPv4, <code>0..128</code> for IPv6) or a string containing a valid
- netmask (optional)
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local range = luci.ip.new("172.19.37.45/16")
- print(range:broadcast()) -- "172.19.255.255"
- print(range:broadcast(24)) -- "172.19.37.255"
- print(range:broadcast("255.0.0.0")) -- "172.255.255.255"</pre>
- <h3>Return value:</h3>
- Return a new CIDR instance representing the broadcast address if this
- instance is an IPv4 range, else return nothing.
- </dd>
- <dt><a name="cidr.mapped4"></a><strong>cidr:mapped4</strong> ()</dt>
- <dd>
-
- Derive mapped IPv4 address of CIDR instance.
-
- Constructs a CIDR instance representing the IPv4 address of the IPv6 mapped
- IPv4 address in this instance.
-
- This function has no effect on IPv4 instances or IPv6 instances which are not a
- mapped address, it will return nothing in this case.
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("::ffff:172.16.19.1")
- print(addr:mapped4()) -- "172.16.19.1"</pre>
- <h3>Return value:</h3>
- Return a new CIDR instance representing the IPv4 address if this
- instance is an IPv6 mapped IPv4 address, else return nothing.
- </dd>
- <dt><a name="cidr.contains"></a><strong>cidr:contains</strong> (addr)</dt>
- <dd>
-
- Test whether CIDR contains given range.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- addr: A <code>luci.ip.cidr</code> instance or a string convertable by
- <code>luci.ip.new()</code> to test.
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local range = luci.ip.new("10.24.0.0/255.255.0.0")
- print(range:contains("10.24.5.1")) -- true
- print(range:contains("::1")) -- false
- print(range:contains("10.0.0.0/8")) -- false
-
- local range6 = luci.ip.new("fe80::/10")
- print(range6:contains("fe80::221:63f:fe75:aa17/64")) -- true
- print(range6:contains("fd9b:6b3:c5:0:221:63f:fe75:aa17/64")) -- false</pre>
- <h3>Return value:</h3>
- <code>true</code> if this instance fully contains the given address else
- <code>false</code>.
- </dd>
- <dt><a name="cidr.add"></a><strong>cidr:add</strong> (amount, inplace)</dt>
- <dd>
-
- Add given amount to CIDR instance. If the result would overflow the maximum
- address space, the result is set to the highest possible address.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- amount: A numeric value between 0 and 0xFFFFFFFF, a
- <code>luci.ip.cidr</code> instance or a string convertable by
- <code>luci.ip.new()</code>.
- </li>
-
- <li>
- inplace: If <code>true</code>, modify this instance instead of returning
- a new derived CIDR instance.
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("192.168.1.1/24")
- print(addr:add(250)) -- "192.168.1.251/24"
- print(addr:add("0.0.99.0")) -- "192.168.100.1/24"
-
- addr:add(256, true) -- true
- print(addr) -- "192.168.2.1/24
-
- addr:add("255.0.0.0", true) -- false (overflow)
- print(addr) -- "255.255.255.255/24
-
- local addr6 = luci.ip.new("fe80::221:63f:fe75:aa17/64")
- print(addr6:add(256)) -- "fe80::221:63f:fe75:ab17/64"
- print(addr6:add("::ffff:0")) -- "fe80::221:640:fe74:aa17/64"
-
- addr:add(256, true) -- true
- print(addr) -- "fe80::221:63f:fe75:ab17/64
-
- addr:add("ffff::", true) -- false (overflow)
- print(addr) -- "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/64"</pre>
- <h3>Return value:</h3>
- <ul>
- <li>When adding inplace: Return <code>true</code> if the addition succeeded
- or <code>false</code> when the addition overflowed.</li>
- <li>When deriving new CIDR: Return new instance representing the value of
- this instance plus the added amount or the highest possible address if
- the addition overflowed the available address space.</li></ul>
- </dd>
- <dt><a name="cidr.sub"></a><strong>cidr:sub</strong> (amount, inplace)</dt>
- <dd>
-
- Subtract given amount from CIDR instance. If the result would under, the lowest
- possible address is returned.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- amount: A numeric value between 0 and 0xFFFFFFFF, a
- <code>luci.ip.cidr</code> instance or a string convertable by
- <code>luci.ip.new()</code>.
- </li>
-
- <li>
- inplace: If <code>true</code>, modify this instance instead of returning
- a new derived CIDR instance.
- </li>
-
- </ul>
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("192.168.1.1/24")
- print(addr:sub(256)) -- "192.168.0.1/24"
- print(addr:sub("0.168.0.0")) -- "192.0.1.1/24"
-
- addr:sub(256, true) -- true
- print(addr) -- "192.168.0.1/24
-
- addr:sub("255.0.0.0", true) -- false (underflow)
- print(addr) -- "0.0.0.0/24
-
- local addr6 = luci.ip.new("fe80::221:63f:fe75:aa17/64")
- print(addr6:sub(256)) -- "fe80::221:63f:fe75:a917/64"
- print(addr6:sub("::ffff:0")) -- "fe80::221:63e:fe76:aa17/64"
-
- addr:sub(256, true) -- true
- print(addr) -- "fe80::221:63f:fe75:a917/64"
-
- addr:sub("ffff::", true) -- false (underflow)
- print(addr) -- "::/64"</pre>
- <h3>Return value:</h3>
- <ul>
- <li>When subtracting inplace: Return <code>true</code> if the subtraction
- succeeded or <code>false</code> when the subtraction underflowed.</li>
- <li>When deriving new CIDR: Return new instance representing the value of
- this instance minus the subtracted amount or the lowest address if
- the subtraction underflowed.</li></ul>
- </dd>
- <dt><a name="cidr.minhost"></a><strong>cidr:minhost</strong> ()</dt>
- <dd>
-
- Calculate the lowest possible host address within this CIDR instance.
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("192.168.123.56/24")
- print(addr:minhost()) -- "192.168.123.1"
-
- local addr6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
- print(addr6:minhost()) -- "fd9b:62b3:9cc5::1"</pre>
- <h3>Return value:</h3>
- Returns a new CIDR instance representing the lowest host address
- within this range.
- </dd>
- <dt><a name="cidr.maxhost"></a><strong>cidr:maxhost</strong> ()</dt>
- <dd>
-
- Calculate the highest possible host address within this CIDR instance.
- <h3>Usage:</h3>
- <pre>local addr = luci.ip.new("192.168.123.56/24")
- print(addr:maxhost()) -- "192.168.123.254" (.255 is broadcast)
-
- local addr6 = luci.ip.new("fd9b:62b3:9cc5:0:221:63ff:fe75:aa17/64")
- print(addr6:maxhost()) -- "fd9b:62b3:9cc5:0:ffff:ffff:ffff:ffff"</pre>
- <h3>Return value:</h3>
- Returns a new CIDR instance representing the highest host address
- within this range.
- </dd>
- <dt><a name="cidr.string"></a><strong>cidr:string</strong> ()</dt>
- <dd>
-
- Convert CIDR instance into string representation.
-
- If the prefix size of instance is less than 32 for IPv4 or 128 for IPv6, the
- address is returned in the form "address/prefix" otherwise just "address".
-
- It is usually not required to call this function directly as CIDR objects
- define it as __tostring function in the associated metatable.
- <h3>Return value:</h3>
- Returns a string representing the range or address of this CIDR instance
- </dd>
- </dl>
- </div> <!-- id="content" -->
- </div> <!-- id="main" -->
- <div id="about">
- <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>
- </div> <!-- id="about" -->
- </div> <!-- id="container" -->
- </body>
- </html>
|