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; }
int inet_ptrton(int af, const char *src, void *dst) { #if defined(VITA) || defined(__ORBIS__) return sceNetInetPton(af, src, dst); #elif defined(GEKKO) || defined(_WIN32) /* TODO/FIXME - should use InetPton on Vista and later */ return inet_aton(src, (struct in_addr*)dst); #else return inet_pton(af, src, dst); #endif }
static void cmd_PORT_func(ClientInfo *client) { unsigned char data_ip[4]; unsigned char porthi, portlo; unsigned short data_port; char ip_str[16]; SceNetInAddr data_addr; sscanf(client->recv_buffer, "%*s %hhu,%hhu,%hhu,%hhu,%hhu,%hhu", &data_ip[0], &data_ip[1], &data_ip[2], &data_ip[3], &porthi, &portlo); data_port = portlo + porthi*256; /* Convert to an X.X.X.X IP string */ sprintf(ip_str, "%d.%d.%d.%d", data_ip[0], data_ip[1], data_ip[2], data_ip[3]); /* Convert the IP to a SceNetInAddr */ sceNetInetPton(PSP2_NET_AF_INET, ip_str, &data_addr); DEBUG("PORT connection to client's IP: %s Port: %d\n", ip_str, data_port); /* Create data mode socket name */ char data_socket_name[64]; sprintf(data_socket_name, "FTPVita_client_%i_data_socket", client->num); /* Create data mode socket */ client->data_sockfd = sceNetSocket(data_socket_name, PSP2_NET_AF_INET, PSP2_NET_SOCK_STREAM, 0); DEBUG("Client %i data socket fd: %d\n", client->num, client->data_sockfd); /* Prepare socket address for the data connection */ client->data_sockaddr.sin_family = PSP2_NET_AF_INET; client->data_sockaddr.sin_addr = data_addr; client->data_sockaddr.sin_port = sceNetHtons(data_port); /* Set the data connection type to active! */ client->data_con_type = FTP_DATA_CONNECTION_ACTIVE; client_send_ctrl_msg(client, "200 PORT command successful!\n"); }
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; }