Welcome! Log In Create A New Profile

Advanced

gethostbyname fails always

Posted by punto 
gethostbyname fails always
June 30, 2009 09:29PM
Hi.. I'm having some problems with some network code, I was wondering if I missed anything. I copied some network init code from examples and posts on this forum, but I'm not sure if I'm initializing correctly, because net_gethostbyname fails always, even when the lookup string is "192.168.1.1". Here's what I have:

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;
	}

	[...]
}

net_gethostbyname fails always, and when I print the results from if_config, 'localip' is fine, but the other two ('gateway' and 'netmask') look like garbage.

am I missing anything? is this stuff documented anywhere?

thanks



Edited 1 time(s). Last edit at 06/30/2009 09:30PM by punto.
Re: gethostbyname fails always
July 01, 2009 12:34AM
Are you sure the "p_host" contains the correct value. I've used this function before and it works great. Here's my code, you can see if it works for you.


	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
Quote
scanff
Are you sure the "p_host" contains the correct value.

I'm printing it, it looks good. I also tried hardcoding the ip on the gethostbyname call, same result.


Quote
scanff
I've used this function before and it works great. Here's my code, you can see if it works for you.

what do you use to initialize the network?
Re: gethostbyname fails always
July 01, 2009 02:30AM
Quote

what do you use to initialize the network?
Pretty much the same as your code.
Quote

I'm printing it, it looks good. I also tried hardcoding the ip on the gethostbyname call, same result.
Give me an example of what your passing it. gethostbyname takes a domain name not an IP, something like "www.yahoo.com"
Re: gethostbyname fails always
July 01, 2009 03:15AM
I think possibly my sample might help you. My project is pretty much dead in the water but at least that code should be a good example for how to use some of the libogc network functionality.
Re: gethostbyname fails always
July 01, 2009 03:20AM
Quote
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")
Re: gethostbyname fails always
July 01, 2009 03:28AM
Quote
punto
Quote
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")

I never knew that. I've always used a name. Maybe there is a bug in the network code.

Here's a link to the source code for net_gethostbyname. Maybe you can figure it out from there.

[devkitpro.svn.sourceforge.net]
Sorry, only registered users may post in this forum.

Click here to login