Which IP Address Formats Are Allowed With MySQL INET6_ATON()?

The MySQL INET6_ATON() function accepts both, IPv4 and IPv6 addresses, as an argument:

-- IPv4
-- IPv6

If an invalid argument is supplied to INET6_ATON(), then it returns NULL:

-- invalid IP
SELECT INET6_ATON('foo') # null

Below is a list of IP addresses that are not allowed with the INET6_ATON() function:

Trying to convert any of these invalid values to their binary representation using the INET6_ATON() function will result in a NULL value:

-- IP with trailing zone ID
SELECT INET6_ATON('fe80::3%eth0') # null
-- IPv6 with trailing network mask
SELECT INET6_ATON('2001:45f:3:ba::/64') # null
-- IPv4 with trailing network mask
SELECT INET6_ATON('') # null
-- IPv4 classful address
SELECT INET6_ATON('198.51.1') # null
-- IPv4 with trailing port
SELECT INET6_ATON('') # null
-- IPv4 hexadecimal in address component
SELECT INET6_ATON('198.0xa0.1.2') # null

Other than that, octal numbers are not supported. For example, is interpreted as, and not

-- IPv4 octal misinterpretation

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.