Open In App

IS_IPV4_MAPPED() function in MySQL

Last Updated : 15 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

IS_IPV4_MAPPED() :

This function in MySQL takes an IPv6 address represented in numeric form as a binary string, as returned by INET6_ATON function. If the argument is a valid IPv4-mapped IPv6 address it returns 1, It returns 0 otherwise. The general form of IPv4-mapped addresses is ::ffff:ipv4_address.

Syntax :

IS_IPV4_MAPPED(expr)

Parameter : 

This function accepts one argument.

  • expr – Input IPv6 address represented by a string.

Returns : 

  • It returns 1 if the string is a valid IPv4-mapped IPv6 address. 
  • If the string is not a valid IPv4-mapped IPv6 address then it will return 0.  

Example-1 :

Checking whether the given address “::12.10.15.8” is valid or not using IS_IPV4_MAPPED Function. As given input is not a valid IPv4-mapped address here, it will return 0.

SELECT IS_IPV4_MAPPED(INET6_ATON('::12.10.15.8')) AS IS_IPV4_MAPPED ;

Output :

IS_IPV4_MAPPED 
0

Example-2 :

Checking whether the given address “::ffff:8.7.12.3” is valid or not using IS_IPV4_MAPPED Function. As the given input is a valid IPv4-mapped address here, it will return 1.

 SELECT IS_IPV4_MAPPED(INET6_ATON('::ffff:8.7.12.3')) AS IS_IPV4_MAPPED;

Output :

IS_IPV4_MAPPED
1

Example -3 :

Checking whether the given address “ff::9.6.10.11” is valid or not using IS_IPV4_MAPPED Function. As the given input is not a valid IPv4-mapped address here, it will return 0.

SELECT IS_IPV4_MAPPED(INET6_ATON('ff::9.6.10.11')) AS IS_IPV4_MAPPED ;

Output :

IS_IPV4_MAPPED
0

Example-4 :

Checking whether the given IPv6 address “::1″ is valid or not using IS_IPV4_MAPPED Function

SELECT IS_IPV4_MAPPED(INET6_ATON('::1')) AS IS_IPV4_MAPPED;

Output :

IS_IPV4_MAPPED
0

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads