Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tcp: set hints for address resolution
getaddrinfo really likes to get hints on how to resolve. This should fix
the problem where 'localhost' can not be used as a hostname.

This should work with AF_UNSPEC but may need to be reverted to AF_INET.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
  • Loading branch information
oliv3r authored and perexg committed Sep 29, 2015
1 parent b260c8c commit e32dea8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tcp.c
Expand Up @@ -76,12 +76,14 @@ tcp_connect(const char *hostname, int port, const char *bindaddr,
char *errbuf, size_t errbufsize, int timeout)
{
int fd, r, res, err;
struct addrinfo *ai;
struct addrinfo *ai, hints;
char portstr[6];
socklen_t errlen = sizeof(err);

snprintf(portstr, 6, "%u", port);
res = getaddrinfo(hostname, portstr, NULL, &ai);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
res = getaddrinfo(hostname, portstr, &hints, &ai);

if (res != 0) {
snprintf(errbuf, errbufsize, "%s", gai_strerror(res));
Expand Down

0 comments on commit e32dea8

Please sign in to comment.