List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:May 3 2011 1:04pm
Subject:bzr push into mysql-trunk branch (alexander.nozdrin:3358 to 3360) WL#5787
View as plain text  
 3360 Alexander Nozdrin	2011-05-03
      MTR tests for QA sign off of wl#5787.

    modified:
      mysql-test/include/ipv6.inc
      mysql-test/r/ipv4_as_ipv6.result
      mysql-test/r/ipv6.result
      mysql-test/t/ipv4_as_ipv6.test
      mysql-test/t/ipv6.test
 3359 Alexander Nozdrin	2011-05-03
      Patch for WL#5787 (IPv6-capable INET_ATON and INET_NTOA functions).
      
      The patch introduces the following new functions:
        - INET6_ATON()
        - INET6_NTOA()
        - IS_IPV4()
        - IS_IPV6()
        - IS_IPV4_COMPAT()
        - IS_IPV4_MAPPED()

    modified:
      mysql-test/r/func_misc.result
      mysql-test/t/func_misc.test
      sql/item_create.cc
      sql/item_inetfunc.cc
      sql/item_inetfunc.h
 3358 Tor Didriksen	2011-05-03
      BUG#11766327 post-push fix: build break with optimized/-DMYSQL_MAINTAINER_MODE=1

    modified:
      sql/sql_select.cc
=== modified file 'mysql-test/include/ipv6.inc'
--- a/mysql-test/include/ipv6.inc	2010-02-08 10:43:56 +0000
+++ b/mysql-test/include/ipv6.inc	2011-05-03 13:04:00 +0000
@@ -1,11 +1,6 @@
 eval CREATE USER testuser@'$IPv6' identified by '1234';
 eval GRANT ALL ON test.* TO testuser@'$IPv6';
 eval SHOW GRANTS FOR testuser@'$IPv6';
-# deliver NULL instead of a valid number, see bug#34037
-eval SET @nip= inet_aton('$IPv6');
-SELECT @nip;
-SELECT inet_ntoa(@nip);
-# delivers a wrong value, see bug#34037
 --replace_result ::1 localhost
 SELECT USER();
 --replace_result ::1 localhost

=== modified file 'mysql-test/r/func_misc.result'
--- a/mysql-test/r/func_misc.result	2010-12-17 14:02:56 +0000
+++ b/mysql-test/r/func_misc.result	2011-05-03 13:03:00 +0000
@@ -400,6 +400,594 @@ DROP TABLE t1;
 #
 # End of 5.5 tests
 #
+
+# --
+# -- WL#5787: IPv6-capable INET_ATON and INET_NTOA functions.
+# --
+
+# -- INET6_ATON: checking NULL, invalid types, out-of range values...
+
+SELECT INET6_ATON(NULL) IS NULL;
+INET6_ATON(NULL) IS NULL
+1
+SELECT INET6_ATON(123) IS NULL;
+INET6_ATON(123) IS NULL
+1
+SELECT INET6_ATON(123.45) IS NULL;
+INET6_ATON(123.45) IS NULL
+1
+SELECT INET6_ATON(NOW()) IS NULL;
+INET6_ATON(NOW()) IS NULL
+1
+SELECT INET6_ATON('1.2.3') IS NULL;
+INET6_ATON('1.2.3') IS NULL
+1
+SELECT INET6_ATON('1.2.3.') IS NULL;
+INET6_ATON('1.2.3.') IS NULL
+1
+SELECT INET6_ATON('1..3.4') IS NULL;
+INET6_ATON('1..3.4') IS NULL
+1
+SELECT INET6_ATON('-1.2.3.4') IS NULL;
+INET6_ATON('-1.2.3.4') IS NULL
+1
+SELECT INET6_ATON('1.2.3.256') IS NULL;
+INET6_ATON('1.2.3.256') IS NULL
+1
+SELECT INET6_ATON('1.2.3.4.5') IS NULL;
+INET6_ATON('1.2.3.4.5') IS NULL
+1
+SELECT INET6_ATON('0001.2.3.4') IS NULL;
+INET6_ATON('0001.2.3.4') IS NULL
+1
+SELECT INET6_ATON('0x1.2.3.4') IS NULL;
+INET6_ATON('0x1.2.3.4') IS NULL
+1
+SELECT INET6_ATON('a.2.3.4') IS NULL;
+INET6_ATON('a.2.3.4') IS NULL
+1
+SELECT INET6_ATON('1.2.3.4:80') IS NULL;
+INET6_ATON('1.2.3.4:80') IS NULL
+1
+SELECT INET6_ATON('1.2.3.4/32') IS NULL;
+INET6_ATON('1.2.3.4/32') IS NULL
+1
+SELECT INET6_ATON('mysql.com') IS NULL;
+INET6_ATON('mysql.com') IS NULL
+1
+SELECT INET6_ATON(':::') IS NULL;
+INET6_ATON(':::') IS NULL
+1
+SELECT INET6_ATON(':1:2:3') IS NULL;
+INET6_ATON(':1:2:3') IS NULL
+1
+SELECT INET6_ATON('1:2:3:') IS NULL;
+INET6_ATON('1:2:3:') IS NULL
+1
+SELECT INET6_ATON(':1::2:3') IS NULL;
+INET6_ATON(':1::2:3') IS NULL
+1
+SELECT INET6_ATON('1::2:3:') IS NULL;
+INET6_ATON('1::2:3:') IS NULL
+1
+SELECT INET6_ATON('::00001') IS NULL;
+INET6_ATON('::00001') IS NULL
+1
+SELECT INET6_ATON('::00001:2') IS NULL;
+INET6_ATON('::00001:2') IS NULL
+1
+SELECT INET6_ATON('::12345') IS NULL;
+INET6_ATON('::12345') IS NULL
+1
+SELECT INET6_ATON('1020::3040::5060') IS NULL;
+INET6_ATON('1020::3040::5060') IS NULL
+1
+SELECT INET6_ATON('::ABCZ') IS NULL;
+INET6_ATON('::ABCZ') IS NULL
+1
+SELECT INET6_ATON('::0x1.2.3.4') IS NULL;
+INET6_ATON('::0x1.2.3.4') IS NULL
+1
+SELECT INET6_ATON('::1.0x2.3.4') IS NULL;
+INET6_ATON('::1.0x2.3.4') IS NULL
+1
+SELECT INET6_ATON('::a.b.c.d') IS NULL;
+INET6_ATON('::a.b.c.d') IS NULL
+1
+SELECT INET6_ATON('::FFFF:0x1.2.3.4') IS NULL;
+INET6_ATON('::FFFF:0x1.2.3.4') IS NULL
+1
+SELECT INET6_ATON('::FFFF:1.0x2.3.4') IS NULL;
+INET6_ATON('::FFFF:1.0x2.3.4') IS NULL
+1
+SELECT INET6_ATON('::FFFF:a.b.c.d') IS NULL;
+INET6_ATON('::FFFF:a.b.c.d') IS NULL
+1
+SELECT INET6_ATON('::1.2.3.4:ABCD') IS NULL;
+INET6_ATON('::1.2.3.4:ABCD') IS NULL
+1
+# NOTE: such addresses are supported because getaddrinfo() supports them.
+# This is just to record the current behaviour.
+SELECT HEX(INET6_ATON('::ABCD:1.2.3.4'));
+HEX(INET6_ATON('::ABCD:1.2.3.4'))
+00000000000000000000ABCD01020304
+
+# -- INET6_ATON: checking binary representation...
+
+SELECT HEX(INET6_ATON('0.0.0.0'));
+HEX(INET6_ATON('0.0.0.0'))
+00000000
+SELECT HEX(INET6_ATON('00.00.00.00'));
+HEX(INET6_ATON('00.00.00.00'))
+00000000
+SELECT HEX(INET6_ATON('000.000.000.000'));
+HEX(INET6_ATON('000.000.000.000'))
+00000000
+SELECT HEX(INET6_ATON('1.2.3.4'));
+HEX(INET6_ATON('1.2.3.4'))
+01020304
+SELECT HEX(INET6_ATON('01.02.03.04'));
+HEX(INET6_ATON('01.02.03.04'))
+01020304
+SELECT HEX(INET6_ATON('001.002.003.004'));
+HEX(INET6_ATON('001.002.003.004'))
+01020304
+SELECT HEX(INET6_ATON('255.255.255.255'));
+HEX(INET6_ATON('255.255.255.255'))
+FFFFFFFF
+SELECT HEX(INET6_ATON('::'));
+HEX(INET6_ATON('::'))
+00000000000000000000000000000000
+SELECT HEX(INET6_ATON('0::0'));
+HEX(INET6_ATON('0::0'))
+00000000000000000000000000000000
+SELECT HEX(INET6_ATON('1::2'));
+HEX(INET6_ATON('1::2'))
+00010000000000000000000000000002
+SELECT HEX(INET6_ATON('0::'));
+HEX(INET6_ATON('0::'))
+00000000000000000000000000000000
+SELECT HEX(INET6_ATON('1::'));
+HEX(INET6_ATON('1::'))
+00010000000000000000000000000000
+SELECT HEX(INET6_ATON('::0'));
+HEX(INET6_ATON('::0'))
+00000000000000000000000000000000
+SELECT HEX(INET6_ATON('::1'));
+HEX(INET6_ATON('::1'))
+00000000000000000000000000000001
+SELECT HEX(INET6_ATON('1:2:3:4:5:6:7:8'));
+HEX(INET6_ATON('1:2:3:4:5:6:7:8'))
+00010002000300040005000600070008
+SELECT HEX(INET6_ATON('::2:3:4:5:6:7:8'));
+HEX(INET6_ATON('::2:3:4:5:6:7:8'))
+00000002000300040005000600070008
+SELECT HEX(INET6_ATON('1::3:4:5:6:7:8'));
+HEX(INET6_ATON('1::3:4:5:6:7:8'))
+00010000000300040005000600070008
+SELECT HEX(INET6_ATON('1:2::4:5:6:7:8'));
+HEX(INET6_ATON('1:2::4:5:6:7:8'))
+00010002000000040005000600070008
+SELECT HEX(INET6_ATON('1:2:3::5:6:7:8'));
+HEX(INET6_ATON('1:2:3::5:6:7:8'))
+00010002000300000005000600070008
+SELECT HEX(INET6_ATON('1:2:3:4::6:7:8'));
+HEX(INET6_ATON('1:2:3:4::6:7:8'))
+00010002000300040000000600070008
+SELECT HEX(INET6_ATON('1:2:3:4:5::7:8'));
+HEX(INET6_ATON('1:2:3:4:5::7:8'))
+00010002000300040005000000070008
+SELECT HEX(INET6_ATON('1:2:3:4:5:6::8'));
+HEX(INET6_ATON('1:2:3:4:5:6::8'))
+00010002000300040005000600000008
+SELECT HEX(INET6_ATON('1:2:3:4:5:6:7::'));
+HEX(INET6_ATON('1:2:3:4:5:6:7::'))
+00010002000300040005000600070000
+SELECT HEX(INET6_ATON('0000:0000::0000:0001'));
+HEX(INET6_ATON('0000:0000::0000:0001'))
+00000000000000000000000000000001
+SELECT HEX(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed'));
+HEX(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed'))
+123456789ABCDEF043218765CBA90FED
+SELECT HEX(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001'));
+HEX(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001'))
+00000000000000000000000000000001
+SELECT HEX(INET6_ATON('::C0A8:0102'));
+HEX(INET6_ATON('::C0A8:0102'))
+000000000000000000000000C0A80102
+SELECT HEX(INET6_ATON('::c0a8:0102'));
+HEX(INET6_ATON('::c0a8:0102'))
+000000000000000000000000C0A80102
+SELECT HEX(INET6_ATON('::192.168.1.2'));
+HEX(INET6_ATON('::192.168.1.2'))
+000000000000000000000000C0A80102
+SELECT HEX(INET6_ATON('::FfFf:C0a8:0102'));
+HEX(INET6_ATON('::FfFf:C0a8:0102'))
+00000000000000000000FFFFC0A80102
+SELECT HEX(INET6_ATON('::ffff:c0a8:0102'));
+HEX(INET6_ATON('::ffff:c0a8:0102'))
+00000000000000000000FFFFC0A80102
+SELECT HEX(INET6_ATON('::ffff:192.168.1.2'));
+HEX(INET6_ATON('::ffff:192.168.1.2'))
+00000000000000000000FFFFC0A80102
+SELECT HEX(INET6_ATON('::01.2.3.4'));
+HEX(INET6_ATON('::01.2.3.4'))
+00000000000000000000000001020304
+SELECT HEX(INET6_ATON('::1.02.3.4'));
+HEX(INET6_ATON('::1.02.3.4'))
+00000000000000000000000001020304
+SELECT HEX(INET6_ATON('::1.2.03.4'));
+HEX(INET6_ATON('::1.2.03.4'))
+00000000000000000000000001020304
+SELECT HEX(INET6_ATON('::1.2.3.04'));
+HEX(INET6_ATON('::1.2.3.04'))
+00000000000000000000000001020304
+SELECT HEX(INET6_ATON('::1.2.3.00'));
+HEX(INET6_ATON('::1.2.3.00'))
+00000000000000000000000001020300
+SELECT HEX(INET6_ATON('::FFFF:01.2.3.4'));
+HEX(INET6_ATON('::FFFF:01.2.3.4'))
+00000000000000000000FFFF01020304
+SELECT HEX(INET6_ATON('::FFFF:1.02.3.4'));
+HEX(INET6_ATON('::FFFF:1.02.3.4'))
+00000000000000000000FFFF01020304
+SELECT HEX(INET6_ATON('::FFFF:1.2.03.4'));
+HEX(INET6_ATON('::FFFF:1.2.03.4'))
+00000000000000000000FFFF01020304
+SELECT HEX(INET6_ATON('::FFFF:1.2.3.04'));
+HEX(INET6_ATON('::FFFF:1.2.3.04'))
+00000000000000000000FFFF01020304
+SELECT HEX(INET6_ATON('::FFFF:1.2.3.00'));
+HEX(INET6_ATON('::FFFF:1.2.3.00'))
+00000000000000000000FFFF01020300
+
+# -- INET6_ATON: checking the length is either 4 or 16...
+
+SELECT LENGTH(INET6_ATON('0.0.0.0'));
+LENGTH(INET6_ATON('0.0.0.0'))
+4
+SELECT LENGTH(INET6_ATON('255.255.255.255'));
+LENGTH(INET6_ATON('255.255.255.255'))
+4
+SELECT LENGTH(INET6_ATON('::'));
+LENGTH(INET6_ATON('::'))
+16
+SELECT LENGTH(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010'));
+LENGTH(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010'))
+16
+
+# -- INET6_NTOA: checking NULL, invalid types, out-of range values...
+
+SELECT INET6_NTOA(NULL);
+INET6_NTOA(NULL)
+NULL
+SELECT INET6_NTOA(123);
+INET6_NTOA(123)
+NULL
+SELECT INET6_NTOA(123.456);
+INET6_NTOA(123.456)
+NULL
+SELECT INET6_NTOA(NOW());
+INET6_NTOA(NOW())
+NULL
+SELECT INET6_NTOA(UNHEX('C0A801'));
+INET6_NTOA(UNHEX('C0A801'))
+NULL
+SELECT INET6_NTOA(UNHEX('C0A80102'));
+INET6_NTOA(UNHEX('C0A80102'))
+192.168.1.2
+SELECT INET6_NTOA(UNHEX('C0A8010203'));
+INET6_NTOA(UNHEX('C0A8010203'))
+NULL
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F'));
+INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F'))
+NULL
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F10'));
+INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F10'))
+102:304:506:708:90a:b0c:d0e:f10
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F1011'));
+INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F1011'))
+NULL
+SELECT INET6_NTOA('1234'), INET6_NTOA(BINARY('1234'));
+INET6_NTOA('1234')	INET6_NTOA(BINARY('1234'))
+NULL	49.50.51.52
+SELECT INET6_NTOA('0123456789abcdef'), INET6_NTOA(BINARY('0123456789abcdef'));
+INET6_NTOA('0123456789abcdef')	INET6_NTOA(BINARY('0123456789abcdef'))
+NULL	3031:3233:3435:3637:3839:6162:6364:6566
+
+# -- Checking double-conversion...
+
+SELECT INET6_NTOA(INET6_ATON('::'));
+INET6_NTOA(INET6_ATON('::'))
+::
+SELECT INET6_NTOA(INET6_ATON('0::0'));
+INET6_NTOA(INET6_ATON('0::0'))
+::
+SELECT INET6_NTOA(INET6_ATON('1::2'));
+INET6_NTOA(INET6_ATON('1::2'))
+1::2
+SELECT INET6_NTOA(INET6_ATON('0::'));
+INET6_NTOA(INET6_ATON('0::'))
+::
+SELECT INET6_NTOA(INET6_ATON('1::'));
+INET6_NTOA(INET6_ATON('1::'))
+1::
+SELECT INET6_NTOA(INET6_ATON('::0'));
+INET6_NTOA(INET6_ATON('::0'))
+::
+SELECT INET6_NTOA(INET6_ATON('::1'));
+INET6_NTOA(INET6_ATON('::1'))
+::1
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7:8'));
+INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7:8'))
+1:2:3:4:5:6:7:8
+SELECT INET6_NTOA(INET6_ATON('::2:3:4:5:6:7:8'));
+INET6_NTOA(INET6_ATON('::2:3:4:5:6:7:8'))
+::2:3:4:5:6:7:8
+SELECT INET6_NTOA(INET6_ATON('1::3:4:5:6:7:8'));
+INET6_NTOA(INET6_ATON('1::3:4:5:6:7:8'))
+1::3:4:5:6:7:8
+SELECT INET6_NTOA(INET6_ATON('1:2::4:5:6:7:8'));
+INET6_NTOA(INET6_ATON('1:2::4:5:6:7:8'))
+1:2::4:5:6:7:8
+SELECT INET6_NTOA(INET6_ATON('1:2:3::5:6:7:8'));
+INET6_NTOA(INET6_ATON('1:2:3::5:6:7:8'))
+1:2:3::5:6:7:8
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4::6:7:8'));
+INET6_NTOA(INET6_ATON('1:2:3:4::6:7:8'))
+1:2:3:4::6:7:8
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5::7:8'));
+INET6_NTOA(INET6_ATON('1:2:3:4:5::7:8'))
+1:2:3:4:5::7:8
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6::8'));
+INET6_NTOA(INET6_ATON('1:2:3:4:5:6::8'))
+1:2:3:4:5:6::8
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7::'));
+INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7::'))
+1:2:3:4:5:6:7::
+SELECT INET6_NTOA(INET6_ATON('0000:0000::0000:0001'));
+INET6_NTOA(INET6_ATON('0000:0000::0000:0001'))
+::1
+SELECT INET6_NTOA(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed'));
+INET6_NTOA(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed'))
+1234:5678:9abc:def0:4321:8765:cba9:fed
+SELECT INET6_NTOA(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001'));
+INET6_NTOA(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001'))
+::1
+SELECT INET6_NTOA(INET6_ATON('::C0A8:0102'));
+INET6_NTOA(INET6_ATON('::C0A8:0102'))
+::192.168.1.2
+SELECT INET6_NTOA(INET6_ATON('::c0a8:0102'));
+INET6_NTOA(INET6_ATON('::c0a8:0102'))
+::192.168.1.2
+SELECT INET6_NTOA(INET6_ATON('::192.168.1.2'));
+INET6_NTOA(INET6_ATON('::192.168.1.2'))
+::192.168.1.2
+SELECT INET6_NTOA(INET6_ATON('::FfFf:C0a8:0102'));
+INET6_NTOA(INET6_ATON('::FfFf:C0a8:0102'))
+::ffff:192.168.1.2
+SELECT INET6_NTOA(INET6_ATON('::ffff:c0a8:0102'));
+INET6_NTOA(INET6_ATON('::ffff:c0a8:0102'))
+::ffff:192.168.1.2
+SELECT INET6_NTOA(INET6_ATON('::ffff:192.168.1.2'));
+INET6_NTOA(INET6_ATON('::ffff:192.168.1.2'))
+::ffff:192.168.1.2
+SELECT INET6_NTOA(INET6_ATON('::01.2.3.4'));
+INET6_NTOA(INET6_ATON('::01.2.3.4'))
+::1.2.3.4
+SELECT INET6_NTOA(INET6_ATON('::1.02.3.4'));
+INET6_NTOA(INET6_ATON('::1.02.3.4'))
+::1.2.3.4
+SELECT INET6_NTOA(INET6_ATON('::1.2.03.4'));
+INET6_NTOA(INET6_ATON('::1.2.03.4'))
+::1.2.3.4
+SELECT INET6_NTOA(INET6_ATON('::1.2.3.04'));
+INET6_NTOA(INET6_ATON('::1.2.3.04'))
+::1.2.3.4
+SELECT INET6_NTOA(INET6_ATON('::1.2.3.00'));
+INET6_NTOA(INET6_ATON('::1.2.3.00'))
+::1.2.3.0
+SELECT INET6_NTOA(INET6_ATON('::FFFF:01.2.3.4'));
+INET6_NTOA(INET6_ATON('::FFFF:01.2.3.4'))
+::ffff:1.2.3.4
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.02.3.4'));
+INET6_NTOA(INET6_ATON('::FFFF:1.02.3.4'))
+::ffff:1.2.3.4
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.03.4'));
+INET6_NTOA(INET6_ATON('::FFFF:1.2.03.4'))
+::ffff:1.2.3.4
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.04'));
+INET6_NTOA(INET6_ATON('::FFFF:1.2.3.04'))
+::ffff:1.2.3.4
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.00'));
+INET6_NTOA(INET6_ATON('::FFFF:1.2.3.00'))
+::ffff:1.2.3.0
+
+# -- Comparing INET_ATON() and INET6_ATON()...
+
+SELECT HEX(INET_ATON('192.168.1.2'));
+HEX(INET_ATON('192.168.1.2'))
+C0A80102
+SELECT HEX(INET6_ATON('192.168.1.2'));
+HEX(INET6_ATON('192.168.1.2'))
+C0A80102
+SELECT HEX(INET_ATON('255.255.255.255'));
+HEX(INET_ATON('255.255.255.255'))
+FFFFFFFF
+SELECT HEX(INET6_ATON('255.255.255.255'));
+HEX(INET6_ATON('255.255.255.255'))
+FFFFFFFF
+SELECT HEX(INET_ATON('192.168.08.2'));
+HEX(INET_ATON('192.168.08.2'))
+C0A80802
+SELECT HEX(INET6_ATON('192.168.08.2'));
+HEX(INET6_ATON('192.168.08.2'))
+C0A80802
+SELECT HEX(INET_ATON('192.168.0x8.2'));
+HEX(INET_ATON('192.168.0x8.2'))
+NULL
+SELECT HEX(INET6_ATON('192.168.0x8.2'));
+HEX(INET6_ATON('192.168.0x8.2'))
+NULL
+SELECT HEX(INET_ATON('1.2.255'));
+HEX(INET_ATON('1.2.255'))
+10200FF
+SELECT HEX(INET6_ATON('1.2.255'));
+HEX(INET6_ATON('1.2.255'))
+NULL
+SELECT HEX(INET_ATON('1.2.256'));
+HEX(INET_ATON('1.2.256'))
+NULL
+SELECT HEX(INET6_ATON('1.2.256'));
+HEX(INET6_ATON('1.2.256'))
+NULL
+SELECT HEX(INET_ATON('1.0002.3.4'));
+HEX(INET_ATON('1.0002.3.4'))
+1020304
+SELECT HEX(INET6_ATON('1.0002.3.4'));
+HEX(INET6_ATON('1.0002.3.4'))
+NULL
+SELECT HEX(INET_ATON('1.2.3.4.5'));
+HEX(INET_ATON('1.2.3.4.5'))
+102030405
+SELECT HEX(INET6_ATON('1.2.3.4.5'));
+HEX(INET6_ATON('1.2.3.4.5'))
+NULL
+
+# -- Checking mix of INET- and INET6- functions...
+
+SELECT HEX(INET6_ATON(INET_NTOA(INET_ATON('1.2.3.4')))) AS x;
+x
+01020304
+
+# -- Checking IS_IPV4() / IS_IPV6()...
+
+SELECT IS_IPV4(NULL);
+IS_IPV4(NULL)
+0
+SELECT IS_IPV4(1);
+IS_IPV4(1)
+0
+SELECT IS_IPV4(1.0);
+IS_IPV4(1.0)
+0
+SELECT IS_IPV4('1.2.3.4');
+IS_IPV4('1.2.3.4')
+1
+SELECT IS_IPV4('001.02.000.255');
+IS_IPV4('001.02.000.255')
+1
+SELECT IS_IPV4('::1.2.0.255');
+IS_IPV4('::1.2.0.255')
+0
+SELECT IS_IPV4('::1');
+IS_IPV4('::1')
+0
+SELECT IS_IPV4(BINARY('1.2.3.4'));
+IS_IPV4(BINARY('1.2.3.4'))
+1
+SELECT IS_IPV6(NULL);
+IS_IPV6(NULL)
+0
+SELECT IS_IPV6(1);
+IS_IPV6(1)
+0
+SELECT IS_IPV6(1.0);
+IS_IPV6(1.0)
+0
+SELECT IS_IPV6('1.2.3.4');
+IS_IPV6('1.2.3.4')
+0
+SELECT IS_IPV6('001.02.000.255');
+IS_IPV6('001.02.000.255')
+0
+SELECT IS_IPV6('::001.02.000.255');
+IS_IPV6('::001.02.000.255')
+1
+SELECT IS_IPV6('::1.2.0.255');
+IS_IPV6('::1.2.0.255')
+1
+SELECT IS_IPV6('::1');
+IS_IPV6('::1')
+1
+SELECT IS_IPV6('0000:0000:0000:0000:0000:0000:0000:0001');
+IS_IPV6('0000:0000:0000:0000:0000:0000:0000:0001')
+1
+SELECT IS_IPV6(BINARY('0000:0000:0000:0000:0000:0000:0000:0001'));
+IS_IPV6(BINARY('0000:0000:0000:0000:0000:0000:0000:0001'))
+1
+
+# -- Checking IS_IPV4_MAPPED() and IS_IPV4_COMPAT()...
+
+SELECT IS_IPV4_MAPPED(INET6_ATON('1.2.3.4')),
+IS_IPV4_COMPAT(INET6_ATON('1.2.3.4'));
+IS_IPV4_MAPPED(INET6_ATON('1.2.3.4'))	IS_IPV4_COMPAT(INET6_ATON('1.2.3.4'))
+0	0
+SELECT IS_IPV4_MAPPED(INET6_ATON('::1.2.3.4')),
+IS_IPV4_COMPAT(INET6_ATON('::1.2.3.4'));
+IS_IPV4_MAPPED(INET6_ATON('::1.2.3.4'))	IS_IPV4_COMPAT(INET6_ATON('::1.2.3.4'))
+0	1
+SELECT IS_IPV4_MAPPED(INET6_ATON('::FFFF:1.2.3.4')),
+IS_IPV4_COMPAT(INET6_ATON('::FFFF:1.2.3.4'));
+IS_IPV4_MAPPED(INET6_ATON('::FFFF:1.2.3.4'))	IS_IPV4_COMPAT(INET6_ATON('::FFFF:1.2.3.4'))
+1	0
+SELECT IS_IPV4_MAPPED(INET6_ATON('::ABCD:1.2.3.4')),
+IS_IPV4_COMPAT(INET6_ATON('::ABCD:1.2.3.4'));
+IS_IPV4_MAPPED(INET6_ATON('::ABCD:1.2.3.4'))	IS_IPV4_COMPAT(INET6_ATON('::ABCD:1.2.3.4'))
+0	0
+SELECT IS_IPV4_MAPPED(INET6_ATON('::1')),
+IS_IPV4_COMPAT(INET6_ATON('::1'));
+IS_IPV4_MAPPED(INET6_ATON('::1'))	IS_IPV4_COMPAT(INET6_ATON('::1'))
+0	0
+SELECT IS_IPV4_MAPPED(INET6_ATON('::')),
+IS_IPV4_COMPAT(INET6_ATON('::'));
+IS_IPV4_MAPPED(INET6_ATON('::'))	IS_IPV4_COMPAT(INET6_ATON('::'))
+0	0
+
+# -- Checking IS_IPV4_COMPAT()...
+
+
+# -- Working with a table...
+
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+CREATE TABLE t1(ip INT UNSIGNED);
+CREATE TABLE t2(ip VARBINARY(16));
+
+INSERT INTO t1 VALUES
+(INET_ATON('1.2.3.4')), (INET_ATON('255.255.255.255'));
+SELECT INET_NTOA(ip) FROM t1;
+INET_NTOA(ip)
+1.2.3.4
+255.255.255.255
+
+INSERT INTO t2 SELECT INET6_ATON(INET_NTOA(ip)) FROM t1;
+SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2;
+INET6_NTOA(ip)	HEX(ip)	LENGTH(ip)
+1.2.3.4	01020304	4
+255.255.255.255	FFFFFFFF	4
+DELETE FROM t2;
+
+INSERT INTO t2 VALUES
+(INET6_ATON('1.2.3.4')), (INET6_ATON('255.255.255.255')),
+(INET6_ATON('::1.2.3.4')), (INET6_ATON('::ffff:255.255.255.255')),
+(INET6_ATON('::')), (INET6_ATON('::1')),
+(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010'));
+SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2;
+INET6_NTOA(ip)	HEX(ip)	LENGTH(ip)
+1.2.3.4	01020304	4
+255.255.255.255	FFFFFFFF	4
+::1.2.3.4	00000000000000000000000001020304	16
+::ffff:255.255.255.255	00000000000000000000FFFFFFFFFFFF	16
+::	00000000000000000000000000000000	16
+::1	00000000000000000000000000000001	16
+1020:3040:5060:7080:90a0:b0c0:d0e0:f010	102030405060708090A0B0C0D0E0F010	16
+
+DROP TABLE t1;
+DROP TABLE t2;
+
+# -- Done.
+
 #
 # End of tests
 #

=== modified file 'mysql-test/r/ipv4_as_ipv6.result'
--- a/mysql-test/r/ipv4_as_ipv6.result	2010-10-18 16:20:26 +0000
+++ b/mysql-test/r/ipv4_as_ipv6.result	2011-05-03 13:04:00 +0000
@@ -6,13 +6,6 @@ SHOW GRANTS FOR testuser@'127.0.0.1';
 Grants for testuser@stripped
 GRANT USAGE ON *.* TO 'testuser'@'127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'127.0.0.1'
-SET @nip= inet_aton('127.0.0.1');
-SELECT @nip;
-@nip
-2130706433
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-127.0.0.1
 SELECT USER();
 USER()
 root@localhost
@@ -27,6 +20,98 @@ SELECT USER();
 USER()
 root@localhost
 DROP USER testuser1@'127.0.0.1';
+SET @nip= inet_aton('127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+127.0.0.1
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+127.0.0.1
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+127.0.0.1
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+127.0.0.1
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+127.0.0.1
+Warnings:
+Warning	1292	Truncated incorrect INTEGER value: '2130706433\x00\x00\x00\x00\x00\x00'
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+127.0.0.1
+Warnings:
+Warning	1292	Truncated incorrect INTEGER value: '2130706433\x00\x00\x00\x00\x00\x00'
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+127.0.0.1
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+127.0.0.1
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+127.0.0.1
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+127.0.0.1
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+127.0.0.1
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+2130706433
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+127.0.0.1
+SET @nip6= inet6_aton('127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+Warnings:
+Warning	1366	Incorrect integer value: '\x7F\x00\x00\x01' for column 'c6' at row 1
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+127.0.0.1
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+7f00:1::
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+7f00:1::
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+7f00:1::
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+7f00:1::
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+7f00:1::
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+7f00:1::
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+3000::
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+127.0.0.1
 =============Test of '0:0:0:0:0:FFFF:127.0.0.1' ===================
 mysqld is alive
 CREATE USER testuser@'0:0:0:0:0:FFFF:127.0.0.1' identified by '1234';
@@ -35,13 +120,6 @@ SHOW GRANTS FOR testuser@'0:0:0:0:0:FFFF
 Grants for testuser@0:0:0:0:0:ffff:127.0.0.1
 GRANT USAGE ON *.* TO 'testuser'@'0:0:0:0:0:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0:0:0:0:0:ffff:127.0.0.1'
-SET @nip= inet_aton('0:0:0:0:0:FFFF:127.0.0.1');
-SELECT @nip;
-@nip
-NULL
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-NULL
 SELECT USER();
 USER()
 root@localhost
@@ -56,6 +134,94 @@ SELECT USER();
 USER()
 root@localhost
 DROP USER testuser1@'0:0:0:0:0:FFFF:127.0.0.1';
+SET @nip= inet_aton('0:0:0:0:0:FFFF:127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('0:0:0:0:0:FFFF:127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+Warnings:
+Warning	1366	Incorrect integer value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x7F\x00\x00\x01' for column 'c6' at row 1
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+::ffff:127.0.0.1
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+::ffff:127.0.0.1
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+3000::
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+::ffff:127.0.0.1
 =============Test of '0000:0000:0000:0000:0000:FFFF:127.0.0.1' ====
 mysqld is alive
 CREATE USER testuser@'0000:0000:0000:0000:0000:FFFF:127.0.0.1' identified by '1234';
@@ -64,13 +230,6 @@ SHOW GRANTS FOR testuser@'0000:0000:0000
 Grants for testuser@0000:0000:0000:0000:0000:ffff:127.0.0.1
 GRANT USAGE ON *.* TO 'testuser'@'0000:0000:0000:0000:0000:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0000:0000:0000:0000:0000:ffff:127.0.0.1'
-SET @nip= inet_aton('0000:0000:0000:0000:0000:FFFF:127.0.0.1');
-SELECT @nip;
-@nip
-NULL
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-NULL
 SELECT USER();
 USER()
 root@localhost
@@ -85,6 +244,94 @@ SELECT USER();
 USER()
 root@localhost
 DROP USER testuser1@'0000:0000:0000:0000:0000:FFFF:127.0.0.1';
+SET @nip= inet_aton('0000:0000:0000:0000:0000:FFFF:127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('0000:0000:0000:0000:0000:FFFF:127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+Warnings:
+Warning	1366	Incorrect integer value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x7F\x00\x00\x01' for column 'c6' at row 1
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+::ffff:127.0.0.1
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+::ffff:127.0.0.1
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+3000::
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+::ffff:127.0.0.1
 =============Test of '0:0000:0000:0:0000:FFFF:127.0.0.1' ====
 mysqld is alive
 CREATE USER testuser@'0:0000:0000:0:0000:FFFF:127.0.0.1' identified by '1234';
@@ -93,13 +340,6 @@ SHOW GRANTS FOR testuser@'0:0000:0000:0:
 Grants for testuser@0:0000:0000:0:0000:ffff:127.0.0.1
 GRANT USAGE ON *.* TO 'testuser'@'0:0000:0000:0:0000:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0:0000:0000:0:0000:ffff:127.0.0.1'
-SET @nip= inet_aton('0:0000:0000:0:0000:FFFF:127.0.0.1');
-SELECT @nip;
-@nip
-NULL
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-NULL
 SELECT USER();
 USER()
 root@localhost
@@ -114,6 +354,94 @@ SELECT USER();
 USER()
 root@localhost
 DROP USER testuser1@'0:0000:0000:0:0000:FFFF:127.0.0.1';
+SET @nip= inet_aton('0:0000:0000:0:0000:FFFF:127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('0:0000:0000:0:0000:FFFF:127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+Warnings:
+Warning	1366	Incorrect integer value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x7F\x00\x00\x01' for column 'c6' at row 1
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+::ffff:127.0.0.1
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+::ffff:127.0.0.1
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+3000::
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+::ffff:127.0.0.1
 =============Test of '0::0000:FFFF:127.0.0.1' ====
 mysqld is alive
 CREATE USER testuser@'0::0000:FFFF:127.0.0.1' identified by '1234';
@@ -122,13 +450,6 @@ SHOW GRANTS FOR testuser@'0::0000:FFFF:1
 Grants for testuser@0::0000:ffff:127.0.0.1
 GRANT USAGE ON *.* TO 'testuser'@'0::0000:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0::0000:ffff:127.0.0.1'
-SET @nip= inet_aton('0::0000:FFFF:127.0.0.1');
-SELECT @nip;
-@nip
-NULL
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-NULL
 SELECT USER();
 USER()
 root@localhost
@@ -143,7 +464,181 @@ SELECT USER();
 USER()
 root@localhost
 DROP USER testuser1@'0::0000:FFFF:127.0.0.1';
+SET @nip= inet_aton('0::0000:FFFF:127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('0::0000:FFFF:127.0.0.1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+Warnings:
+Warning	1366	Incorrect integer value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x7F\x00\x00\x01' for column 'c6' at row 1
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+::ffff:127.0.0.1
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+::ffff:127.0.0.1
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+::ffff:127.0.0.1
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+3000::
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+::ffff:127.0.0.1
 =============Test of '0:0:0:0:0:FFFF:127.0.0.1/96' ================
+SET @nip= inet_aton('0:0:0:0:0:FFFF:127.0.0.1/96');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('0:0:0:0:0:FFFF:127.0.0.1/96');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+NULL
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+NULL
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+NULL
 =============Test of '::FFFF:127.0.0.1' ===========================
 mysqld is alive
 CREATE USER testuser@'::FFFF:127.0.0.1' identified by '1234';
@@ -152,13 +647,6 @@ SHOW GRANTS FOR testuser@'::FFFF:127.0.0
 Grants for testuser@::ffff:127.0.0.1
 GRANT USAGE ON *.* TO 'testuser'@'::ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'::ffff:127.0.0.1'
-SET @nip= inet_aton('::FFFF:127.0.0.1');
-SELECT @nip;
-@nip
-NULL
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-NULL
 SELECT USER();
 USER()
 root@localhost
@@ -174,6 +662,92 @@ USER()
 root@localhost
 DROP USER testuser1@'::FFFF:127.0.0.1';
 =============Test of '::FFFF:127.0.0.1/96' ========================
+SET @nip= inet_aton('::FFFF:127.0.0.1/96');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('::FFFF:127.0.0.1/96');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+NULL
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+NULL
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+NULL
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+NULL
 =============Test of '::1' ========================
 connect (con1, ::1, root, , test, MASTER_MYPORT,);
 Got one of the listed errors

=== modified file 'mysql-test/r/ipv6.result'
--- a/mysql-test/r/ipv6.result	2010-01-29 10:48:11 +0000
+++ b/mysql-test/r/ipv6.result	2011-05-03 13:04:00 +0000
@@ -6,13 +6,6 @@ SHOW GRANTS FOR testuser@'::1';
 Grants for testuser@::1
 GRANT USAGE ON *.* TO 'testuser'@'::1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'::1'
-SET @nip= inet_aton('::1');
-SELECT @nip;
-@nip
-NULL
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-NULL
 SELECT USER();
 USER()
 root@localhost
@@ -27,6 +20,94 @@ SELECT USER();
 USER()
 root@localhost
 DROP USER testuser1@'::1';
+SET @nip= inet_aton('::1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('::1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+Warnings:
+Warning	1366	Incorrect integer value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01' for column 'c6' at row 1
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+::1
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+::1
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+3000::
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+::1
 =============Test of '::1/128' ====================================
 =============Test of '0000:0000:0000:0000:0000:0000:0000:0001' ====
 mysqld is alive
@@ -36,13 +117,6 @@ SHOW GRANTS FOR testuser@'0000:0000:0000
 Grants for testuser@0000:0000:0000:0000:0000:0000:0000:0001
 GRANT USAGE ON *.* TO 'testuser'@'0000:0000:0000:0000:0000:0000:0000:0001' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0000:0000:0000:0000:0000:0000:0000:0001'
-SET @nip= inet_aton('0000:0000:0000:0000:0000:0000:0000:0001');
-SELECT @nip;
-@nip
-NULL
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-NULL
 SELECT USER();
 USER()
 root@localhost
@@ -57,6 +131,94 @@ SELECT USER();
 USER()
 root@localhost
 DROP USER testuser1@'0000:0000:0000:0000:0000:0000:0000:0001';
+SET @nip= inet_aton('0000:0000:0000:0000:0000:0000:0000:0001');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('0000:0000:0000:0000:0000:0000:0000:0001');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+Warnings:
+Warning	1366	Incorrect integer value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01' for column 'c6' at row 1
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+::1
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+::1
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+3000::
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+::1
 =============Test of '0:0:0:0:0:0:0:1' ============================
 mysqld is alive
 CREATE USER testuser@'0:0:0:0:0:0:0:1' identified by '1234';
@@ -65,13 +227,6 @@ SHOW GRANTS FOR testuser@'0:0:0:0:0:0:0:
 Grants for testuser@0:0:0:0:0:0:0:1
 GRANT USAGE ON *.* TO 'testuser'@'0:0:0:0:0:0:0:1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
 GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0:0:0:0:0:0:0:1'
-SET @nip= inet_aton('0:0:0:0:0:0:0:1');
-SELECT @nip;
-@nip
-NULL
-SELECT inet_ntoa(@nip);
-inet_ntoa(@nip)
-NULL
 SELECT USER();
 USER()
 root@localhost
@@ -86,3 +241,91 @@ SELECT USER();
 USER()
 root@localhost
 DROP USER testuser1@'0:0:0:0:0:0:0:1';
+SET @nip= inet_aton('0:0:0:0:0:0:0:1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip,@nip,@nip,@nip,@nip,@nip);
+SELECT inet_ntoa(c1) FROM t1;
+inet_ntoa(c1)
+NULL
+SELECT inet_ntoa(CAST(c1 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c1 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c2) FROM t1;
+inet_ntoa(c2)
+NULL
+SELECT inet_ntoa(CAST(c2 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c2 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c3) FROM t1;
+inet_ntoa(c3)
+NULL
+SELECT inet_ntoa(CAST(c3 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c3 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c4) FROM t1;
+inet_ntoa(c4)
+NULL
+SELECT inet_ntoa(CAST(c4 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c4 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c5) FROM t1;
+inet_ntoa(c5)
+NULL
+SELECT inet_ntoa(CAST(c5 AS UNSIGNED)) FROM t1;
+inet_ntoa(CAST(c5 AS UNSIGNED))
+NULL
+SELECT inet_ntoa(c6) FROM t1;
+inet_ntoa(c6)
+NULL
+DROP TABLE IF EXISTS t1;
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SET @nip6= inet6_aton('0:0:0:0:0:0:0:1');
+CREATE TABLE t1 (c1 varbinary(16), c2 varchar(16), c3 binary(16), c4 char(16), c5 long, c6 int);
+INSERT INTO t1 VALUES (@nip6,@nip6,@nip6,@nip6,@nip6,@nip6);
+Warnings:
+Warning	1366	Incorrect integer value: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01' for column 'c6' at row 1
+SELECT inet6_ntoa(c1) FROM t1;
+inet6_ntoa(c1)
+::1
+SELECT inet6_ntoa(CAST(c1 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c1 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c2) FROM t1;
+inet6_ntoa(c2)
+NULL
+SELECT inet6_ntoa(CAST(c2 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c2 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c3) FROM t1;
+inet6_ntoa(c3)
+::1
+SELECT inet6_ntoa(CAST(c3 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c3 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c4) FROM t1;
+inet6_ntoa(c4)
+NULL
+SELECT inet6_ntoa(CAST(c4 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c4 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c5) FROM t1;
+inet6_ntoa(c5)
+NULL
+SELECT inet6_ntoa(CAST(c5 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c5 AS BINARY(16)))
+::1
+SELECT inet6_ntoa(c6) FROM t1;
+inet6_ntoa(c6)
+NULL
+SELECT inet6_ntoa(CAST(c6 AS BINARY(16))) FROM t1;
+inet6_ntoa(CAST(c6 AS BINARY(16)))
+3000::
+DROP TABLE IF EXISTS t1;
+SELECT inet6_ntoa(@nip6);
+inet6_ntoa(@nip6)
+::1

=== modified file 'mysql-test/t/func_misc.test'
--- a/mysql-test/t/func_misc.test	2010-12-17 14:02:56 +0000
+++ b/mysql-test/t/func_misc.test	2011-05-03 13:03:00 +0000
@@ -541,6 +541,299 @@ DROP TABLE t1;
 --echo # End of 5.5 tests
 --echo #
 
+--echo
+--echo # --
+--echo # -- WL#5787: IPv6-capable INET_ATON and INET_NTOA functions.
+--echo # --
+
+--echo
+--echo # -- INET6_ATON: checking NULL, invalid types, out-of range values...
+--echo
+
+SELECT INET6_ATON(NULL) IS NULL;
+SELECT INET6_ATON(123) IS NULL;
+SELECT INET6_ATON(123.45) IS NULL;
+SELECT INET6_ATON(NOW()) IS NULL;
+
+SELECT INET6_ATON('1.2.3') IS NULL;
+SELECT INET6_ATON('1.2.3.') IS NULL;
+SELECT INET6_ATON('1..3.4') IS NULL;
+SELECT INET6_ATON('-1.2.3.4') IS NULL;
+SELECT INET6_ATON('1.2.3.256') IS NULL;
+SELECT INET6_ATON('1.2.3.4.5') IS NULL;
+SELECT INET6_ATON('0001.2.3.4') IS NULL;
+SELECT INET6_ATON('0x1.2.3.4') IS NULL;
+SELECT INET6_ATON('a.2.3.4') IS NULL;
+
+SELECT INET6_ATON('1.2.3.4:80') IS NULL;
+SELECT INET6_ATON('1.2.3.4/32') IS NULL;
+
+SELECT INET6_ATON('mysql.com') IS NULL;
+
+SELECT INET6_ATON(':::') IS NULL;
+SELECT INET6_ATON(':1:2:3') IS NULL;
+SELECT INET6_ATON('1:2:3:') IS NULL;
+SELECT INET6_ATON(':1::2:3') IS NULL;
+SELECT INET6_ATON('1::2:3:') IS NULL;
+SELECT INET6_ATON('::00001') IS NULL;
+SELECT INET6_ATON('::00001:2') IS NULL;
+SELECT INET6_ATON('::12345') IS NULL;
+SELECT INET6_ATON('1020::3040::5060') IS NULL;
+SELECT INET6_ATON('::ABCZ') IS NULL;
+
+SELECT INET6_ATON('::0x1.2.3.4') IS NULL;
+SELECT INET6_ATON('::1.0x2.3.4') IS NULL;
+SELECT INET6_ATON('::a.b.c.d') IS NULL;
+
+SELECT INET6_ATON('::FFFF:0x1.2.3.4') IS NULL;
+SELECT INET6_ATON('::FFFF:1.0x2.3.4') IS NULL;
+SELECT INET6_ATON('::FFFF:a.b.c.d') IS NULL;
+
+SELECT INET6_ATON('::1.2.3.4:ABCD') IS NULL;
+
+--echo # NOTE: such addresses are supported because getaddrinfo() supports them.
+--echo # This is just to record the current behaviour.
+SELECT HEX(INET6_ATON('::ABCD:1.2.3.4'));
+
+--echo
+--echo # -- INET6_ATON: checking binary representation...
+--echo
+
+SELECT HEX(INET6_ATON('0.0.0.0'));
+SELECT HEX(INET6_ATON('00.00.00.00'));
+SELECT HEX(INET6_ATON('000.000.000.000'));
+SELECT HEX(INET6_ATON('1.2.3.4'));
+SELECT HEX(INET6_ATON('01.02.03.04'));
+SELECT HEX(INET6_ATON('001.002.003.004'));
+SELECT HEX(INET6_ATON('255.255.255.255'));
+SELECT HEX(INET6_ATON('::'));
+SELECT HEX(INET6_ATON('0::0'));
+SELECT HEX(INET6_ATON('1::2'));
+SELECT HEX(INET6_ATON('0::'));
+SELECT HEX(INET6_ATON('1::'));
+SELECT HEX(INET6_ATON('::0'));
+SELECT HEX(INET6_ATON('::1'));
+SELECT HEX(INET6_ATON('1:2:3:4:5:6:7:8'));
+SELECT HEX(INET6_ATON('::2:3:4:5:6:7:8'));
+SELECT HEX(INET6_ATON('1::3:4:5:6:7:8'));
+SELECT HEX(INET6_ATON('1:2::4:5:6:7:8'));
+SELECT HEX(INET6_ATON('1:2:3::5:6:7:8'));
+SELECT HEX(INET6_ATON('1:2:3:4::6:7:8'));
+SELECT HEX(INET6_ATON('1:2:3:4:5::7:8'));
+SELECT HEX(INET6_ATON('1:2:3:4:5:6::8'));
+SELECT HEX(INET6_ATON('1:2:3:4:5:6:7::'));
+SELECT HEX(INET6_ATON('0000:0000::0000:0001'));
+SELECT HEX(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed'));
+SELECT HEX(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001'));
+SELECT HEX(INET6_ATON('::C0A8:0102'));
+SELECT HEX(INET6_ATON('::c0a8:0102'));
+SELECT HEX(INET6_ATON('::192.168.1.2'));
+SELECT HEX(INET6_ATON('::FfFf:C0a8:0102'));
+SELECT HEX(INET6_ATON('::ffff:c0a8:0102'));
+SELECT HEX(INET6_ATON('::ffff:192.168.1.2'));
+SELECT HEX(INET6_ATON('::01.2.3.4'));
+SELECT HEX(INET6_ATON('::1.02.3.4'));
+SELECT HEX(INET6_ATON('::1.2.03.4'));
+SELECT HEX(INET6_ATON('::1.2.3.04'));
+SELECT HEX(INET6_ATON('::1.2.3.00'));
+SELECT HEX(INET6_ATON('::FFFF:01.2.3.4'));
+SELECT HEX(INET6_ATON('::FFFF:1.02.3.4'));
+SELECT HEX(INET6_ATON('::FFFF:1.2.03.4'));
+SELECT HEX(INET6_ATON('::FFFF:1.2.3.04'));
+SELECT HEX(INET6_ATON('::FFFF:1.2.3.00'));
+
+--echo
+--echo # -- INET6_ATON: checking the length is either 4 or 16...
+--echo
+
+SELECT LENGTH(INET6_ATON('0.0.0.0'));
+SELECT LENGTH(INET6_ATON('255.255.255.255'));
+SELECT LENGTH(INET6_ATON('::'));
+SELECT LENGTH(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010'));
+
+--echo
+--echo # -- INET6_NTOA: checking NULL, invalid types, out-of range values...
+--echo
+
+SELECT INET6_NTOA(NULL);
+SELECT INET6_NTOA(123);
+SELECT INET6_NTOA(123.456);
+SELECT INET6_NTOA(NOW());
+SELECT INET6_NTOA(UNHEX('C0A801'));     # 3 bytes -> NULL
+SELECT INET6_NTOA(UNHEX('C0A80102'));   # 4 bytes -> 192.168.1.2
+SELECT INET6_NTOA(UNHEX('C0A8010203')); # 5 bytes -> NULL
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F'));     # 15 bytes -> NULL
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F10'));   # 16 bytes -> IP
+SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F1011')); # 17 bytes -> NULL
+
+SELECT INET6_NTOA('1234'), INET6_NTOA(BINARY('1234'));
+SELECT INET6_NTOA('0123456789abcdef'), INET6_NTOA(BINARY('0123456789abcdef'));
+
+--echo
+--echo # -- Checking double-conversion...
+--echo
+
+SELECT INET6_NTOA(INET6_ATON('::'));
+SELECT INET6_NTOA(INET6_ATON('0::0'));
+SELECT INET6_NTOA(INET6_ATON('1::2'));
+SELECT INET6_NTOA(INET6_ATON('0::'));
+SELECT INET6_NTOA(INET6_ATON('1::'));
+SELECT INET6_NTOA(INET6_ATON('::0'));
+SELECT INET6_NTOA(INET6_ATON('::1'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('::2:3:4:5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1::3:4:5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2::4:5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3::5:6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4::6:7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5::7:8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6::8'));
+SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7::'));
+SELECT INET6_NTOA(INET6_ATON('0000:0000::0000:0001'));
+SELECT INET6_NTOA(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed'));
+SELECT INET6_NTOA(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001'));
+SELECT INET6_NTOA(INET6_ATON('::C0A8:0102'));
+SELECT INET6_NTOA(INET6_ATON('::c0a8:0102'));
+SELECT INET6_NTOA(INET6_ATON('::192.168.1.2'));
+SELECT INET6_NTOA(INET6_ATON('::FfFf:C0a8:0102'));
+SELECT INET6_NTOA(INET6_ATON('::ffff:c0a8:0102'));
+SELECT INET6_NTOA(INET6_ATON('::ffff:192.168.1.2'));
+SELECT INET6_NTOA(INET6_ATON('::01.2.3.4'));
+SELECT INET6_NTOA(INET6_ATON('::1.02.3.4'));
+SELECT INET6_NTOA(INET6_ATON('::1.2.03.4'));
+SELECT INET6_NTOA(INET6_ATON('::1.2.3.04'));
+SELECT INET6_NTOA(INET6_ATON('::1.2.3.00'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:01.2.3.4'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.02.3.4'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.03.4'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.04'));
+SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.00'));
+
+--echo
+--echo # -- Comparing INET_ATON() and INET6_ATON()...
+--echo
+
+SELECT HEX(INET_ATON('192.168.1.2'));
+SELECT HEX(INET6_ATON('192.168.1.2'));
+
+SELECT HEX(INET_ATON('255.255.255.255'));
+SELECT HEX(INET6_ATON('255.255.255.255'));
+
+SELECT HEX(INET_ATON('192.168.08.2'));
+SELECT HEX(INET6_ATON('192.168.08.2'));
+
+SELECT HEX(INET_ATON('192.168.0x8.2'));
+SELECT HEX(INET6_ATON('192.168.0x8.2'));
+
+SELECT HEX(INET_ATON('1.2.255'));
+SELECT HEX(INET6_ATON('1.2.255'));
+
+SELECT HEX(INET_ATON('1.2.256'));
+SELECT HEX(INET6_ATON('1.2.256'));
+
+SELECT HEX(INET_ATON('1.0002.3.4'));
+SELECT HEX(INET6_ATON('1.0002.3.4'));
+
+SELECT HEX(INET_ATON('1.2.3.4.5'));
+SELECT HEX(INET6_ATON('1.2.3.4.5'));
+
+--echo
+--echo # -- Checking mix of INET- and INET6- functions...
+--echo
+
+SELECT HEX(INET6_ATON(INET_NTOA(INET_ATON('1.2.3.4')))) AS x;
+
+--echo
+--echo # -- Checking IS_IPV4() / IS_IPV6()...
+--echo
+
+SELECT IS_IPV4(NULL);
+SELECT IS_IPV4(1);
+SELECT IS_IPV4(1.0);
+SELECT IS_IPV4('1.2.3.4');
+SELECT IS_IPV4('001.02.000.255');
+SELECT IS_IPV4('::1.2.0.255');
+SELECT IS_IPV4('::1');
+SELECT IS_IPV4(BINARY('1.2.3.4'));
+
+SELECT IS_IPV6(NULL);
+SELECT IS_IPV6(1);
+SELECT IS_IPV6(1.0);
+SELECT IS_IPV6('1.2.3.4');
+SELECT IS_IPV6('001.02.000.255');
+SELECT IS_IPV6('::001.02.000.255');
+SELECT IS_IPV6('::1.2.0.255');
+SELECT IS_IPV6('::1');
+SELECT IS_IPV6('0000:0000:0000:0000:0000:0000:0000:0001');
+SELECT IS_IPV6(BINARY('0000:0000:0000:0000:0000:0000:0000:0001'));
+
+--echo
+--echo # -- Checking IS_IPV4_MAPPED() and IS_IPV4_COMPAT()...
+--echo
+
+SELECT IS_IPV4_MAPPED(INET6_ATON('1.2.3.4')),
+       IS_IPV4_COMPAT(INET6_ATON('1.2.3.4'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::1.2.3.4')),
+       IS_IPV4_COMPAT(INET6_ATON('::1.2.3.4'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::FFFF:1.2.3.4')),
+       IS_IPV4_COMPAT(INET6_ATON('::FFFF:1.2.3.4'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::ABCD:1.2.3.4')),
+       IS_IPV4_COMPAT(INET6_ATON('::ABCD:1.2.3.4'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::1')),
+       IS_IPV4_COMPAT(INET6_ATON('::1'));
+SELECT IS_IPV4_MAPPED(INET6_ATON('::')),
+       IS_IPV4_COMPAT(INET6_ATON('::'));
+
+# NOTE: IS_IPV4_COMPAT() / IS_IPV4_MAPPED() could work with "regular strings in
+# binary collation" too, but there is no way to create a "regular string"
+# starting with \0.
+
+--echo
+--echo # -- Checking IS_IPV4_COMPAT()...
+--echo
+
+--echo
+--echo # -- Working with a table...
+--echo
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TABLE IF EXISTS t2;
+--enable_warnings
+
+CREATE TABLE t1(ip INT UNSIGNED);
+CREATE TABLE t2(ip VARBINARY(16));
+
+--echo
+
+INSERT INTO t1 VALUES
+  (INET_ATON('1.2.3.4')), (INET_ATON('255.255.255.255'));
+SELECT INET_NTOA(ip) FROM t1;
+
+--echo
+
+INSERT INTO t2 SELECT INET6_ATON(INET_NTOA(ip)) FROM t1;
+SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2;
+DELETE FROM t2;
+
+--echo
+
+INSERT INTO t2 VALUES
+  (INET6_ATON('1.2.3.4')), (INET6_ATON('255.255.255.255')),
+  (INET6_ATON('::1.2.3.4')), (INET6_ATON('::ffff:255.255.255.255')),
+  (INET6_ATON('::')), (INET6_ATON('::1')),
+  (INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010'));
+SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2;
+
+--echo
+
+DROP TABLE t1;
+DROP TABLE t2;
+
+--echo
+--echo # -- Done.
+--echo
+
 --echo #
 --echo # End of tests
 --echo #

=== modified file 'mysql-test/t/ipv4_as_ipv6.test'
--- a/mysql-test/t/ipv4_as_ipv6.test	2010-01-29 10:48:11 +0000
+++ b/mysql-test/t/ipv4_as_ipv6.test	2011-05-03 13:04:00 +0000
@@ -16,31 +16,37 @@ echo =============Test of '127.0.0.1' (I
 let $IPv6= 127.0.0.1;
 --source include/ipv6_clients.inc
 --source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '0:0:0:0:0:FFFF:127.0.0.1' ===================;
 let $IPv6= 0:0:0:0:0:FFFF:127.0.0.1;
 --source include/ipv6_clients.inc
 --source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '0000:0000:0000:0000:0000:FFFF:127.0.0.1' ====;
 let $IPv6= 0000:0000:0000:0000:0000:FFFF:127.0.0.1;
 --source include/ipv6_clients.inc
 --source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '0:0000:0000:0:0000:FFFF:127.0.0.1' ====;
 let $IPv6= 0:0000:0000:0:0000:FFFF:127.0.0.1;
 --source include/ipv6_clients.inc
 --source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '0::0000:FFFF:127.0.0.1' ====;
 let $IPv6= 0::0000:FFFF:127.0.0.1;
 --source include/ipv6_clients.inc
 --source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '0:0:0:0:0:FFFF:127.0.0.1/96' ================;
 let $IPv6= 0:0:0:0:0:FFFF:127.0.0.1/96;
 #--source include/ipv6_clients.inc
 #--source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '::FFFF:127.0.0.1' ===========================;
 let $IPv6= ::FFFF:127.0.0.1;
@@ -51,6 +57,7 @@ echo =============Test of '::FFFF:127.0.
 let $IPv6= ::FFFF:127.0.0.1/96;
 #--source include/ipv6_clients.inc
 #--source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '::1' ========================;
 let $IPv6= ::1;

=== modified file 'mysql-test/t/ipv6.test'
--- a/mysql-test/t/ipv6.test	2010-01-29 10:48:11 +0000
+++ b/mysql-test/t/ipv6.test	2011-05-03 13:04:00 +0000
@@ -16,6 +16,7 @@ echo =============Test of '::1' ========
 let $IPv6= ::1;
 --source include/ipv6_clients.inc
 --source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '::1/128' ====================================;
 let $IPv6= ::1/128;
@@ -26,11 +27,13 @@ echo =============Test of '0000:0000:000
 let $IPv6= 0000:0000:0000:0000:0000:0000:0000:0001;
 --source include/ipv6_clients.inc
 --source include/ipv6.inc
+--source include/ipv6_func.inc
 
 echo =============Test of '0:0:0:0:0:0:0:1' ============================;
 let $IPv6= 0:0:0:0:0:0:0:1;
 --source include/ipv6_clients.inc
 --source include/ipv6.inc
+--source include/ipv6_func.inc
 
 # Wait till all disconnects are completed
 --source include/wait_until_count_sessions.inc

=== modified file 'sql/item_create.cc'
--- a/sql/item_create.cc	2011-04-15 09:04:21 +0000
+++ b/sql/item_create.cc	2011-05-03 13:03:00 +0000
@@ -1204,6 +1204,84 @@ protected:
 };
 
 
+class Create_func_inet6_aton : public Create_func_arg1
+{
+public:
+  virtual Item *create(THD *thd, Item *arg1);
+
+  static Create_func_inet6_aton s_singleton;
+
+protected:
+  Create_func_inet6_aton() {}
+  virtual ~Create_func_inet6_aton() {}
+};
+
+
+class Create_func_inet6_ntoa : public Create_func_arg1
+{
+public:
+  virtual Item *create(THD *thd, Item *arg1);
+
+  static Create_func_inet6_ntoa s_singleton;
+
+protected:
+  Create_func_inet6_ntoa() {}
+  virtual ~Create_func_inet6_ntoa() {}
+};
+
+
+class Create_func_is_ipv4 : public Create_func_arg1
+{
+public:
+  virtual Item *create(THD *thd, Item *arg1);
+
+  static Create_func_is_ipv4 s_singleton;
+
+protected:
+  Create_func_is_ipv4() {}
+  virtual ~Create_func_is_ipv4() {}
+};
+
+
+class Create_func_is_ipv6 : public Create_func_arg1
+{
+public:
+  virtual Item *create(THD *thd, Item *arg1);
+
+  static Create_func_is_ipv6 s_singleton;
+
+protected:
+  Create_func_is_ipv6() {}
+  virtual ~Create_func_is_ipv6() {}
+};
+
+
+class Create_func_is_ipv4_compat : public Create_func_arg1
+{
+public:
+  virtual Item *create(THD *thd, Item *arg1);
+
+  static Create_func_is_ipv4_compat s_singleton;
+
+protected:
+  Create_func_is_ipv4_compat() {}
+  virtual ~Create_func_is_ipv4_compat() {}
+};
+
+
+class Create_func_is_ipv4_mapped : public Create_func_arg1
+{
+public:
+  virtual Item *create(THD *thd, Item *arg1);
+
+  static Create_func_is_ipv4_mapped s_singleton;
+
+protected:
+  Create_func_is_ipv4_mapped() {}
+  virtual ~Create_func_is_ipv4_mapped() {}
+};
+
+
 class Create_func_instr : public Create_func_arg2
 {
 public:
@@ -3904,6 +3982,24 @@ Create_func_inet_ntoa::create(THD *thd,
 }
 
 
+Create_func_inet6_aton Create_func_inet6_aton::s_singleton;
+
+Item*
+Create_func_inet6_aton::create(THD *thd, Item *arg1)
+{
+  return new (thd->mem_root) Item_func_inet6_aton(arg1);
+}
+
+
+Create_func_inet6_ntoa Create_func_inet6_ntoa::s_singleton;
+
+Item*
+Create_func_inet6_ntoa::create(THD *thd, Item *arg1)
+{
+  return new (thd->mem_root) Item_func_inet6_ntoa(arg1);
+}
+
+
 Create_func_inet_aton Create_func_inet_aton::s_singleton;
 
 Item*
@@ -3913,6 +4009,42 @@ Create_func_inet_aton::create(THD *thd,
 }
 
 
+Create_func_is_ipv4 Create_func_is_ipv4::s_singleton;
+
+Item*
+Create_func_is_ipv4::create(THD *thd, Item *arg1)
+{
+  return new (thd->mem_root) Item_func_is_ipv4(arg1);
+}
+
+
+Create_func_is_ipv6 Create_func_is_ipv6::s_singleton;
+
+Item*
+Create_func_is_ipv6::create(THD *thd, Item *arg1)
+{
+  return new (thd->mem_root) Item_func_is_ipv6(arg1);
+}
+
+
+Create_func_is_ipv4_compat Create_func_is_ipv4_compat::s_singleton;
+
+Item*
+Create_func_is_ipv4_compat::create(THD *thd, Item *arg1)
+{
+  return new (thd->mem_root) Item_func_is_ipv4_compat(arg1);
+}
+
+
+Create_func_is_ipv4_mapped Create_func_is_ipv4_mapped::s_singleton;
+
+Item*
+Create_func_is_ipv4_mapped::create(THD *thd, Item *arg1)
+{
+  return new (thd->mem_root) Item_func_is_ipv4_mapped(arg1);
+}
+
+
 Create_func_instr Create_func_instr::s_singleton;
 
 Item*
@@ -5279,6 +5411,12 @@ static Native_func_registry func_array[]
   { { C_STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
   { { C_STRING_WITH_LEN("INET_ATON") }, BUILDER(Create_func_inet_aton)},
   { { C_STRING_WITH_LEN("INET_NTOA") }, BUILDER(Create_func_inet_ntoa)},
+  { { C_STRING_WITH_LEN("INET6_ATON") }, BUILDER(Create_func_inet6_aton)},
+  { { C_STRING_WITH_LEN("INET6_NTOA") }, BUILDER(Create_func_inet6_ntoa)},
+  { { C_STRING_WITH_LEN("IS_IPV4") }, BUILDER(Create_func_is_ipv4)},
+  { { C_STRING_WITH_LEN("IS_IPV6") }, BUILDER(Create_func_is_ipv6)},
+  { { C_STRING_WITH_LEN("IS_IPV4_COMPAT") }, BUILDER(Create_func_is_ipv4_compat)},
+  { { C_STRING_WITH_LEN("IS_IPV4_MAPPED") }, BUILDER(Create_func_is_ipv4_mapped)},
   { { C_STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
   { { C_STRING_WITH_LEN("INTERIORRINGN") }, GEOM_BUILDER(Create_func_interiorringn)},
   { { C_STRING_WITH_LEN("INTERSECTS") }, GEOM_BUILDER(Create_func_mbr_intersects)},

=== modified file 'sql/item_inetfunc.cc'
--- a/sql/item_inetfunc.cc	2011-04-15 09:42:59 +0000
+++ b/sql/item_inetfunc.cc	2011-05-03 13:03:00 +0000
@@ -19,6 +19,14 @@
 
 ///////////////////////////////////////////////////////////////////////////
 
+static const int IN_ADDR_SIZE= sizeof (in_addr);
+static const int IN6_ADDR_SIZE= sizeof (in6_addr);
+static const int IN6_ADDR_NUM_WORDS= IN6_ADDR_SIZE / 2;
+
+static const char HEX_DIGITS[]= "0123456789abcdef";
+
+///////////////////////////////////////////////////////////////////////////
+
 longlong Item_func_inet_aton::val_int()
 {
   DBUG_ASSERT(fixed);
@@ -131,3 +139,699 @@ String* Item_func_inet_ntoa::val_str(Str
 
   return str;
 }
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Check the function argument, handle errors properly.
+
+  @return The function value.
+*/
+
+longlong Item_func_inet_bool_base::val_int()
+{
+  DBUG_ASSERT(fixed);
+
+  if (args[0]->result_type() != STRING_RESULT ||  // String argument expected
+      args[0]->null_value)                        // Not-NULL argument expected
+    return 0;
+
+  String buffer;
+  String *arg_str= args[0]->val_str(&buffer);
+
+  if (!arg_str) // Out-of memory happened. The error has been reported.
+    return 0;
+
+  return calc_value(arg_str) ? 1 : 0;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Check the function argument, handle errors properly.
+
+  @param [out] buffer Buffer for string operations.
+
+  @return The function value.
+*/
+
+String *Item_func_inet_str_base::val_str_ascii(String *buffer)
+{
+  DBUG_ASSERT(fixed);
+
+  if (args[0]->result_type() != STRING_RESULT ||  // String argument expected
+      args[0]->null_value)                        // Not-NULL argument expected
+  {
+    null_value= true;
+    return NULL;
+  }
+
+  String *arg_str= args[0]->val_str(buffer);
+
+  if (!arg_str) // Out-of memory happened. The error has been reported.
+  {
+    null_value= true;
+    return NULL;
+  }
+
+  null_value= !calc_value(arg_str, buffer);
+
+  return null_value ? NULL : buffer;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Tries to convert given string to binary IPv4-address representation.
+  This is a portable alternative to inet_pton(AF_INET).
+
+  @param      str          String to convert.
+  @param      str_len      String length.
+  @param[out] ipv4_address Buffer to store IPv4-address.
+
+  @return Completion status.
+  @retval false Given string does not represent an IPv4-address.
+  @retval true  The string has been converted sucessfully.
+
+  @note The problem with inet_pton() is that it treats leading zeros in
+  IPv4-part differently on different platforms.
+*/
+
+static bool str_to_ipv4(const char *str, int str_length, in_addr *ipv4_address)
+{
+  if (str_length < 7)
+  {
+    DBUG_PRINT("error", ("str_to_ipv4(%.*s): "
+                         "invalid IPv4 address: too short.",
+                         str_length, str));
+    return false;
+  }
+
+  if (str_length > 15)
+  {
+    DBUG_PRINT("error", ("str_to_ipv4(%.*s): "
+                         "invalid IPv4 address: too long.",
+                         str_length, str));
+    return false;
+  }
+
+  unsigned char *ipv4_bytes= (unsigned char *) ipv4_address;
+  const char *p= str;
+  int byte_value= 0;
+  int chars_in_group= 0;
+  int dot_count= 0;
+  char c;
+
+  while (*p && ((p - str) < str_length))
+  {
+    c= *p++;
+
+    if (my_isdigit(&my_charset_latin1, c))
+    {
+      ++chars_in_group;
+
+      if (chars_in_group > 3)
+      {
+        DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: "
+                             "too many characters in a group.",
+                             str_length, str));
+        return false;
+      }
+
+      byte_value= byte_value * 10 + (c - '0');
+
+      if (byte_value > 255)
+      {
+        DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: "
+                             "invalid byte value.",
+                             str_length, str));
+        return false;
+      }
+    }
+    else if (c == '.')
+    {
+      if (chars_in_group == 0)
+      {
+        DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: "
+                             "too few characters in a group.",
+                             str_length, str));
+        return false;
+      }
+
+      ipv4_bytes[dot_count]= (unsigned char) byte_value;
+
+      ++dot_count;
+      byte_value= 0;
+      chars_in_group= 0;
+
+      if (dot_count > 3)
+      {
+        DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: "
+                             "too many dots.", str_length, str));
+        return false;
+      }
+    }
+    else
+    {
+      DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: "
+                           "invalid character at pos %d.",
+                           str_length, str, (int) (p - str)));
+      return false;
+    }
+  }
+
+  if (c == '.')
+  {
+    DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: "
+                         "ending at '.'.", str_length, str));
+    return false;
+  }
+
+  if (dot_count != 3)
+  {
+    DBUG_PRINT("error", ("str_to_ipv4(%.*s): invalid IPv4 address: "
+                         "classful address (too few groups).",
+                         str_length, str));
+    return false;
+  }
+
+  ipv4_bytes[3]= (unsigned char) byte_value;
+
+  DBUG_PRINT("info", ("str_to_ipv4(%.*s): valid IPv4 address: %d.%d.%d.%d",
+                      str_length, str,
+                      ipv4_bytes[0], ipv4_bytes[1],
+                      ipv4_bytes[2], ipv4_bytes[3]));
+  return true;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Tries to convert given string to binary IPv6-address representation.
+  This is a portable alternative to inet_pton(AF_INET6).
+
+  @param      str          String to convert.
+  @param      str_len      String length.
+  @param[out] ipv6_address Buffer to store IPv6-address.
+
+  @return Completion status.
+  @retval false Given string does not represent an IPv6-address.
+  @retval true  The string has been converted sucessfully.
+
+  @note The problem with inet_pton() is that it treats leading zeros in
+  IPv4-part differently on different platforms.
+*/
+
+static bool str_to_ipv6(const char *str, int str_length, in6_addr *ipv6_address)
+{
+  if (str_length < 2)
+  {
+    DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: too short.",
+                         str_length, str));
+    return false;
+  }
+
+  if (str_length > 8 * 4 + 7)
+  {
+    DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: too long.",
+                         str_length, str));
+    return false;
+  }
+
+  bzero(ipv6_address, IN6_ADDR_SIZE);
+
+  const char *p= str;
+
+  if (*p == ':')
+  {
+    ++p;
+
+    if (*p != ':')
+    {
+      DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                           "can not start with ':x'.", str_length, str));
+      return false;
+    }
+  }
+
+  char *ipv6_bytes= (char *) ipv6_address;
+  char *ipv6_bytes_end= ipv6_bytes + IN6_ADDR_SIZE;
+  char *dst= ipv6_bytes;
+  char *gap_ptr= NULL;
+  const char *group_start_ptr= p;
+  int chars_in_group= 0;
+  int group_value= 0;
+
+  while (*p && ((p - str) < str_length))
+  {
+    char c= *p++;
+
+    if (c == ':')
+    {
+      group_start_ptr= p;
+
+      if (!chars_in_group)
+      {
+        if (gap_ptr)
+        {
+          DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                               "too many gaps(::).", str_length, str));
+          return false;
+        }
+
+        gap_ptr= dst;
+        continue;
+      }
+
+      if (!*p || ((p - str) >= str_length))
+      {
+        DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                             "ending at ':'.", str_length, str));
+        return false;
+      }
+
+      if (dst + 2 > ipv6_bytes_end)
+      {
+        DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                             "too many groups (1).", str_length, str));
+        return false;
+      }
+
+      dst[0]= (unsigned char) (group_value >> 8) & 0xff;
+      dst[1]= (unsigned char) group_value & 0xff;
+      dst += 2;
+
+      chars_in_group= 0;
+      group_value= 0;
+    }
+    else if (c == '.')
+    {
+      if (dst + IN_ADDR_SIZE > ipv6_bytes_end)
+      {
+        DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                             "unexpected IPv4-part.", str_length, str));
+        return false;
+      }
+
+      if (!str_to_ipv4(group_start_ptr,
+                       str + str_length - group_start_ptr,
+                       (in_addr *) dst))
+      {
+        DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                             "invalid IPv4-part.", str_length, str));
+        return false;
+      }
+
+      dst += IN_ADDR_SIZE;
+      chars_in_group= 0;
+
+      break;
+    }
+    else
+    {
+      const char *hdp= strchr(HEX_DIGITS, my_tolower(&my_charset_latin1, c));
+
+      if (!hdp)
+      {
+        DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                             "invalid character at pos %d.",
+                             str_length, str, (int) (p - str)));
+        return false;
+      }
+
+      if (chars_in_group >= 4)
+      {
+        DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                             "too many digits in group.",
+                             str_length, str));
+        return false;
+      }
+
+      group_value <<= 4;
+      group_value |= hdp - HEX_DIGITS;
+
+      DBUG_ASSERT(group_value <= 0xffff);
+
+      ++chars_in_group;
+    }
+  }
+
+  if (chars_in_group > 0)
+  {
+    if (dst + 2 > ipv6_bytes_end)
+    {
+      DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                           "too many groups (2).", str_length, str));
+      return false;
+    }
+
+    dst[0]= (unsigned char) (group_value >> 8) & 0xff;
+    dst[1]= (unsigned char) group_value & 0xff;
+    dst += 2;
+  }
+
+  if (gap_ptr)
+  {
+    if (dst == ipv6_bytes_end)
+    {
+      DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                           "no room for a gap (::).", str_length, str));
+      return false;
+    }
+
+    int bytes_to_move= dst - gap_ptr;
+
+    for (int i= 1; i <= bytes_to_move; ++i)
+    {
+      ipv6_bytes_end[-i]= gap_ptr[bytes_to_move - i];
+      gap_ptr[bytes_to_move - i]= 0;
+    }
+
+    dst= ipv6_bytes_end;
+  }
+
+  if (dst < ipv6_bytes_end)
+  {
+    DBUG_PRINT("error", ("str_to_ipv6(%.*s): invalid IPv6 address: "
+                         "too few groups.", str_length, str));
+    return false;
+  }
+
+  return true;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Converts IPv4-binary-address to a string. This function is a portable
+  alternative to inet_ntop(AF_INET).
+
+  @param[in] ipv4 IPv4-address data (byte array)
+  @param[out] str A buffer to store string representation of IPv4-address.
+                  It must be at least of INET_ADDRSTRLEN.
+
+  @note The problem with inet_ntop() is that it is available starting from
+  Windows Vista, but out the minimum supported version is Windows 2000.
+*/
+
+static void ipv4_to_str(const in_addr *ipv4, char *str)
+{
+  const unsigned char *ipv4_bytes= (const unsigned char *) ipv4;
+
+  sprintf(str, "%d.%d.%d.%d",
+          ipv4_bytes[0], ipv4_bytes[1], ipv4_bytes[2], ipv4_bytes[3]);
+}
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Converts IPv6-binary-address to a string. This function is a portable
+  alternative to inet_ntop(AF_INET6).
+
+  @param[in] ipv6 IPv6-address data (byte array)
+  @param[out] str A buffer to store string representation of IPv6-address.
+                  It must be at least of INET6_ADDRSTRLEN.
+
+  @note The problem with inet_ntop() is that it is available starting from
+  Windows Vista, but out the minimum supported version is Windows 2000.
+*/
+
+static void ipv6_to_str(const in6_addr *ipv6, char *str)
+{
+  struct Region
+  {
+    int pos;
+    int length;
+  };
+
+  const unsigned char *ipv6_bytes= (const unsigned char *) ipv6;
+
+  // 1. Translate IPv6-address bytes to words.
+  // We can't just cast to short, because it's not guaranteed
+  // that sizeof (short) == 2. So, we have to make a copy.
+
+  uint16 ipv6_words[IN6_ADDR_NUM_WORDS];
+
+  for (int i= 0; i < IN6_ADDR_NUM_WORDS; ++i)
+    ipv6_words[i]= (ipv6_bytes[2 * i] << 8) + ipv6_bytes[2 * i + 1];
+
+  // 2. Find "the gap" -- longest sequence of zeros in IPv6-address.
+
+  Region gap= { -1, -1 };
+
+  {
+    Region rg= { -1, -1 };
+
+    for (int i = 0; i < IN6_ADDR_NUM_WORDS; ++i)
+    {
+      if (ipv6_words[i] != 0)
+      {
+        if (rg.pos >= 0)
+        {
+          if (rg.length > gap.length)
+            gap= rg;
+
+          rg.pos= -1;
+          rg.length= -1;
+        }
+      }
+      else
+      {
+        if (rg.pos >= 0)
+        {
+          ++rg.length;
+        }
+        else
+        {
+          rg.pos= i;
+          rg.length= 1;
+        }
+      }
+    }
+
+    if (rg.pos >= 0)
+    {
+      if (rg.length > gap.length)
+        gap= rg;
+    }
+  }
+
+  // 3. Convert binary data to string.
+
+  char *p= str;
+
+  for (int i = 0; i < IN6_ADDR_NUM_WORDS; ++i)
+  {
+    if (i == gap.pos)
+    {
+      // We're at the gap position. We should put trailing ':' and jump to
+      // the end of the gap.
+
+      if (i == 0)
+      {
+        // The gap starts from the beginning of the data -- leading ':'
+        // should be put additionally.
+
+        *p= ':';
+        ++p;
+      }
+
+      *p= ':';
+      ++p;
+
+      i += gap.length - 1;
+    }
+    else if (i == 6 && gap.pos == 0 &&
+             (gap.length == 6 ||                           // IPv4-compatible
+              (gap.length == 5 && ipv6_words[5] == 0xffff) // IPv4-mapped
+             ))
+    {
+      // The data represents either IPv4-compatible or IPv4-mapped address.
+      // The IPv6-part (zeros or zeros + ffff) has been already put into
+      // the string (str). Now it's time to dump IPv4-part.
+
+      ipv4_to_str((const in_addr *) (ipv6_bytes + 12), p);
+      return;
+    }
+    else
+    {
+      // Usual IPv6-address-field. Print it out using lower-case
+      // hex-letters without leading zeros (recommended IPv6-format).
+      //
+      // If it is not the last field, append closing ':'.
+
+      p += sprintf(p, "%x", ipv6_words[i]);
+
+      if (i != IN6_ADDR_NUM_WORDS - 1)
+      {
+        *p= ':';
+        ++p;
+      }
+    }
+  }
+
+  *p= 0;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Converts IP-address-string to IP-address-data.
+
+  @param       arg    IP-address-string.
+  @param [out] buffer Buffer to store IP-address-data.
+
+  @return Completion status.
+  @retval false Given string does not represent an IP-address.
+  @retval true  The string has been converted sucessfully.
+*/
+
+bool Item_func_inet6_aton::calc_value(String *arg, String *buffer)
+{
+  // ipv4-string -> varbinary(4)
+  // ipv6-string -> varbinary(16)
+
+  in_addr ipv4_address;
+  in6_addr ipv6_address;
+
+  if (str_to_ipv4(arg->ptr(), arg->length(), &ipv4_address))
+  {
+    buffer->length(0);
+    buffer->append((char *) &ipv4_address, sizeof (in_addr), &my_charset_bin);
+
+    return true;
+  }
+
+  if (str_to_ipv6(arg->ptr(), arg->length(), &ipv6_address))
+  {
+    buffer->length(0);
+    buffer->append((char *) &ipv6_address, sizeof (in6_addr), &my_charset_bin);
+
+    return true;
+  }
+
+  return false;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Converts IP-address-data to IP-address-string.
+
+  @param       arg    IP-address-data.
+  @param [out] buffer Buffer to store IP-address-string.
+
+  @return Completion status.
+  @retval false The argument does not correspond to IP-address.
+  @retval true  The string has been converted sucessfully.
+*/
+
+bool Item_func_inet6_ntoa::calc_value(String *arg, String *buffer)
+{
+  if (arg->charset() != &my_charset_bin)
+    return false;
+
+  if ((int) arg->length() == IN_ADDR_SIZE)
+  {
+    char str[INET_ADDRSTRLEN];
+
+    ipv4_to_str((const in_addr *) arg->ptr(), str);
+
+    buffer->length(0);
+    buffer->append(str, (uint32) strlen(str), &my_charset_latin1);
+
+    return true;
+  }
+  else if ((int) arg->length() == IN6_ADDR_SIZE)
+  {
+    char str[INET6_ADDRSTRLEN];
+
+    ipv6_to_str((const in6_addr *) arg->ptr(), str);
+
+    buffer->length(0);
+    buffer->append(str, (uint32) strlen(str), &my_charset_latin1);
+
+    return true;
+  }
+
+  DBUG_PRINT("info",
+             ("INET6_NTOA(): varbinary(4) or varbinary(16) expected."));
+  return false;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Checks if the passed string represents an IPv4-address.
+
+  @param arg The string to check.
+
+  @return Check status.
+  @retval false The passed string does not represent an IPv4-address.
+  @retval true  The passed string represents an IPv4-address.
+*/
+
+bool Item_func_is_ipv4::calc_value(const String *arg)
+{
+  in_addr ipv4_address;
+
+  return str_to_ipv4(arg->ptr(), arg->length(), &ipv4_address);
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Checks if the passed string represents an IPv6-address.
+
+  @param arg The string to check.
+
+  @return Check status.
+  @retval false The passed string does not represent an IPv6-address.
+  @retval true  The passed string represents an IPv6-address.
+*/
+
+bool Item_func_is_ipv6::calc_value(const String *arg)
+{
+  in6_addr ipv6_address;
+
+  return str_to_ipv6(arg->ptr(), arg->length(), &ipv6_address);
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Checks if the passed IPv6-address is an IPv4-compat IPv6-address.
+
+  @param arg The IPv6-address to check.
+
+  @return Check status.
+  @retval false The passed IPv6-address is not an IPv4-compatible IPv6-address.
+  @retval true  The passed IPv6-address is an IPv4-compatible IPv6-address.
+*/
+
+bool Item_func_is_ipv4_compat::calc_value(const String *arg)
+{
+  if ((int) arg->length() != IN6_ADDR_SIZE || arg->charset() != &my_charset_bin)
+    return false;
+
+  return IN6_IS_ADDR_V4COMPAT((struct in6_addr *) arg->ptr());
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/**
+  Checks if the passed IPv6-address is an IPv4-mapped IPv6-address.
+
+  @param arg The IPv6-address to check.
+
+  @return Check status.
+  @retval false The passed IPv6-address is not an IPv4-mapped IPv6-address.
+  @retval true  The passed IPv6-address is an IPv4-mapped IPv6-address.
+*/
+
+bool Item_func_is_ipv4_mapped::calc_value(const String *arg)
+{
+  if ((int) arg->length() != IN6_ADDR_SIZE || arg->charset() != &my_charset_bin)
+    return false;
+
+  return IN6_IS_ADDR_V4MAPPED((struct in6_addr *) arg->ptr());
+}

=== modified file 'sql/item_inetfunc.h'
--- a/sql/item_inetfunc.h	2011-04-15 09:39:46 +0000
+++ b/sql/item_inetfunc.h	2011-05-03 13:03:00 +0000
@@ -71,4 +71,185 @@ public:
   }
 };
 
+
+/*************************************************************************
+  Item_func_inet_bool_base implements common code for INET6/IP-related
+  functions returning boolean value.
+*************************************************************************/
+
+class Item_func_inet_bool_base : public Item_bool_func
+{
+public:
+  inline Item_func_inet_bool_base(Item *ip_addr)
+    : Item_bool_func(ip_addr)
+  {
+    null_value= false;
+  }
+
+public:
+  virtual longlong val_int();
+
+protected:
+  virtual bool calc_value(const String *arg) = 0;
+};
+
+
+/*************************************************************************
+  Item_func_inet_bool_base implements common code for INET6/IP-related
+  functions returning string value.
+*************************************************************************/
+
+class Item_func_inet_str_base : public Item_str_ascii_func
+{
+public:
+  inline Item_func_inet_str_base(Item *arg)
+    : Item_str_ascii_func(arg)
+  { }
+
+public:
+  virtual String *val_str_ascii(String *buffer);
+
+protected:
+  virtual bool calc_value(String *arg, String *buffer) = 0;
+};
+
+
+/*************************************************************************
+  Item_func_inet6_aton implements INET6_ATON() SQL-function.
+*************************************************************************/
+
+class Item_func_inet6_aton : public Item_func_inet_str_base
+{
+public:
+  inline Item_func_inet6_aton(Item *ip_addr)
+    : Item_func_inet_str_base(ip_addr)
+  { }
+
+public:
+  virtual const char *func_name() const
+  { return "inet6_aton"; }
+
+  virtual void fix_length_and_dec()
+  {
+    decimals= 0;
+    fix_length_and_charset(16, &my_charset_bin);
+    maybe_null= 1;
+  }
+
+protected:
+  virtual bool calc_value(String *arg, String *buffer);
+};
+
+
+/*************************************************************************
+  Item_func_inet6_ntoa implements INET6_NTOA() SQL-function.
+*************************************************************************/
+
+class Item_func_inet6_ntoa : public Item_func_inet_str_base
+{
+public:
+  inline Item_func_inet6_ntoa(Item *ip_addr)
+    : Item_func_inet_str_base(ip_addr)
+  { }
+
+public:
+  virtual const char *func_name() const
+  { return "inet6_ntoa"; }
+
+  virtual void fix_length_and_dec()
+  {
+    decimals= 0;
+
+    // max length: IPv6-address -- 16 bytes
+    // 16 bytes / 2 bytes per group == 8 groups => 7 delimiter
+    // 4 symbols per group
+    fix_length_and_charset(8 * 4 + 7, default_charset());
+
+    maybe_null= 1;
+  }
+
+protected:
+  virtual bool calc_value(String *arg, String *buffer);
+};
+
+
+/*************************************************************************
+  Item_func_is_ipv4 implements IS_IPV4() SQL-function.
+*************************************************************************/
+
+class Item_func_is_ipv4 : public Item_func_inet_bool_base
+{
+public:
+  inline Item_func_is_ipv4(Item *ip_addr)
+    : Item_func_inet_bool_base(ip_addr)
+  { }
+
+public:
+  virtual const char *func_name() const
+  { return "is_ipv4"; }
+
+protected:
+  virtual bool calc_value(const String *arg);
+};
+
+
+/*************************************************************************
+  Item_func_is_ipv6 implements IS_IPV6() SQL-function.
+*************************************************************************/
+
+class Item_func_is_ipv6 : public Item_func_inet_bool_base
+{
+public:
+  inline Item_func_is_ipv6(Item *ip_addr)
+    : Item_func_inet_bool_base(ip_addr)
+  { }
+
+public:
+  virtual const char *func_name() const
+  { return "is_ipv6"; }
+
+protected:
+  virtual bool calc_value(const String *arg);
+};
+
+
+/*************************************************************************
+  Item_func_is_ipv4_compat implements IS_IPV4_COMPAT() SQL-function.
+*************************************************************************/
+
+class Item_func_is_ipv4_compat : public Item_func_inet_bool_base
+{
+public:
+  inline Item_func_is_ipv4_compat(Item *ip_addr)
+    : Item_func_inet_bool_base(ip_addr)
+  { }
+
+public:
+  virtual const char *func_name() const
+  { return "is_ipv4_compat"; }
+
+protected:
+  virtual bool calc_value(const String *arg);
+};
+
+
+/*************************************************************************
+  Item_func_is_ipv4_mapped implements IS_IPV4_MAPPED() SQL-function.
+*************************************************************************/
+
+class Item_func_is_ipv4_mapped : public Item_func_inet_bool_base
+{
+public:
+  inline Item_func_is_ipv4_mapped(Item *ip_addr)
+    : Item_func_inet_bool_base(ip_addr)
+  { }
+
+public:
+  virtual const char *func_name() const
+  { return "is_ipv4_mapped"; }
+
+protected:
+  virtual bool calc_value(const String *arg);
+};
+
 #endif // ITEM_INETFUNC_INCLUDED

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (alexander.nozdrin:3358 to 3360) WL#5787Alexander Nozdrin3 May