You are not logged in.
The source of this question is my attempt to get mpc to contact mpd on my localhost when the internet is down. When the internet is up it works fine, but when i'm not connected to the internet, running mpc behaves as follows:
I seem to have tracked this down to a problem in getaddrinfo (possibly in my sytem configuration?). I created a piece of test code (below) that does a gethostbyname and then a getaddrinfo. On this computer, both work when connected to the internet, but getaddrinfo fails when disconnected. I tested the same code on an ubuntu computer and it getaddrinfo worked even when disconnected from the internet.
My /etc/hosts and /etc/host.conf seem to be set properly. glibc is 2.8-3. I would have thought that getaddrinfo having such a problem would cause more errors than just in mpc, but I haven't noticed any.
I'd really appreciate any help.
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int main (void)
{
struct addrinfo *addrinfo;
int i, error;
struct hostent *h;
h = gethostbyname("localhost");
if (h) {
for (i=0; i < h->h_length - 1; i++)
printf("%d.", h->h_addr_list[0][i]);
printf("%d\n", h->h_addr_list[0][i]);
} else {
printf("no such host\n");
}
error = getaddrinfo("localhost", NULL, NULL, &addrinfo);
if (error) {
printf("host not found: %s\n", gai_strerror(error));
} else {
while (addrinfo) {
printf("%d %d %d\n",AF_INET,AF_INET6,addrinfo->ai_family);
addrinfo = addrinfo->ai_next;
}
}
return 0;
}
$ ./hnt
127.0.0.1
2 10 2
2 10 2
2 10 2
$ sudo dhcpcd -k wlan0
$ ./hnt
127.0.0.1
host not found: Temporary failure in name resolution
$ mpc
MPD_HOST and/or MPD_PORT environment variables are not set
error: host "localhost" not found: Temporary failure in name resolution
$
Uncommented and nonblank lines of /etc/hosts:
127.0.0.1 localhost.localdomain localhost heroine
and /etc/host.conf:
order hosts,bind
multi on
Offline
Welcome to the forums mlmeola.
I had the same problem with MPC even with the network fully operational. I ended up setting the MPD_HOST variable in ~/.bashrc.
Offline
Alas, setting MPD_HOST does not help. If there is some way to give mpc an ip address instead of a hostname, that might help. Just putting 127.0.0.1 as MPD_HOST doesn't work.
I also really think there is something really weird going on with getaddrinfo.
Thanks for the idea.
$ MPD_HOST=localhost mpc
MPD_HOST and/or MPD_PORT environment variables are not set
error: host "localhost" not found: Temporary failure in name resolution
$ MPD_HOST=127.0.0.1 mpc
MPD_HOST and/or MPD_PORT environment variables are not set
error: host "127.0.0.1" not found: Address family for hostname not supported
$
Offline
I see the same behavior as OP, but I think I've tracked it down a bit further.
MPC only refuses to connect when I have wicd running, althought it would be interesting to see if the mpc code is using getaddr / gethostname.
Offline