Home | Gaming | Programming | Play Online | Contact | Keyword Query
Games++ Games & Game Programming

GAMES++
Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

BROWSER UTILITIES
E-mail This Page
Add to Favorites

SITE SEARCH

Web Games++

AFFILIATES
Cheat Codes
Trickster Wiki
Game Ratings
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials

ADVERTISEMENT

ADVERTISEMENT

Setting Up TCP/IP

Xbox Programming & Development

TCP/IP on the XBOX is a bit tricky to set up, but other than that - it does work like a dream.

I know this is not a good way to do it, the other ways are by far better - but this will make you understand HOW it works.

Setting up STATIC ip

#include 

char szHost[32];
unsigned char params[512]; 


void GiveIPtoxbox( char *ip, char *gateway )
{

int index = 0x14; 
// 0x14 is the ip location in the parameter array
 

XNetLoadConfigParams(params);
// -- insert ip into params --


params[index] = ip[0];

index++;

params[index] = ip[1];


index++;

params[index] = ip[2];


index++;

params[index] = ip[3];


index++;

params[index] = gateway[0];

index++;

params[index] = gateway[1];


index++;

params[index] = gateway[2];


index++;

params[index] = gateway[3];

XNetSaveConfigParams(params);
}

OK, not rocket science, but can be a pain to locate how to do this. Now for the DHCP method, since most people prefer that over static ip.

DHCP

char NETWORK_STATUS[1024];
char Network_mode=0;
XNetStartupParams sXNetStartup;
WSADATA sWSAData;
DWORD vReturn;
WORD vVersionRequested;
bool isGateway;
int vError;
XNADDR sAddress;
char NETWORK_STATUS[256];

DWORD SetUpNetwork( char *ip )
{
	int socketloop=1;
	// Start up NET
	memset(&sXNetStartup, 0, sizeof(sXNetStartup));
	sXNetStartup.cfgSizeOfStruct = sizeof(XNetStartupParams);
	sXNetStartup.cfgFlags = XNET_STARTUP_BYPASS_SECURITY;
	vError = XNetStartup(&sXNetStartup);
	vVersionRequested = MAKEWORD( 2, 2 );

	if( WSAStartup( vVersionRequested, &sWSAData ) != 0 ) 
	{
		Return();
	}

	// If we didn't get version 2.2, return!
	if ( LOBYTE( sWSAData.wVersion ) != 2 || HIBYTE( sWSAData.wVersion ) != 2 ) 
	{
		WSACleanup( );
		Return();
	}

	while( socketloop )
	{
		//Setting up network
		strcat(NETWORK_STATUS, "Setting up network\r\n");
		isGateway = false;
		vReturn = XNetGetTitleXnAddr(&sAddress);

		if( vReturn && XNET_GET_XNADDR_GATEWAY ) 
		{
			isGateway = true;
			vReturn ^= XNET_GET_XNADDR_GATEWAY;
			//Gateway Present
		} 

		socketloop = 1;

		switch( vReturn ) 
		{
		case XNET_GET_XNADDR_DHCP:
		{
			strcat(NETWORK_STATUS,"XNET_GET_XNADDR_DHCP\r\n");
		} break;
		case XNET_GET_XNADDR_DNS: 
		{
			strcat(NETWORK_STATUS,"XNET_GET_XNADDR_DNS\r\n");
		} break;
		case XNET_GET_XNADDR_ETHERNET: 
		{
			strcat(NETWORK_STATUS,"XNET_GET_XNADDR_ETHERNET\r\n");
		} break;
		case XNET_GET_XNADDR_NONE: 
		{
			strcat(NETWORK_STATUS,"XNET_GET_XNADDR_NONE\r\n");
		} break;
		case XNET_GET_XNADDR_ONLINE: 
		{
			strcat(NETWORK_STATUS,"XNET_GET_XNADDR_ONLINE\r\n");
		} break;
		case XNET_GET_XNADDR_PENDING: 
		{
			strcat(NETWORK_STATUS,"XNET_GET_XNADDR_PENDING\r\n");
		} break;
		case XNET_GET_XNADDR_STATIC:
		{
			strcat(NETWORK_STATUS,"XNET_GET_XNADDR_STATIC\r\n");
		} break;
		default : 
		{
			strcat(NETWORK_STATUS,"Unknown Return Code\r\n");
		} break;
		} 

		if( vReturn != XNET_GET_XNADDR_NONE ) 
		{
			char azIPAdd[256];
			//char azMessage[256];

			memset(azIPAdd,0,sizeof(azIPAdd));

			XNetInAddrToString(sAddress.ina,azIPAdd,sizeof(azIPAdd));
			strcpy(NETWORK_STATUS,azIPAdd);

			if( !strstr(azIPAdd,"0.0.0.0"))
			socketloop = 0;
		}

		Sleep(50); 
	}

	Network_mode = 1;
	return 0;
}

If you don't understand why I programmed this loop the way I did - it is because I threaded it so I could go on with my program while this thing figured out all the ip stuff - since it DOES take a few seconds extra of the init-time. Look in the threading part for how to call this up as a thread.

Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy