Date: Sat, 15 Feb 2003 16:41:40 +0530
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
If anybody has any clue why it is failing please let me know.
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
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
hostname passed to gethostbynagme_r() is same as above.
gethostbynagme_r() returns 2, h_errnop = 1 h = NULL
Hope that that info helps.
/* TEST PROGRAM TO use libcurl
#define FTP_MODE_PASV 1
#define FTP_MODE_PORT 2
int main(int argc, char **argv)
CURL *curlHandle; // curl handler
char *filePtr = argv;
int pasv = FTP_MODE_PASV;
printf("Usage:%s uri file_name user:pass\n", argv);;
strcpy( user_pass, argv);
if((code = curl_global_init(CURL_GLOBAL_ALL)) != CURLE_OK)
curlHandle = curl_easy_init();
if(curlHandle == NULL)
printf("curlHandle = NULL\n");
goto error ;
if((code = curl_easy_setopt(curlHandle , CURLOPT_ERRORBUFFER , errBuf))
if((code = curl_easy_setopt(curlHandle , CURLOPT_URL , uri)) != CURLE_OK)
if((code = curl_easy_setopt(curlHandle , CURLOPT_USERPWD , user_pass))
if((code = curl_easy_setopt(curlHandle , CURLOPT_FAILONERROR, 1)) !=
if (pasv == FTP_MODE_PORT)
/* PROGRAM TO TEST gethostbyname_r()
void print_hostent(struct hostent *h)
printf("h_name = %s\n", h->h_name);
int main(int argc, char **argv)
struct hostent host_ent, *h;
if(argc <= 1)
printf("usage: %s host_name\n", argv);
ret = gethostbyname_r( argv, &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, h);
print_hostent( h );
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
> Where do I get that patch?
> Thank you
-- \\\|/// \|||/ (o o) ---------------------o0o--(_)--o0o------------------------------- ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sfReceived on 2003-02-15