Sean Boudreau(deleted)
|
Re: gethostbyname_r fails after connected
|
Sean Boudreau(deleted)
10/27/2011 11:34 AM
post89689
|
Re: gethostbyname_r fails after connected
This has been fixed.
Regards,
-seanb
On Wed, Oct 26, 2011 at 10:25:48AM -0400, Andy Naegle wrote:
> I have created a program that repeatedly calls gethostbyname_r. In the case where I connect the target to the
internet then run the program, as expected it prints the IP address. Also, if I start the program while disconnected to
the internet, as expected no IP address is received. However, if I start the program while disconnected to the
internet, then while the program is running establish a connection to the internet, gethostbyname_r continues to fail
even though it's connected to the internet. At this point, if I terminate the program restart it, gethostbyname_r will
resolve the name.
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post89647
> #include <netdb.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <arpa/inet.h>
>
> int main(int argc, char **argv) {
>
> if (argc < 2) {
> fprintf(stderr, "Usage: %s hostname\n", argv[0]);
> exit(1);
> }
>
> struct hostent *host = malloc(sizeof(struct hostent));
> char buffer[1024];
> int error;
>
> while(1) {
> if (gethostbyname_r(argv[1],host,buffer,sizeof(buffer),&error) != NULL) {
> int i=0;
> printf("%s IPs: \n", host->h_name);
>
> while (host->h_addr_list[i] != NULL) {
> printf("%s \n", inet_ntoa(*(struct in_addr*)(host->h_addr_list[i])));
> i++;
> }
> } else {
> printf("gethostbyname_r returned null\n");
> }
> }
> }
|
|
|