ID EN
Miscellaneous Functions

IS_IPV4_COMPAT(expr)

MySQL 8.4

This function takes an IPv6 address represented in numeric form as a binary string, as returned by INET6_ATON(). It returns 1 if the argument is a valid IPv4-compatible IPv6 address, 0 otherwise (unless expr is NULL, in which case the function returns NULL). IPv4-compatible addresses have the form ::ipv4_address.

Syntax

MYSQL
SELECT IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9'));
1
SELECT IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9'));
0

Examples

Example

The IPv4 part of an IPv4-compatible address can also be represented using hexadecimal notation. For example, 198.51.100.1 has this raw hexadecimal value:

MYSQL
SELECT IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9'));
1
SELECT IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9'));
0
Example 2

Expressed in IPv4-compatible form, ::198.51.100.1 is equivalent to ::c0a8:0001 or (without leading zeros) ::c0a8:1

MYSQL
SELECT HEX(INET6_ATON('198.51.100.1'));
'C6336401'
Example 3
MYSQL
SELECT
  IS_IPV4_COMPAT(INET6_ATON('::198.51.100.1')),
  IS_IPV4_COMPAT(INET6_ATON('::c0a8:0001')),
  IS_IPV4_COMPAT(INET6_ATON('::c0a8:1'));
1, 1, 1