Skip to main content
Version: V1.0.0

INET6_ATON

Declaration

INET6_ATON(expr)

Description

Returns the specified IPv6 or IPv4 network address as a binary string in network byte order (big-endian).

Since IPv6 addresses in numeric format require more bytes than the maximum size of an integer type, this function returns the VARBINARY data type. Specifically, VARBINARY(16) represents an IPv6 address, and VARBINARY(4) represents an IPv4 address. If the parameter is not a valid address, it returns NULL.

INET6_ATON() has the following limitations for valid parameters:

  • Zone IDs cannot be specified at the end of the address, such as in fc50::3%1 or fc50::3%eth1.

  • Network masks cannot be specified at the end of the address, such as in 2002:45f:3:ba::/64 or 198.xx.100.0/24.

  • Only classless address representations are supported for IPv4 addresses. Classful addresses such as 198.51.1 are rejected.

  • Port numbers cannot be specified at the end of the address, such as in 198.xx.100.2:8082.

  • Hexadecimal digits cannot be used in the address, such as in 198.0xa0.1.2.

  • Octal numbers are not supported. For example, 198.xx.010.1 is interpreted as 198.xx.10.1, not 198.xx.8.1.

These IPv4 limitations 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

SELECT HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089'));
+----------------------------------------------+
| HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089')) |
+----------------------------------------------+
| FDFE0000000000005A55CAFFFEFA9089 |
+----------------------------------------------+
1 row in set (0.001 sec)