예제 #1
0
static int if_up_with(int index)
{
   (void)index;
#ifdef __CELLOS_LV2__
   int timeout_count = 10;
   int state;
   int ret;

   ret = cellNetCtlInit();
   if (ret < 0)
   {
      printf("cellNetCtlInit() failed(%x)\n", ret);
      return -1;
   }

   for (;;)
   {
      ret = cellNetCtlGetState(&state);
      if (ret < 0)
      {
         printf("cellNetCtlGetState() failed(%x)\n", ret);
         return -1;
      }
      if (state == CELL_NET_CTL_STATE_IPObtained)
         break;

      sys_timer_usleep(500 * 1000);
      timeout_count--;
      if (index && timeout_count < 0)
      {
         printf("if_up_with(%d) timeout\n", index);
         return 0;
      }
   }
#elif defined(GEKKO)
   char t[16];
   if (if_config(t, NULL, NULL, TRUE) < 0)
   {
      return -1;
   }
#endif

   sock=socket(AF_INET, SOCK_DGRAM, 0);

   target.sin_family = AF_INET;
   target.sin_port = htons(PC_DEVELOPMENT_UDP_PORT);
#ifdef GEKKO
   target.sin_len = 8;
#endif

   inet_pton(AF_INET, PC_DEVELOPMENT_IP_ADDRESS, &target.sin_addr);

   return 0;
}
예제 #2
0
/**
 * network_init:
 *
 * Platform specific socket library initialization.
 *
 * Returns: true (1) if successful, otherwise false (0).
 **/
bool network_init(void)
{
#ifdef _WIN32
   WSADATA wsaData;
#endif
   static bool inited = false;
   if (inited)
      return true;

#if defined(_WIN32)
   if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
   {
      network_deinit();
      return false;
   }
#elif defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
   int timeout_count = 10;

   cellSysmoduleLoadModule(CELL_SYSMODULE_NET);
   sys_net_initialize_network();

   if (cellNetCtlInit() < 0)
      return false;

   for (;;)
   {
      int state;
      if (cellNetCtlGetState(&state) < 0)
         return false;

      if (state == CELL_NET_CTL_STATE_IPObtained)
         break;

      retro_sleep(500);
      timeout_count--;
      if (timeout_count < 0)
         return 0;
   }
#elif defined(VITA)
   SceNetInitParam initparam;

   if (sceNetShowNetstat() == SCE_NET_ERROR_ENOTINIT)
   {
      _net_compat_net_memory = malloc(COMPAT_NET_INIT_SIZE);

      initparam.memory       = _net_compat_net_memory;
      initparam.size         = COMPAT_NET_INIT_SIZE;
      initparam.flags        = 0;

      sceNetInit(&initparam);

      sceNetCtlInit();
   }

   retro_epoll_fd = sceNetEpollCreate("epoll", 0);
#elif defined(GEKKO)
   char t[16];
   if (if_config(t, NULL, NULL, TRUE, 10) < 0)
      return false;
#elif defined(WIIU)
   socket_lib_init();
#elif defined(_3DS)
    _net_compat_net_memory = (u32*)memalign(SOC_ALIGN, SOC_BUFFERSIZE);
	if (_net_compat_net_memory == NULL)
		return false;
	Result ret = socInit(_net_compat_net_memory, SOC_BUFFERSIZE);//WIFI init
	if (ret != 0)
		return false;
#else
   signal(SIGPIPE, SIG_IGN); /* Do not like SIGPIPE killing our app. */
#endif

   inited = true;
   return true;
}
예제 #3
0
static int network_interface_up(struct sockaddr_in *target, int index,
      const char *ip_address, unsigned udp_port, int *s)
{
   (void)index;

#if defined(VITA)
   if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT)
   {
      SceNetInitParam initparam;
      net_memory = malloc(NET_INIT_SIZE);

      initparam.memory = net_memory;
      initparam.size = NET_INIT_SIZE;
      initparam.flags = 0;

      sceNetInit(&initparam);
   }
   *s                 = sceNetSocket("RA_netlogger", PSP2_NET_AF_INET, PSP2_NET_SOCK_DGRAM, 0);
   target->sin_family = PSP2_NET_AF_INET;
   target->sin_port   = sceNetHtons(udp_port);

   sceNetInetPton(PSP2_NET_AF_INET, ip_address, &target->sin_addr);
#else

#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
   int ret = 0;

   int state, timeout_count = 10;
   ret = cellNetCtlInit();
   if (ret < 0)
      return -1;

   for (;;)
   {
      ret = cellNetCtlGetState(&state);
      if (ret < 0)
         return -1;

      if (state == CELL_NET_CTL_STATE_IPObtained)
         break;

      retro_sleep(500);
      timeout_count--;
      if (index && timeout_count < 0)
         return 0;
   }
#elif defined(GEKKO)
   char t[16];
   if (if_config(t, NULL, NULL, TRUE) < 0)
      ret = -1;
#endif
   if (ret < 0)
      return -1;

   *s                 = socket(AF_INET, SOCK_DGRAM, 0);

   target->sin_family = AF_INET;
   target->sin_port   = htons(udp_port);
#ifdef GEKKO
   target->sin_len    = 8;
#endif

   inet_pton(AF_INET, ip_address, &target->sin_addr);
#endif
   return 0;
}