Open In App

INET6_ATON() function in MySQL

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

This function in MySQL takes a dotted representation of an IPv4 or IPv6 address and returns a binary string that represents the numeric value of the address in network byte order. If the input address is not a valid IPv4 or IPv6 address this function returns NULL.

Syntax :

INET6_ATON(expr)

Parameter :
This method accepts only one parameter.

  • expr –
    Input IPv4 or IPv6 address represented by a string.

Returns :
It returns the numeric value of the address in VARBINARY data type: VARBINARY(16) for IPv6 addresses and VARBINARY(4) for IPv4 addresses.

Example-1 :
Checking the equivalent VARBINARY representation for the following address ‘10.16.25.0’ with the help of INET6_ATON Function. As it is a valid IPv4 address we will get result in VARBINARY form.

SELECT INET6_ATON('10.16.25.0')  
AS EquivalentAddressValue ;

Output :

EQUIVALENTADDRESSVALUE
0x0A101900

Example-2 :
Checking the equivalent VARBINARY representation  for the following address ‘2001:0db8:85a3:0000:0000:8a2e:0370:7334’  with the help of INET6_ATON Function. As it is a valid IPv6 address we will get result in VARBINARY form.

SELECT INET6_ATON('2001:0db8:85a3:0000:0000:8a2e:0370:7334')  
AS EquivalentAddressValue ;

Output :

EQUIVALENTADDRESSVALUE
0x20010DB885A3000000008A2E03707334

Example-3 :
Checking the equivalent VARBINARY representation for the following address ‘::0.5’ with the help of INET6_ATON Function. As it is not a valid IPv4 or IPv6 address we will get NULL.

SELECT INET6_ATON('::0.5')  
AS EquivalentAddressValue ;

Output :

EQUIVALENTADDRESSVALUE
0x

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads