doc-exports/docs/dws/dev/dws_06_0016.html
Lu, Huayi e6fa411af0 DWS DEV 830.201 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:24:04 +00:00

154 lines
18 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<a name="EN-US_TOPIC_0000001233510147"></a><a name="EN-US_TOPIC_0000001233510147"></a>
<h1 class="topictitle1">Network Address Types</h1>
<div id="body8662426"><p id="EN-US_TOPIC_0000001233510147__a02dbb622c6974478aa90ffa2edceb873"><span id="EN-US_TOPIC_0000001233510147__text927379203">GaussDB(DWS)</span> offers data types to store IPv4, IPv6, and MAC addresses.</p>
<p id="EN-US_TOPIC_0000001233510147__ad97f41ef54a74e7cb3c9ffa6e7fe1053">It is better to use network address types instead of plaintext types to store IPv4, IPv6, and MAC addresses, because these types offer input error checking and specialized operators and functions. For details, see <a href="dws_06_0038.html">Network Address Functions and Operators</a>.</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233510147__tf15c83379d6d40ed9e7a46db54b835bb" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Network Address Types</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233510147__r2a4c76431beb4d2b98105a6a3692d247"><th align="left" class="cellrowborder" valign="top" width="25.247475252474754%" id="mcps1.3.3.2.4.1.1"><p id="EN-US_TOPIC_0000001233510147__a6c153419b6544c7595ae2323cc8b485f">Name</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="32.966703329667034%" id="mcps1.3.3.2.4.1.2"><p id="EN-US_TOPIC_0000001233510147__a0e16f8dea73c46a0a47a970d8113e3ac">Storage Space</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="41.785821417858216%" id="mcps1.3.3.2.4.1.3"><p id="EN-US_TOPIC_0000001233510147__ac4a9cc9b00284aa8970c9ea29aaf81f6">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001233510147__r3ea8dabb60a24de29615d5d062bcaf67"><td class="cellrowborder" valign="top" width="25.247475252474754%" headers="mcps1.3.3.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__acfd0ea3c6eb74cccadd48e3d1ae5d5e7">cidr</p>
</td>
<td class="cellrowborder" valign="top" width="32.966703329667034%" headers="mcps1.3.3.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__a4b848394b0be4769b0ac77b63624eb00">7 or 19 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="41.785821417858216%" headers="mcps1.3.3.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a7c24bf754e6746d0ad5b0d4399c721df">IPv4 or IPv6 networks</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__rce62f2075ed440c1ad91bcf3d27bd75f"><td class="cellrowborder" valign="top" width="25.247475252474754%" headers="mcps1.3.3.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__aa29d410bc53546e099be9c537b7a1fdf">inet</p>
</td>
<td class="cellrowborder" valign="top" width="32.966703329667034%" headers="mcps1.3.3.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__ac878ad8875b0477ab353c5241f066664">7 or 19 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="41.785821417858216%" headers="mcps1.3.3.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a1f1356e96eb44553a6370f69839167ad">IPv4 or IPv6 hosts and networks</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__r2045fb24f7684c8bb4d5a1ace968e008"><td class="cellrowborder" valign="top" width="25.247475252474754%" headers="mcps1.3.3.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__adebae43694534a50be0a3308b4b1d011">macaddr</p>
</td>
<td class="cellrowborder" valign="top" width="32.966703329667034%" headers="mcps1.3.3.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__a4f50b2f62bb1405580fb7271e6594c5b">6 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="41.785821417858216%" headers="mcps1.3.3.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a5abeff293b624862927b7ba61df19907">MAC addresses</p>
</td>
</tr>
</tbody>
</table>
</div>
<p id="EN-US_TOPIC_0000001233510147__aec82e1dbc53646debe7d1fefed5e181e">When sorting <strong id="EN-US_TOPIC_0000001233510147__b84235270692438">inet</strong> or <strong id="EN-US_TOPIC_0000001233510147__b84235270692444">cidr</strong> data types, IPv4 addresses will always sort before IPv6 addresses, including IPv4 addresses encapsulated or mapped to IPv6 addresses, such as ::10.2.3.4 or ::ffff:10.4.3.2.</p>
<div class="section" id="EN-US_TOPIC_0000001233510147__s1015eadf9fba4a289d2492c36b9b9287"><h4 class="sectiontitle">cidr</h4><p id="EN-US_TOPIC_0000001233510147__a242fe1e9989346f298ae15047ff371bb">The <strong id="EN-US_TOPIC_0000001233510147__b84235270692639">cidr</strong> type (Classless Inter-Domain Routing) holds an IPv4 or IPv6 network specification. The format for specifying networks is <strong id="EN-US_TOPIC_0000001233510147__b8423527069280">address/y</strong> where <strong id="EN-US_TOPIC_0000001233510147__b8423527069286">address</strong> is the network represented as an IPv4 or IPv6 address, and y is the number of bits in the netmask. If <strong id="EN-US_TOPIC_0000001233510147__b84235270692936">y</strong> is omitted, it is calculated using assumptions from the older classful network numbering system, except it will be at least large enough to include all of the octets written in the input.</p>
<ul id="EN-US_TOPIC_0000001233510147__ul12944132024615"><li id="EN-US_TOPIC_0000001233510147__li13945202012467">Example 1: Convert a value in the CIDR format to an IP address segment.<p id="EN-US_TOPIC_0000001233510147__p821548104613"><a name="EN-US_TOPIC_0000001233510147__li13945202012467"></a><a name="li13945202012467"></a>For example, <strong id="EN-US_TOPIC_0000001233510147__b15474287129">10.0.0.0/8</strong> is converted into a 32-bit binary address <strong id="EN-US_TOPIC_0000001233510147__b104811289126">00001010.00000000.00000000.00000000</strong>. <strong id="EN-US_TOPIC_0000001233510147__b602913432">/8</strong> indicates an 8-bit network ID. The first eight bits of the 32-bit binary address are fixed. The corresponding network segment is 00001010.00000000.00000000.00000000-00001010.11111111.11111111.11111111. <strong id="EN-US_TOPIC_0000001233510147__b19655111384311">10.0.0.0/8</strong> indicates that the subnet mask is 255.0.0.0 and the corresponding network segment is 10.0.0.0-10.255.255.255.</p>
</li><li id="EN-US_TOPIC_0000001233510147__li12449125410461">Example 2: Convert an IP address segment to the CIDR format.<p id="EN-US_TOPIC_0000001233510147__p116611510114711"><a name="EN-US_TOPIC_0000001233510147__li12449125410461"></a><a name="li12449125410461"></a>For the IP address segment <strong id="EN-US_TOPIC_0000001233510147__b1772885745612">192.168.0.0192.168.31.255</strong>, the last two segments can be converted into a binary address <strong id="EN-US_TOPIC_0000001233510147__b372815579560">00000000.00000000-00011111.11111111</strong>. The first 19 bits (8 x 2 + 3) are fixed. Therefore, the binary address is 192.168.0.0/19.</p>
</li></ul>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233510147__tf35133551efa4f4b921bc508402f61b9" frame="border" border="1" rules="all"><caption><b>Table 2 </b><strong id="EN-US_TOPIC_0000001233510147__b842352706104343">cidr</strong> type input examples</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233510147__r72f31ddd8d864e8b83af712dabe4c0d9"><th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.5.4.2.4.1.1"><p id="EN-US_TOPIC_0000001233510147__aba406b888cea4b818e169ad5dc81a2ba"><strong id="EN-US_TOPIC_0000001233510147__b84235270610448">cidr</strong> Input</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.5.4.2.4.1.2"><p id="EN-US_TOPIC_0000001233510147__abea9e4af1be3455eaab8ae200411ae7f"><strong id="EN-US_TOPIC_0000001233510147__b842352706104420">cidr</strong> Output</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.5.4.2.4.1.3"><p id="EN-US_TOPIC_0000001233510147__a62f2c69e55eb4e19acd8a5cc706d1be5">abbrev (cidr)</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001233510147__r8909e0554f914bd2965e62f8bbaf82ed"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__a4e506a59c3e1483a8eb42881979f5adb">192.168.100.128/25</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__acbb92981231a4f0e95d9546b489bb2de">192.168.100.128/25</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a69b6a80775b346d1ae0b82cfe52cc595">192.168.100.128/25</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__rfa3b3c9fdce84dcd991ae8e9e91c51e2"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__a9b54a2a9a52b4d2fb146ba388e12bb82">192.168/24</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__a5c322ca922024ae7aff82b7a987b24a6">192.168.0.0/24</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a5de1647b6bd6480b89d7387fb3dc920d">192.168.0/24</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__r55a882080ad24dd8beb35c2ae4445cb5"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__a641d8558904f48799e3a668493b1cf9b">192.168/25</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__aeca24e017a924bc5a1b12bc9b02b0b87">192.168.0.0/25</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a039566b974a04a3e90b6f9e33498ef36">192.168.0.0/25</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__rea820ffa5b464d6e8b81757dd1d58289"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__ac142ed6795f24d388d1033debe557499">192.168.1</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__ae5e26f07ca5d4ab7811f3ccf9c04f9ee">192.168.1.0/24</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a7cac72306d8a40baad5f32f693ac009d">192.168.1/24</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__r7407bd7fab1c4ff3af01fce05cee8fdb"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__accfcc7e4d729406381aae09091e3cc83">192.168</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__a7dc76a8fb3844748861741d567fd407d">192.168.0.0/24</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a69e7428d82384ad681a905e105a47fcf">192.168.0/24</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__rdd0a196fcdd845939fe95caec495ddd6"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__a724bd81122364761a3b7940ec2afdade">10.1.2</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__aef0b48db22164b838e5f763f208ce656">10.1.2.0/24</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a8189c9e1023044c9bf42a484a56844da">10.1.2/24</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__r7cb71bb3745d4f3d93ca3dfe258fcd69"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__a1d747c14c97a45e19be004054b5f1198">10.1</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__afe7a413e040e446b936adc66b17ae9b9">10.1.0.0/16</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a587299518729488798bf29ab64c291c1">10.1/16</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__r4169defbb37644dd9e9c45b766a6edfa"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__a040667ac0e9b44f3bd4b65bcb3db4e88">10</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__af21ad60935a747d4b07a519dc033f229">10.0.0.0/8</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a0a67612cdd9541c4a6997bf09c5a74f5">10/8</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__r7db8ee2a923c4ad98b2f2be57b6ab05d"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__a5442730d8ff644239594e7376146478c">10.1.2.3/32</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__a3d1e11335de44ad0858f8b1c53850424">10.1.2.3/32</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__af37fcbfb432443d6a2be2d7a2016408c">10.1.2.3/32</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__rbd5e4d59909f4b5f9518a5967c976791"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__abeb4d57c5ca141438b68b216426c9974">2001:4f8:3:ba::/64</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__a478b2d7fa2ec4fcea6b67e4331aa277e">2001:4f8:3:ba::/64</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__aabfe46349c914828b6bb8ce0d03e2a23">2001:4f8:3:ba::/64</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233510147__ra441401527234a36968d729e6d25627b"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.1 "><p id="EN-US_TOPIC_0000001233510147__a50669b8404bf4e2897d8f7697d948a36">2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.2 "><p id="EN-US_TOPIC_0000001233510147__a6a101cc6b4a9440bbb4b5a7670cc2f0d">2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.5.4.2.4.1.3 "><p id="EN-US_TOPIC_0000001233510147__a050503dc4d0149c38db78836490aece4">2001:4f8:3:ba:2e0:81ff:fe22:d1f1</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001233510147__s87b1cb4d5afb419496070f24cac7929b"><h4 class="sectiontitle">inet</h4><p id="EN-US_TOPIC_0000001233510147__a2af3d7c2ed9e4d2d91cadd1d0fc2e702">The <strong id="EN-US_TOPIC_0000001233510147__b84235270693328">inet</strong> type holds an IPv4 or IPv6 host address, and optionally its subnet, all in one field. The subnet is represented by the number of network address bits present in the host address (the "netmask"). If the netmask is 32 and the address is IPv4, then the value does not indicate a subnet, only a single host. In IPv6, the address length is 128 bits, so 128 bits specify a unique host address.</p>
<p id="EN-US_TOPIC_0000001233510147__a46f0321ae91e4332926222d616ac3c00">The input format for this type is <strong id="EN-US_TOPIC_0000001233510147__b84235270693622">address/y</strong> where <strong id="EN-US_TOPIC_0000001233510147__b84235270693629">address</strong> is an IPv4 or IPv6 address and <strong id="EN-US_TOPIC_0000001233510147__b84235270693650">y</strong> is the number of bits in the netmask. If the <strong id="EN-US_TOPIC_0000001233510147__b84235270693749">/y</strong> portion is missing, the netmask is 32 for IPv4 and 128 for IPv6, so the value represents just a single host. On display, the <strong id="EN-US_TOPIC_0000001233510147__b84235270693827">/y</strong> portion is suppressed if the netmask specifies a single host.</p>
<p id="EN-US_TOPIC_0000001233510147__a472cc4c3aa5b470ba9c6e435b2b3a078">The essential difference between the <strong id="EN-US_TOPIC_0000001233510147__b84235270693948">inet</strong> and <strong id="EN-US_TOPIC_0000001233510147__b84235270693958">cidr</strong> data types is that <strong id="EN-US_TOPIC_0000001233510147__b84235270694041">inet</strong> accepts values with nonzero bits to the right of the netmask, whereas <strong id="EN-US_TOPIC_0000001233510147__b84235270694136">cidr</strong> does not.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001233510147__s1731e84e30c9450e8549fa9f5cf9ebaa"><h4 class="sectiontitle">macaddr</h4><p id="EN-US_TOPIC_0000001233510147__a598c2a7e20df4101b758497ecbb1aac0">The <strong id="EN-US_TOPIC_0000001233510147__b84235270615525">macaddr</strong> type stores MAC addresses, known for example from Ethernet card hardware addresses (although MAC addresses are used for other purposes as well). Input is accepted in the following formats:</p>
<pre class="screen" id="EN-US_TOPIC_0000001233510147__s4d2fd9fd9417401d86c86bcf4f073735">'08:00:2b:01:02:03'
'08-00-2b-01-02-03'
'08002b:010203'
'08002b-010203'
'0800.2b01.0203'
'08002b010203'</pre>
<p id="EN-US_TOPIC_0000001233510147__aa0ee5b7a8ce14f57bd4d51c7768970bc">These examples would all specify the same address. Upper and lower cases are accepted for the digits a through f. Output is always in the first of the forms shown.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0008.html">Data Types</a></div>
</div>
</div>