void console_init() { SceNetInitParam initparam; if (console_initialzed) { return; } console_mtx = sceKernelCreateMutex("console_mutex", 0, 0, NULL); if (sceSysmoduleIsLoaded(SCE_SYSMODULE_NET) != SCE_SYSMODULE_LOADED) sceSysmoduleLoadModule(SCE_SYSMODULE_NET); if (sceNetShowNetstat() == SCE_NET_ERROR_ENOTINIT) { net_memory = malloc(NET_INIT_SIZE); initparam.memory = net_memory; initparam.size = NET_INIT_SIZE; initparam.flags = 0; sceNetInit(&initparam); } sock = sceNetSocket("netdbg", SCE_NET_AF_INET, SCE_NET_SOCK_DGRAM, 0); memset(&target, 0, sizeof(target)); target.sin_family = SCE_NET_AF_INET; target.sin_port = sceNetHtons(3490); sceNetInetPton(SCE_NET_AF_INET, "192.168.1.104", &target.sin_addr); console_initialzed = 1; }
void ftp_init(char *vita_ip, unsigned short int *vita_port) { int ret; UNUSED(ret); SceNetInitParam initparam; SceNetCtlInfo info; if (ftp_initialized) { return; } /* Init Net */ if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT) { net_memory = malloc(NET_INIT_SIZE); initparam.memory = net_memory; initparam.size = NET_INIT_SIZE; initparam.flags = 0; ret = sceNetInit(&initparam); DEBUG("sceNetInit(): 0x%08X\n", ret); } else { DEBUG("Net is already initialized.\n"); } /* Init NetCtl */ ret = sceNetCtlInit(); DEBUG("sceNetCtlInit(): 0x%08X\n", ret); /* Get IP address */ ret = sceNetCtlInetGetInfo(PSP2_NETCTL_INFO_GET_IP_ADDRESS, &info); DEBUG("sceNetCtlInetGetInfo(): 0x%08X\n", ret); /* Return data */ strcpy(vita_ip, info.ip_address); *vita_port = FTP_PORT; /* Save the IP of PSVita to a global variable */ sceNetInetPton(PSP2_NET_AF_INET, info.ip_address, &vita_addr); /* Create server thread */ server_thid = sceKernelCreateThread("FTPVita_server_thread", server_thread, 0x10000100, 0x10000, 0, 0, NULL); DEBUG("Server thread UID: 0x%08X\n", server_thid); /* Create the client list mutex */ client_list_mtx = sceKernelCreateMutex("FTPVita_client_list_mutex", 0, 0, NULL); DEBUG("Client list mutex UID: 0x%08X\n", client_list_mtx); /* Start the server thread */ sceKernelStartThread(server_thid, 0, NULL); ftp_initialized = 1; }
/** * 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; }
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; }
/** * Init debugnet library * * @par Example: * @code * #define LOGLEVEL 3 * int ret; * ret = debugNetInit("172.26.0.2", 18194, DEBUG); * @endcode * * @param serverIP - your pc/mac server ip * @param port - udp port server * @param level - DEBUG,ERROR,INFO or NONE */ int debugNetInit(char *serverIp, int port, int level) { int ret; SceNetInitParam initparam; SceNetCtlInfo info; struct SceNetSockaddrIn stSockAddr; debugNetSetLogLevel(level); if (debugnet_initialized) { return debugnet_initialized; } /*net initialazation code from xerpi at https://github.com/xerpi/FTPVita/blob/master/ftp.c*/ /* Init Net */ if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT) { net_memory = malloc(NET_INIT_SIZE); initparam.memory = net_memory; initparam.size = NET_INIT_SIZE; initparam.flags = 0; ret = sceNetInit(&initparam); //printf("sceNetInit(): 0x%08X\n", ret); } else { //printf("Net is already initialized.\n"); } /* Init NetCtl */ ret = sceNetCtlInit(); //printf("sceNetCtlInit(): 0x%08X\n", ret); /* Get IP address */ ret = sceNetCtlInetGetInfo(PSP2_NETCTL_INFO_GET_IP_ADDRESS, &info); //printf("sceNetCtlInetGetInfo(): 0x%08X\n", ret); /* Save the IP of PSVita to a global variable */ sceNetInetPton(PSP2_NET_AF_INET, info.ip_address, &vita_addr); /* Create datagram udp socket*/ SocketFD = sceNetSocket("debugnet_socket", PSP2_NET_AF_INET , PSP2_NET_SOCK_DGRAM, PSP2_NET_IPPROTO_UDP); memset(&stSockAddr, 0, sizeof stSockAddr); /*Populate SceNetSockaddrIn structure values*/ stSockAddr.sin_family = PSP2_NET_AF_INET; stSockAddr.sin_port = sceNetHtons(port); sceNetInetPton(PSP2_NET_AF_INET, serverIp, &stSockAddr.sin_addr); /*Connect socket to server*/ sceNetConnect(SocketFD, (struct SceNetSockaddr *)&stSockAddr, sizeof stSockAddr); /*Show log on pc/mac side*/ debugNetUDPPrintf("debugnet initialized\n"); debugNetUDPPrintf("Copyright (C) 2010,2015 Antonio Jose Ramos Marquez aka bigboss @psxdev\n"); debugNetUDPPrintf("This Program is subject to the terms of the Mozilla Public\n" "License, v. 2.0. If a copy of the MPL was not distributed with this\n" "file, You can obtain one at http://mozilla.org/MPL/2.0/.\n"); debugNetUDPPrintf("ready to have a lot of fun...\n"); /*library debugnet initialized*/ debugnet_initialized = 1; return debugnet_initialized; }