curl-library
Re: gethostbyname_r
Date: Sat, 15 Feb 2003 16:41:40 +0530
Hi All
This is in continuation of my previous mail.
I am giving the source code of my program that is giving me the segfault when
I give an invalid IP address to this program.
For the same invalid IP address "curl" rightly says that it couldn't resolve
the host.
If anybody has any clue why it is failing please let me know.
My observations
-------------------
1. if run the same program with catchsegv I don't get any segfault.
2. I went through the source code in hostip.c. I wrote a test program
using gethostbynagme_r(). hostip.c assumes that if gethostbynagme_r()
returns 0, there must be a hostent in the buffer passed to it.
But that is not the case. I am also attaching a program to test
gethostbyname_r()
If the problem is only with gethostbynagme_r() "curl" command also should not
work. But it is working fine.
I am running my program like this
./tx ftp://192.168.128.45:/abcd /home/kilaru/abcd admin:123456
hostname passed to gethostbynagme_r() is "192.168.128.45:". For this
argument gethostbynagme_r() returns 0, h_errnop = 1 h = NULL
I am running curl like this
./curl -T /home/kilaru/text --url ftp://192.168.128.45:/abcd
-u admin:123456
hostname passed to gethostbynagme_r() is same as above.
gethostbynagme_r() returns 2, h_errnop = 1 h = NULL
Hope that that info helps.
Thank you
Bye
Kilaru
/* TEST PROGRAM TO use libcurl
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <unistd.h>
char errBuf[CURL_ERROR_SIZE];
#define FTP_MODE_PASV 1
#define FTP_MODE_PORT 2
int main(int argc, char **argv)
{
CURL *curlHandle; // curl handler
FILE *rPtr;
int code;
char user_pass[1024];
char *filePtr = argv[2];
char uri[1024];
int pasv = FTP_MODE_PASV;
if(argc<4)
{
printf("Usage:%s uri file_name user:pass\n", argv[0]);;
exit(-1);
}
strcpy( user_pass, argv[3]);
strcpy(uri, argv[1]);
if((code = curl_global_init(CURL_GLOBAL_ALL)) != CURLE_OK)
{
goto error;
}
curlHandle = curl_easy_init();
if(curlHandle == NULL)
{
printf("curlHandle = NULL\n");
goto error ;
}
if((code = curl_easy_setopt(curlHandle , CURLOPT_ERRORBUFFER , errBuf))
!= CURLE_OK)
{
goto error;
}
if((code = curl_easy_setopt(curlHandle , CURLOPT_URL , uri)) != CURLE_OK)
{
goto error;
}
if((code = curl_easy_setopt(curlHandle , CURLOPT_USERPWD , user_pass))
!= CURLE_OK)
{
goto error;
}
if((code = curl_easy_setopt(curlHandle , CURLOPT_FAILONERROR, 1)) !=
CURLE_OK)
{
goto error;
}
if (pasv == FTP_MODE_PORT)
/* PROGRAM TO TEST gethostbyname_r()
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
void print_hostent(struct hostent *h)
{
printf("h_name = %s\n", h->h_name);
return;
}
int main(int argc, char **argv)
{
int ret;
int my_err;
char buf[4096];
struct hostent host_ent, *h;
if(argc <= 1)
{
printf("usage: %s host_name\n", argv[0]);
exit(-1);
}
ret = gethostbyname_r( argv[1], &host_ent, buf, 4096, &h, &my_err);
printf("ret = %p &host_ent = %p buf = %p my_err = %d host = %s h = %p\n",
(void *)ret, &host_ent, buf, my_err, argv[1], h);
if(h)
{
print_hostent( h );
}
return 0;
}
On Saturday 15 February 2003 10:51 am, kilaru wrote:
> Hi all
>
> I am using redhat 7.2 with 2.4.12 kernel.
> My curl is 7-9-8.
>
> My application is giving seg fault when I give ill-formatted IP address.
> Ex: "192.168.128.45:" -- ':' is also given to curl library along with the
> valid IP address.
>
> I saw in debugger that gethostbyname_r() was returning 0 for that IP
> address where it should have returned some error.
>
> Does anybody have any clue abt this? Has anybody faced this?
>
> I checked in the archives and found couple of mails abt some problem with
> gethostbyname_r() in RedHat 8.
>
> I also found that somebody has posted some patch for that problem with
> gethostbyname_r().
>
> Where do I get that patch?
>
> Thank you
>
> bye
> KIlaru
-- \\\|/// \|||/ (o o) ---------------------o0o--(_)--o0o------------------------------- ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sfReceived on 2003-02-15