[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
incorrect return value for gethostbyname_r
From: |
R Sreelatha |
Subject: |
incorrect return value for gethostbyname_r |
Date: |
Tue, 12 Feb 2002 19:16:30 +0530 |
Hello,
I find that the return value of gethostbyname_r is set correctly.
Steps to reproduce:
1. Write a testcase using gethostbyname_r().
2. Execute the testcase with non-existing IP Address (For ex, 1.2.3.4.5)
Actual results: Return value is zero.
Expected results: Return value should be non-zero, as the function fails
with HOST_NOT_FOUND error in *h_errnop.
By debugging using gdb, I found that at line 226 of file /nss/getXXbyYY_r.c
in glibc-2.2.4:
"return status == NSS_STATUS_SUCCESS ? 0 : errno;"
the status is not set to NSS_STATUS_SUCCESS, but the errno is 0. Hence
gethostbyname_r returns 0.
Since we are passing an invalid ipaddress 1.2.3.4.5, I would expect
gethostbyname_r to return a non-zero value as given in man pages. Is this a
bug in glibc?
Here is a small testcase to illustrate this.
/*_____________________________________________________________*/
struct hostent * getname(char *host);
int main(int argc, char* argv[]) {
char *phost;
if(argc<2)
{
printf("Use: %s <host>\n",argv[0]);
exit(0);
}
phost=argv[1];
getname (phost);
}
struct hostent * getname (char *host)
{
struct hostent hostbuf, *hp;
size_t hstbuflen;
char *tmphstbuf;
int res;
int herr;
hstbuflen = 1024;
tmphstbuf = (char *) malloc (hstbuflen);
while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen,
&hp, &herr)) == ERANGE)
{
/* Enlarge the buffer. */
hstbuflen *= 2;
tmphstbuf = (char *) realloc (tmphstbuf, hstbuflen);
}
/* Check for errors. */
printf("The return value is %d\n",res);
if (res || hp == NULL)
{
printf("gethostbyname error for host: %d : %s
\n",herr,hstrerror(herr));
return NULL;
}
free(tmphstbuf);
return hp;
}
/*______________________________________________________________*/
regards,
Sreelatha
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- incorrect return value for gethostbyname_r,
R Sreelatha <=