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; }
/** * 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; }