LibCouchbase on Windows: Hostname not working
I am using the current libcouchbase version from github.
The following code is used to connect to a Couchbase cluster:
libcouchbase_t instance; /* our libcouchbase instance */ libcouchbase_error_t oprc; /* for checking various responses */ const char *host = "127.0.0.1:8091"; const char *username = "bucket"; const char *passwd = "secret"; const char *bucket = "bucket"; instance = libcouchbase_create(host, username, passwd, bucket, NULL); if (instance == NULL) { fprintf(stderr, "Failed to create libcouchbase instance\n"); return 1; } (void)libcouchbase_set_error_callback(instance, error_callback); (void)libcouchbase_set_get_callback(instance, get_callback); if (libcouchbase_connect(instance) != LIBCOUCHBASE_SUCCESS) { fprintf(stderr, "Failed to connect libcouchbase instance to server\n"); return 1; } /* Wait for the connect to compelete */ libcouchbase_wait(instance);
This code works fine. But if I change the host to "localhost:8091", libcouchbase_wait calls the error_callback with the code LIBCOUCHBASE_CONNECT_ERROR.
It seems that libcouchbase cannot resolve the name "localhost" to the IP 127.0.0.1. The same error occurs when I the computername as host. Using the external IP will work again.
TL;DR: IP adresses as host are working, hostnames do not work
How do I use hostnames correctly with libcouchbase?
Greetings
DonCa
"localhost" looks up correctly (as "::1" IPv6 adress). Other hostnames are not working with libcouchbase (they are also looked up as IPv6 adresses).
I am using Windows 7 64-bit with IPv6 enabled. Therefore "localhost" resolves to "::1" (IPv6 address). To me it seems that LibCouchbase may have a problem with IPv6 adresses using a Windows OS. I altered the LibCouchbase code, so that it would lookup only IPv4 adresses and everything works just fine.
You may consider including a Windows IPv6 enabled systems in your test scenarios.
Yes, we'll definitely want to do this. Sorry for the trouble.
You can track this issue here: http://www.couchbase.com/issues/browse/CCBC-93
Thanks for letting us know. If you have any thoughts on where the issue is, please let us know.
Have you verified that you have a server listening on IPv6 on localhost?
Does 'localhost' look up correctly in other applications? Does libcouchbase work with other hostname lookups? I do remember that Windows Vista had an issue where localhost would end up going to DNS lookup-- I don't know if that has been resolved or which version of Windows you're using.
For example:
http://yacoding.blogspot.com/2008/07/localhost-redirecting-to.html
We can certainly look at this, but it would be good to rule out lookup issues first.