Game Development Community

Local IP Address on iPhone

by Dave Young · in iTorque 2D · 04/01/2009 (12:07 pm) · 0 replies

I put together some code which works to get the local IP address.
Since I'm having such trouble broadcasting WiFi games, at least this will allow direct connects:

ConsoleFunction(getDeviceIPAddress, const char*, 1, 1, "")
{
	NSHost *currentHost = [NSHost currentHost]; 
	NSString *ip = [[currentHost addresses] objectAtIndex:1]; 
	
	const char *strUniqueID = [ip UTF8String ];
	
	//return address;
	char* ret = Con::getReturnBuffer( 1024 );
	dSprintf(ret, 1024, strUniqueID);
	return ret;
}