INET6_ATON returns NULL for input parameter
C:\&gt;mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.6.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql&gt; use test
Database changed
mysql&gt; DROP FUNCTION IF EXISTS `addrToBinary`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql&gt; DELIMITER ;;
mysql&gt; CREATE FUNCTION `addrToBinary` (`in_remote_ip` varchar(45)) RETURNS varchar(45)
    -&gt; DETERMINISTIC
    -&gt; BEGIN
    -&gt;     RETURN HEX(INET6_ATON(in_remote_ip));
    -&gt; END;;
Query OK, 0 rows affected (0.01 sec)

mysql&gt; DELIMITER ;
mysql&gt; select `addrToBinary`("::ffff:127.0.0.1");
+------------------------------------+
| `addrToBinary`("::ffff:127.0.0.1") |
+------------------------------------+
| 00000000000000000000FFFF7F000001   |
+------------------------------------+
1 row in set (0.00 sec)

mysql&gt; SELECT
    -&gt;     addrToBinary("::ffff:127.0.0.1"),
    -&gt;     HEX(INET6_ATON("::ffff:127.0.0.1"));
+----------------------------------+-------------------------------------+
| addrToBinary("::ffff:127.0.0.1") | HEX(INET6_ATON("::ffff:127.0.0.1")) |
+----------------------------------+-------------------------------------+
| 00000000000000000000FFFF7F000001 | 00000000000000000000FFFF7F000001    |
+----------------------------------+-------------------------------------+
1 row in set (0.00 sec)

mysql&gt;


Works Fine For Me By Hand in MySQL 5.6.22 for Windows

mysql&gt; select `addrToBinary`(@given_ip);
+----------------------------------+
| `addrToBinary`(@given_ip)        |
+----------------------------------+
| 00000000000000000000FFFF7F000001 |
+----------------------------------+
1 row in set (0.00 sec)

mysql&gt;


It works when passing in a parameter from the MySQL Console

If you are doing this from PHP, please make sure the IP is properly enclosed in quotes