getaddrinfo : Non-recoverable failure in name resolution

Marco Atzeri marco.atzeri@gmail.com
Mon Jun 23 11:42:00 GMT 2014


Hi,
the attached two test programs should perform exactly the same call
to getaddrinfo for 127.0.0.1

however on 32 bit
CYGWIN_NT-6.1-WOW64 1.7.30(0.272/5/3) 2014-05-23 10:36 i686 Cygwin

  32 $ ./getaddrinfo_test-1_32
127.0.0.1 ai_addr
02 00 00 00 7f 00 00 01 00 00 00 00 00 00 00 00

  32 $ ./getaddrinfo_test-2_32
127.0.0.1 ai_addr
02 00 00 00 7f 00 00 01 00 00 00 00 00 00 00 00

while on 64 bit
CYGWIN_NT-6.1 1.7.30(0.272/5/3) 2014-05-23 10:36 x86_64 Cygwin

64 $ ./getaddrinfo_test-1_64
127.0.0.1 ai_addr
02 00 00 00 7f 00 00 01 00 00 00 00 00 00 00 00

64 $ ./getaddrinfo_test-2_64
getaddrinfo: Non-recoverable failure in name resolution


Am I missing something ?
The second way is currently used on postgresql in several places,
but it seems to fail only for "127.0.0.1"

Regards
Marco
-------------- next part --------------

#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int rc,i,l;
const char *hostname="127.0.0.1";
const char *servname="";
struct addrinfo *hintp;
/* struct addrinfo *resultp; */
struct addrinfo **result;

char *addr;

hintp=calloc(1,sizeof(struct addrinfo ));
/*
resultp=calloc(1,sizeof(struct addrinfo ));
result=&resultp;
*/
hintp->ai_flags = 4;
hintp->ai_family = 0;
hintp->ai_socktype = 0;
hintp->ai_protocol = 0;
hintp->ai_addrlen = 0;
hintp->ai_canonname = 0x0;
hintp->ai_addr = 0x0;
hintp->ai_next = 0x0;

rc = getaddrinfo(hostname, servname, hintp, result);

if (!rc)
	{ 
	printf("127.0.0.1 ai_addr\n");
	l=(*result)->ai_addrlen;
	addr=(char*)(*result)->ai_addr;
	for(i=0;i<l;i++)
		printf("%2.2x ",addr[i]);
	printf("\n");
	}
else
	{
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rc));
        exit(EXIT_FAILURE);
	}
}

-------------- next part --------------

#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int rc,i,l;
const char *hostname="127.0.0.1";
const char *servname="";
struct addrinfo hintp;
/* struct addrinfo *resultp; */
struct addrinfo *result=NULL;

char *addr;

/*
hintp=calloc(1,sizeof(struct addrinfo ));
resultp=calloc(1,sizeof(struct addrinfo ));
result=&resultp;
*/

hintp.ai_flags = 4;
hintp.ai_family = 0;
hintp.ai_socktype = 0;
hintp.ai_protocol = 0;
hintp.ai_addrlen = 0;
hintp.ai_canonname = 0x0;
hintp.ai_addr = 0x0;
hintp.ai_next = 0x0;

rc = getaddrinfo(hostname, servname, &hintp, &result);

if (!rc)
	{ 
	printf("127.0.0.1 ai_addr\n");
	l=result->ai_addrlen;
	addr=(char*)result->ai_addr;
	for(i=0;i<l;i++)
		printf("%2.2x ",addr[i]);
	printf("\n");
	}
else
	{
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rc));
        exit(EXIT_FAILURE);
	}
}


-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list