Hi there, hopefully I have the right subreddit ! I store a lot of IP addresses, netmasks, subnet info in a MySQL database. For IPv4, it was all done using the standard inet_aton() functions and I would do bitwise calculations (like subnet & netmask) to match addresses to subnets and such. With IPv4, the new data type is varbin(16) as opposed to just integer with IPv4. The inet6_aton() functions are used, but none of the bitwise calculators will work with inet6 functions. How do people now do bit math for IPv6??
For example, the IPv4 way:
`mysql> SELECT INET_NTOA(INET_ATON('255.255.255.0') & INET_ATON('192.168.2.3'));
+------------------------------------------------------------------+
| INET_NTOA(INET_ATON('255.255.255.0') & INET_ATON('192.168.2.3')) |
+------------------------------------------------------------------+
| 192.168.2.0 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)`
It wont' work with inet6 functions:
`mysql> SELECT INET6_NTOA(INET6_ATON('255.255.255.0') & INET6_ATON('192.168.2.3'));
+---------------------------------------------------------------------+
| INET6_NTOA(INET6_ATON('255.255.255.0') & INET6_ATON('192.168.2.3')) |
+---------------------------------------------------------------------+
| NULL |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)`
Surely, with all the products supporting IPv6 out there, there should be a solution. I've Googled and Googled with no luck.
Edit: Sorry my examples are in IPv4. Here's with IPv6 to show the same output:
mysql> SELECT INET6_NTOA(INET6_ATON('::ffff') & INET6_ATON('2001:43ce:beef::cake'));
+-----------------------------------------------------------------------+
| INET6_NTOA(INET6_ATON('::ffff') & INET6_ATON('2001:43ce:beef::cabe')) |
+-----------------------------------------------------------------------+
| NULL |
+-----------------------------------------------------------------------+