Page 1 of 1

Issues with UDP packets

Posted: Wed Jun 06, 2012 3:24 am
by animus
Heya. I'm trying to get some DNS stuff ironed out on the wii (specifically, I'm trying to retrieve SRV records). However, I've had some issues, the most pressing of which appears to be libogc's issues with UDP. I'm only trying to do some simple communication; sending packets, really, but it hasn't worked.

I checked the subnet; the Wii automatically gets an address in the 192.168.1.1xx range, and my server's at 192.168.1.130. The server's not receiving any of the test packets sent by the Wii, and Wireshark isn't picking up any traffic from it, either. I've got the latest releases of devkitPPC and libogc.

For reference, the code I used (a modified mix of the socket test and some UDP code) is

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <network.h>
#include <debug.h>
#include <errno.h>
#include <wiiuse/wpad.h>

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

void *initialise();
void *httpd (void *arg);

static	lwp_t httd_handle = (lwp_t)NULL;

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

	char localip[16] = {0};
	char gateway[16] = {0};
	char netmask[16] = {0};
	
	xfb = initialise();

	printf ("\nlibogc network demo\n");
	printf("Configuring network ...\n");

	// Configure the network interface
	ret = if_config ( localip, netmask, gateway, TRUE);
	if (ret>=0) {
		printf ("network configured, ip: %s, gw: %s, mask %s\n", localip, gateway, netmask);

		LWP_CreateThread(	&httd_handle,	/* thread handle */ 
							httpd,			/* code */ 
							localip,		/* arg pointer for thread */
							NULL,			/* stack base */ 
							16*1024,		/* stack size */
							50				/* thread priority */ );
	} else {
		printf ("network configuration failed!\n");
	}

	while(1) {

		VIDEO_WaitVSync();
		WPAD_ScanPads();

		int buttonsDown = WPAD_ButtonsDown(0);

		if (buttonsDown & WPAD_BUTTON_HOME) {
			exit(0);
		}
	}

	return 0;
}

#define SRV_IP "192.168.1.130"
#define BUFLEN 512
#define NPACK 10
#define PORT 9930

//---------------------------------------------------------------------------------
void *httpd (void *arg) {
//---------------------------------------------------------------------------------

	s32 sock;
	struct sockaddr_in si_other;
	int  i, slen=sizeof(si_other);
	char buf[BUFLEN];

	sock = net_socket (AF_INET, SOCK_DGRAM, IPPROTO_IP);

	if (sock == INVALID_SOCKET) {
      		printf ("Cannot create a socket!\n");
    	} else {
		memset((char *) &si_other, 0, sizeof(si_other));
		si_other.sin_family = AF_INET;
		si_other.sin_port = htons(PORT);
		si_other.sin_len = 8;
		if ((si_other.sin_addr.s_addr = inet_addr(SRV_IP)) == 0) {
			fprintf(stderr, "inet_aton() failed\n");
		}else{
			for (i=0; i<NPACK; i++) {
				printf("Sending packet %d\n", i);
				sprintf(buf, "This is packet %d\n", i);
				int n;
				if((n = net_sendto(sock, buf, BUFLEN, 0, &si_other, 8)) < 0)
					printf("Failed. %d.",n);
			}
			net_close (sock);
		}
	}
	return NULL;
}

//---------------------------------------------------------------------------------
void *initialise() {
//---------------------------------------------------------------------------------

	void *framebuffer;

	VIDEO_Init();
	WPAD_Init();
	
	rmode = VIDEO_GetPreferredMode(NULL);
	framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	
	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(framebuffer);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

	return framebuffer;

}
Any help is appreciated.

Re: Issues with UDP packets

Posted: Tue Jun 12, 2012 1:24 pm
by bmeier
hi,
i faced a similiar scenario. took me a while to figure out the my firewall dropped the packets (don't know if Wireshark can track packets that are dropped by your fw).

if your server is on a linux machine try tcpdump to check.

Re: Issues with UDP packets

Posted: Tue Jun 12, 2012 4:40 pm
by the_leg
Your code ran as expected for me (including the garbage you're sending). I ran netcat on the linux side as the server, like this:

nc -u -vv -l -p 9930