Bug #61750 lookup() and reverse_lookup() are not IPv6 capable
Submitted: 5 Jul 2011 13:31 Modified: 17 Jul 2011 9:32
Reporter: Daniël van Eeden Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: User-defined functions ( UDF ) Severity:S4 (Feature request)
Version:5.6.3-m5 OS:Any
Assigned to: CPU Architecture:Any

[5 Jul 2011 13:31] Daniël van Eeden
Description:
The lookup() and reverse_lookup() UDF's from udf_example.so are not IPv6 capable. It would be nice to see IPv6 support added to these.

How to repeat:
mysql> SELECT reverse_lookup('::1');
+-----------------------+
| reverse_lookup('::1') |
+-----------------------+
| NULL                  |
+-----------------------+
1 row in set (0.00 sec)

Suggested fix:
Add ipv6 support to these functions or add new functions like lookup6()
[5 Jul 2011 13:43] Daniël van Eeden
mysql> SELECT lookup('localhost6');
+----------------------+
| lookup('localhost6') |
+----------------------+
| 127.0.0.1            |
+----------------------+
1 row in set (0.00 sec)

mysql> \! getent hosts localhost6
::1             desktop001 localhost6.localdomain6 localhost6
[17 Jul 2011 9:32] Valeriy Kravchuk
Surely they are not IPv6 capable, as they just ask for IPv4 hostname:

#if defined(HAVE_GETHOSTBYADDR_R) && defined(HAVE_SOLARIS_STYLE_GETHOST)
  if (!(hp=gethostbyaddr_r((char*) &taddr,sizeof(taddr), AF_INET,
                           &tmp_hostent, name_buff,sizeof(name_buff),
                           &tmp_errno)))
  {
    *null_value=1;
    return 0;
  }
#else
  pthread_mutex_lock(&LOCK_hostname);
  if (!(hp= gethostbyaddr((char*) &taddr, sizeof(taddr), AF_INET)))
  {
    pthread_mutex_unlock(&LOCK_hostname);
    *null_value= 1;
    return 0;
  }
  pthread_mutex_unlock(&LOCK_hostname);
#endif

We need separate functions to use AF_INET6 address type.