Syntax
INET6_ATON(expr)
Purpose
Converts the specified IPv6 or IPv4 network address to a binary string that represents the address value in network byte order (big-endian).
IPv6 addresses in numeric format require more bytes than the maximum size of an integer type, so this function returns a VARBINARY data type. VARBINARY(16) represents an IPv6 address, and VARBINARY(4) represents an IPv4 address. If the argument is not a valid address, NULL is returned.
INET6_ATON() has the following restrictions for valid arguments:
Zone IDs cannot be used at the end of the address, such as fc50::3%1 or fc50::3%eth1.
Network masks cannot be used at the end of the address, such as 2002:45f:3:ba::/64 or 198.xx.100.0/24.
Only classless IPv4 addresses are supported. Classful addresses such as 198.51.1 are rejected.
Port numbers cannot be used at the end of the address, such as 198.xx.100.2:8082.
Hexadecimal digits cannot be used in the address, such as 198.0xa0.1.2.
Octal numbers are not supported. 198.xx.010.1 is treated as 198.xx.10.1, not 198.xx.8.1.
These IPv4 restrictions also apply to IPv6 addresses that contain an IPv4 address part, such as IPv4-compatible addresses or IPv4-mapped addresses.
To convert an IPv4 address expr represented by the INT data type to an IPv6 address represented by 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
