示例#1
0
// Xbox version supports the force option, so we can prime the
// system and hopefully be getting an IP while Com_Init() is running.
void NET_GetLocalAddress( bool force )
{
    XNADDR xnMyAddr;
    DWORD dwStatus;
    do
    {
        // Repeat while pending; OK to do other work in this loop
        dwStatus = XNetGetTitleXnAddr( &xnMyAddr );
    } while( dwStatus == XNET_GET_XNADDR_PENDING && force );

    // Error checking
    if( dwStatus == XNET_GET_XNADDR_NONE )
    {
        // If this wasn't the final (necessary) call, then don't worry
        if( force )
            assert(!"Error getting XBox title address.");
        return;
    }

    *(u_long*)&localIP[0] = xnMyAddr.ina.S_un.S_addr;
    *(u_long*)localIP[1] = 0;
    *(u_long*)localIP[2] = 0;
    *(u_long*)localIP[3] = 0;

    Com_Printf( "IP: %i.%i.%i.%i\n", localIP[0], localIP[1], localIP[2], localIP[3] );
}
示例#2
0
struct hostent* smb_gethostbyname(const char* _name)
{
  WSAEVENT hEvent = NULL;
  XNDNS* pDns = NULL;
  INT err;

	HostEnt* server = (HostEnt*)malloc(sizeof(HostEnt));

	gethostname(server->name, 128);
	if(!strcmp(server->name, _name))
	{
		XNADDR xna;
		DWORD dwState;
		do
		{
			dwState = XNetGetTitleXnAddr(&xna);
		} while (dwState==XNET_GET_XNADDR_PENDING);

		server->addr_list[0] = server->addr;
		memcpy(server->addr, &(xna.ina.s_addr), 4);
		server->server.h_name = server->name;
		server->server.h_aliases = 0;
		server->server.h_addrtype = AF_INET;
		server->server.h_length = 4;
		server->server.h_addr_list = (char**)malloc(sizeof(char*)*4);
		server->server.h_addr_list[0] = server->addr_list[0];
		server->server.h_addr_list[1] = 0;
		return (struct hostent*)server;
	}

	hEvent = WSACreateEvent();
	err = XNetDnsLookup(_name, hEvent, &pDns);
	WaitForSingleObject(hEvent, INFINITE);
	if( pDns && pDns->iStatus == 0 )
	{
		strcpy(server->name, _name);
		server->addr_list[0] = server->addr;
		memcpy(server->addr, &(pDns->aina[0].s_addr), 4);
		server->server.h_name = server->name;
		server->server.h_aliases = 0;
		server->server.h_addrtype = AF_INET;
		server->server.h_length = 4;
		server->server.h_addr_list = (char**)malloc(sizeof(char*)*4);

		server->server.h_addr_list[0] = server->addr_list[0];
		server->server.h_addr_list[1] = 0;
		XNetDnsRelease(pDns);
    WSACloseEvent(hEvent);
		return (struct hostent*)server;
	}
	if( pDns )
		XNetDnsRelease(pDns);

  if( hEvent )
    WSACloseEvent(hEvent);

  free(server);
	return NULL;
}
示例#3
0
  PyObject* XBMC_GetIPAddress(PyObject *self, PyObject *args)
  {
    char cTitleIP[32];
#ifdef HAS_XBOX_NETWORK
    XNADDR xna;
    XNetGetTitleXnAddr(&xna);
    XNetInAddrToString(xna.ina, cTitleIP, 32);
#else
    sprintf(cTitleIP, "127.0.0.1");
#endif
    return PyString_FromString(cTitleIP);
  }
示例#4
0
/*-------------------------------------------------------------------------*\
* Initializes module 
\*-------------------------------------------------------------------------*/
int socket_open(void) {
	WSADATA wsaData;
	WORD wVersionRequested = MAKEWORD(2, 0); 
	int err = 0;
	#ifdef _XBOX
		XNetStartupParams xnsp;
		XNADDR          g_xnaddr;                      // our own XNADDR
		DWORD dwRet;

		memset(&xnsp, 0, sizeof(xnsp));
		xnsp.cfgSizeOfStruct = sizeof(XNetStartupParams);
		xnsp.cfgFlags = XNET_STARTUP_BYPASS_SECURITY;
		err = XNetStartup(&xnsp);
		if (err == 0)
		{
			OutputDebugStringA("PE: PROGRESS: XNetStartupParams Succeeded\n");
		}
		else
		{
			OutputDebugStringA("PE: ERROR: XNetStartupParams Failed\n");
		}

		do
		{
			dwRet = XNetGetTitleXnAddr( &g_xnaddr );
		} while( dwRet == XNET_GET_XNADDR_PENDING );

		OutputDebugStringA("Machine IP Address is :");

		printf( " XNADDR: %02X:%02X:%02X:%02X:%02X:%02X\n",
			g_xnaddr.abEnet[0], g_xnaddr.abEnet[1], g_xnaddr.abEnet[2],
			g_xnaddr.abEnet[3], g_xnaddr.abEnet[4], g_xnaddr.abEnet[5] );
		
		do
		{
			dwRet = XNetGetDebugXnAddr( &g_xnaddr );
		} while( dwRet == XNET_GET_XNADDR_PENDING );

		printf( " Debug XNADDR: %02X:%02X:%02X:%02X:%02X:%02X\n",
			g_xnaddr.abEnet[0], g_xnaddr.abEnet[1], g_xnaddr.abEnet[2],
			g_xnaddr.abEnet[3], g_xnaddr.abEnet[4], g_xnaddr.abEnet[5] );
		
	#endif

    err = WSAStartup(wVersionRequested, &wsaData );
    if (err != 0) return 0;
    if ((LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) &&
        (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)) {
        WSACleanup();
        return 0; 
    }
    return 1;
}
	bool GetXBoxAddr(XNADDR *pXnAddr)
	{
		DWORD dwRet;
		do
		{
			dwRet = XNetGetTitleXnAddr( pXnAddr );
		} while( dwRet == XNET_GET_XNADDR_PENDING );

		if( dwRet & XNET_GET_XNADDR_NONE )
		{
			LOG.Write("Failed to find the XNAddr");
			return false;
		}

		return true;
	}
示例#6
0
struct hostent* FAR smb_gethostbyaddr(const char* addr, int len, int type) {
	//OutputDebugString("TODO: gethostbyaddr\n");

	HostEnt* server = (HostEnt*)malloc(sizeof(HostEnt));

	XNADDR xna;
	DWORD dwState;
	do
	{
		dwState = XNetGetTitleXnAddr(&xna);
	} while (dwState==XNET_GET_XNADDR_PENDING);

	if (!memcmp(addr, &(xna.ina.s_addr), 4))
	{
		//get title hostent
		gethostname(server->name, 128);
		server->addr_list[0] = server->addr;
		memcpy(server->addr, &(xna.ina.s_addr), 4);
		server->server.h_name = server->name;
		server->server.h_aliases = 0;
		server->server.h_addrtype = AF_INET;
		server->server.h_length = 4;
		server->server.h_addr_list = (char**)malloc(sizeof(char*)*4);
		server->server.h_addr_list[0] = server->addr_list[0];
		server->server.h_addr_list[1] = 0;
		return (struct hostent*)server;
	}
	else
	{
		//get client hostent
		struct in_addr client = {{addr[0],addr[1],addr[2],addr[3]}};

		strcpy(server->name, smb_inet_ntoa(client));
		server->addr_list[0] = server->addr;
		memcpy(server->addr, addr, 4);
		server->server.h_name = server->name;
		server->server.h_aliases = 0;
		server->server.h_addrtype = AF_INET;
		server->server.h_length = 4;
		server->server.h_addr_list = (char**)malloc(sizeof(char*)*4);
		server->server.h_addr_list[0] = server->addr_list[0];
		server->server.h_addr_list[1] = 0;
		return (struct hostent*)server;
	}
	return 0;
}
示例#7
0
/*
=====================
NET_GetLocalAddress
=====================
*/
void NET_GetLocalAddress( void )
{
#ifndef _XBOX

	char				hostname[256];
	struct hostent		*hostInfo;
	int					error;
	char				*p;
	int					ip;
	int					n;

    // Set this early so we can just return if there is an error
	numIP = 0;

	if( gethostname( hostname, 256 ) == SOCKET_ERROR ) {
		error = WSAGetLastError();
		return;
	}

	hostInfo = gethostbyname( hostname );
	if( !hostInfo ) {
		error = WSAGetLastError();
		return;
	}

	Com_Printf( "Hostname: %s\n", hostInfo->h_name );
	n = 0;
	while( ( p = hostInfo->h_aliases[n++] ) != NULL ) {
		Com_Printf( "Alias: %s\n", p );
	}

	if ( hostInfo->h_addrtype != AF_INET ) {
		return;
	}

	while( ( p = hostInfo->h_addr_list[numIP] ) != NULL && numIP < MAX_IPS ) {
		ip = ntohl( *(int *)p );
		localIP[ numIP ][0] = p[0];
		localIP[ numIP ][1] = p[1];
		localIP[ numIP ][2] = p[2];
		localIP[ numIP ][3] = p[3];
		Com_Printf( "IP: %i.%i.%i.%i\n", ( ip >> 24 ) & 0xff, ( ip >> 16 ) & 0xff, ( ip >> 8 ) & 0xff, ip & 0xff );
		numIP++;
	}

#else
	XNADDR xnMyAddr;
	DWORD dwStatus;
	do
	{
	   // Repeat while pending; OK to do other work in this loop
	   dwStatus = XNetGetTitleXnAddr( &xnMyAddr );
	} while( dwStatus == XNET_GET_XNADDR_PENDING );

	// Error checking
	if( dwStatus == XNET_GET_XNADDR_NONE )
	{
		assert(!"Error getting XBox title address.");
		return;
	}

	*(u_long*)&localIP[0] = xnMyAddr.ina.S_un.S_addr;
	*(u_long*)localIP[1] = 0;
	*(u_long*)localIP[2] = 0;
	*(u_long*)localIP[3] = 0;

	Com_Printf( "IP: %i.%i.%i.%i\n", localIP[0], localIP[1], localIP[2], localIP[3] );

#endif
}
示例#8
0
//---------------------------------------------------------------------
//	InitializeNetwork
// 
// Thanks to XBoxMediaPlayer for this code!
//---------------------------------------------------------------------
BOOL InitializeNetwork( void )
{
  g_szTitleIPAddr[0] = 0;

  if (!IsEthernetConnected())
    return FALSE;

  // if local address is specified
  if ((!g_NetworkConfig.m_IPAddr.IsEmpty()) &&
      (!g_NetworkConfig.m_SubnetMask.IsEmpty()) &&
      (!g_NetworkConfig.m_Gateway.IsEmpty()))
  {
    // Thanks and credits to Team Evox for the description of the 
    // XNetConfigParams structure.

    TXNetConfigParams configParams;   

    PRINTMSG(( T_INFO, "Loading network configuration..." ));
    XNetLoadConfigParams( (LPBYTE) &configParams );
    PRINTMSG(( T_INFO, "Ready." ));

    BOOL bXboxVersion2 = (configParams.V2_Tag == 0x58425632 );	// "XBV2"
    BOOL bDirty = FALSE;

    PRINTMSG(( T_INFO, "User local address: %s", g_NetworkConfig.m_IPAddr.c_str() ));

    if (bXboxVersion2)
    {
      if (configParams.V2_IP != inet_addr(g_NetworkConfig.m_IPAddr.c_str()))
      {
        configParams.V2_IP = inet_addr(g_NetworkConfig.m_IPAddr.c_str());
        bDirty = TRUE;
      }
    }
    else
    {
      if (configParams.V1_IP != inet_addr(g_NetworkConfig.m_IPAddr.c_str()))
      {
        configParams.V1_IP = inet_addr(g_NetworkConfig.m_IPAddr.c_str());
        bDirty = TRUE;
      }
    }

    PRINTMSG(( T_INFO, "User subnet mask: %s", g_NetworkConfig.m_SubnetMask.c_str() ));

    if (bXboxVersion2)
    {
      if (configParams.V2_Subnetmask != inet_addr(g_NetworkConfig.m_SubnetMask.c_str()))
      {
        configParams.V2_Subnetmask = inet_addr(g_NetworkConfig.m_SubnetMask.c_str());
        bDirty = TRUE;
      }
    }
    else
    {
      if (configParams.V1_Subnetmask != inet_addr(g_NetworkConfig.m_SubnetMask.c_str()))
      {
        configParams.V1_Subnetmask = inet_addr(g_NetworkConfig.m_SubnetMask.c_str());
        bDirty = TRUE;
      }
    }

    PRINTMSG(( T_INFO, "User gateway address: %s", g_NetworkConfig.m_Gateway.c_str() ));

    if (bXboxVersion2)
    {
      if (configParams.V2_Defaultgateway != inet_addr(g_NetworkConfig.m_Gateway.c_str()))
      {
        configParams.V2_Defaultgateway = inet_addr(g_NetworkConfig.m_Gateway.c_str());
        bDirty = TRUE;
      }
    }
    else
    {
      if (configParams.V1_Defaultgateway != inet_addr(g_NetworkConfig.m_Gateway.c_str()))
      {
        configParams.V1_Defaultgateway = inet_addr(g_NetworkConfig.m_Gateway.c_str());
        bDirty = TRUE;
      }
    }

    if (configParams.Flag != (0x04|0x08) )
    {
      configParams.Flag = 0x04 | 0x08;
      bDirty = TRUE;
    }

    if (bDirty)
    {
      PRINTMSG(( T_INFO, "Updating network configuration..."));
      XNetSaveConfigParams( (LPBYTE) &configParams );
      PRINTMSG(( T_INFO, "Ready." ));
    }
  }

  XNetStartupParams xnsp;
  memset(&xnsp, 0, sizeof(xnsp));
  xnsp.cfgSizeOfStruct = sizeof(XNetStartupParams);

  // Bypass security so that we may connect to 'untrusted' hosts
  xnsp.cfgFlags = XNET_STARTUP_BYPASS_SECURITY;
  // create more memory for networking
  xnsp.cfgPrivatePoolSizeInPages = 64; // == 256kb, default = 12 (48kb)
  xnsp.cfgEnetReceiveQueueLength = 16; // == 32kb, default = 8 (16kb)
  xnsp.cfgIpFragMaxSimultaneous = 16; // default = 4
  xnsp.cfgIpFragMaxPacketDiv256 = 32; // == 8kb, default = 8 (2kb)
  xnsp.cfgSockMaxSockets = 64; // default = 64
  xnsp.cfgSockDefaultRecvBufsizeInK = 128; // default = 16
  xnsp.cfgSockDefaultSendBufsizeInK = 128; // default = 16
  INT err = XNetStartup(&xnsp);

  XNADDR xna;
  DWORD dwState;
  do
  {
    dwState = XNetGetTitleXnAddr(&xna);
    Sleep(50);
  } while (dwState==XNET_GET_XNADDR_PENDING);

  // Convert the addr to a string
  XNetInAddrToString(xna.ina, g_szTitleIPAddr.GetBuffer(32), 32);

  WSADATA WsaData;
  err = WSAStartup( MAKEWORD(2,2), &WsaData );
  
  return ( err == NO_ERROR );
}