Welcome! Log In Create A New Profile

Advanced

DNS Lookup

Posted by Myu0 
DNS Lookup
February 24, 2009 06:25PM
Hi Everyone,

A (hopefully) nice and easy question from me. I've been tinkering around with implementing a very basic Telnet client through the console, and it's starting to come together. Problem is, the DNS lookup is acting up, big-time, and I'm not sure if it's my code or if it's something in the OGC library. I'll give you a little sample program (which fails when I run it) and see what you make of it (the includes stripped of their brackets for printing sake). Anything needing done? Does the same happen with everyone?

Thanks!

- Myu0

// Simple little DNS lookup program - C

#include network.h
#include stdio.h

#include string.h
#include stdlib.h
#include unistd.h
#include gccore.h
#include wiiuse/wpad.h

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	// Standard console initialisation procedures
	VIDEO_Init();
	WPAD_Init();
	rmode = VIDEO_GetPreferredMode(NULL);
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
	printf("\x1b[2;0H");

	// The Actual Connection bit, effectively copied wholesale from WiiEarth source
	
	char *domain = "forum.wiibrew.org";			// The example domain to look up
        struct hostent *host = net_gethostbyname(domain);	// Retrieve the host information
        if(host == NULL) {					// Test for failure
		printf("Failed to retrieve domain %s\n", domain);
        }else {
        u32 *ip = (u32*)host->h_addr_list[0];			// creates a reference to the IP
	printf("Domain \"%s\"'s IP address: %u",domain,ip);	// Print the output
	}
	// Your standard "Wait until you press home to quit" loop
	while(1) {
		WPAD_ScanPads();
		u32 pressed = WPAD_ButtonsDown(0);
		if ( pressed & WPAD_BUTTON_HOME ) {
			exit(0);
		}
		VIDEO_WaitVSync();
	}
	return 0;
}



Edited 2 time(s). Last edit at 02/24/2009 06:30PM by Myu0.
Re: DNS Lookup
February 24, 2009 07:36PM
I believe before you do anything with the network you must set it up like so.

char            localip[16];
char            gateway[16];
char            netmask[16];

s32 ret = if_config ( localip, netmask, gateway, TRUE);
if (ret>=0) {
	printf ("network configured, ip: %s, gw: %s, mask %s\n", localip, gateway, netmask);
}else{
       printf("Fail");
}



Edited 1 time(s). Last edit at 02/24/2009 07:37PM by scanff.
Re: DNS Lookup
February 24, 2009 09:07PM
Now how did I miss that?

Thanks for the help! =D
Re: DNS Lookup
February 25, 2009 11:29AM
Just don't forget all the telnet protocol features while you are at it. Such as RFC 1097. The telnet protocol actually is a protocol, with some special codes that you need to support.
Sorry, only registered users may post in this forum.

Click here to login