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?


- 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
	rmode = VIDEO_GetPreferredMode(NULL);
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

	// 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) {
		u32 pressed = WPAD_ButtonsDown(0);
		if ( pressed & WPAD_BUTTON_HOME ) {
	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);

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