Declaration
INET6_ATON(expr)
Description
Converts the specified IPv6 or IPv4 network address into a binary string that represents the address value in network byte order (big-endian).
IPv6 addresses require more bytes than the maximum integer type can hold. Therefore, this function returns a VARBINARY data type, where VARBINARY(16) indicates an IPv6 address and VARBINARY(4) indicates an IPv4 address. If the parameter is not a valid address, NULL is returned.
The INET6_ATON() function has the following limitations on valid parameters:
Using a zone ID at the end, such as fc50::3%1 or fc50::3%eth1, is not allowed.
IP addresses with a network mask at the end, such as 2002:45f:3:ba::/64 or 198.xx.100.0/24, are not allowed.
Only classless IP addresses are supported for representing IPv4 addresses. Classful addresses such as 198.51.1 will be rejected.
The port number cannot be used at the end, for example, 198.xx.100.2:8082.
Hexadecimal digits are not allowed in the IP address, for example, 198.0xa0.1.2.
Octal numbers are not supported: 198.xx.010.1 is considered 198.xx.10.1, not 198.xx.8.1.
These IPv4 restrictions also apply to IPv6 addresses that have an IPv4 address portion, such as IPv4-compatible addresses or IPv4-mapped addresses.
To convert an IPv4 address expr represented as an INT value to an IPv6 address represented as a VARBINARY value, use the following expression:
INET6_ATON(INET_NTOA(expr))
Examples
obclient> SELECT HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089'));
+----------------------------------------------+
| HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089')) |
+----------------------------------------------+
| FDFE0000000000005A55CAFFFEFA9089 |
+----------------------------------------------+
1 row in set