gethostbyname fails always June 30, 2009 09:29PM | Registered: 14 years ago Posts: 7 |
RFD_RemoteOps* rfd_tcp_client_create(const char* p_host, int p_port) { s32 result = net_init(); while ( result == -EAGAIN ) { printf("."); usleep(100000); result = net_init(); } printf("\n"); if ( result < 0 ) { printf("net_init Failed with code %i.\n", result ); return NULL; } char localip[16]; char gateway[16]; char netmask[16]; s32 ifcfg = if_config ( localip, netmask, gateway, TRUE); if (ifcfg>=0) { printf ("network configured, ip: %s, gw: %s, mask %s\n", localip, gateway, netmask); } else { printf("if_config failed with code %i\n", ifcfg); return NULL; } struct hostent *he; printf("looking up host %s\n", p_host); if ( (he=net_gethostbyname(p_host)) == NULL) { // get the host info printf("gethostbyname failed!\n"); return NULL; } [...] }
Re: gethostbyname fails always July 01, 2009 12:34AM | Registered: 15 years ago Posts: 703 |
char* getipbyname(char *domain) { struct hostent *host = 0; host = net_gethostbyname(domain); if(host == NULL) return 0; struct sockaddr_in tmp; memcpy(&tmp.sin_addr,host->h_addr_list[0],host->h_length); return inet_ntoa(tmp.sin_addr); };
Re: gethostbyname fails always July 01, 2009 02:23AM | Registered: 14 years ago Posts: 7 |
Quote
scanff
Are you sure the "p_host" contains the correct value.
Quote
scanff
I've used this function before and it works great. Here's my code, you can see if it works for you.
Re: gethostbyname fails always July 01, 2009 02:30AM | Registered: 15 years ago Posts: 703 |
Pretty much the same as your code.Quote
what do you use to initialize the network?
Give me an example of what your passing it. gethostbyname takes a domain name not an IP, something like "www.yahoo.com"Quote
I'm printing it, it looks good. I also tried hardcoding the ip on the gethostbyname call, same result.
Re: gethostbyname fails always July 01, 2009 03:15AM | Registered: 15 years ago Posts: 152 |
Re: gethostbyname fails always July 01, 2009 03:20AM | Registered: 14 years ago Posts: 7 |
Re: gethostbyname fails always July 01, 2009 03:28AM | Registered: 15 years ago Posts: 703 |
Quote
puntoQuote
scanff
gethostbyname takes a domain name not an IP, something like "www.yahoo.com"
yeah, that's the bug actually. gethostbyname is supposed to take ips too (like "192.168.1.1")