RetroArch/netlogger.c

159 lines
3.8 KiB
C
Raw Normal View History

2012-04-21 23:13:50 +02:00
/* RetroArch - A frontend for libretro.
2014-01-01 01:50:59 +01:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2016-01-10 04:06:50 +01:00
* Copyright (C) 2011-2016 - Daniel De Matteis
2015-08-30 22:47:50 +02:00
*
2012-04-21 23:13:50 +02:00
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
2012-04-21 23:13:50 +02:00
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
2012-04-21 23:31:57 +02:00
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(__CELLOS_LV2__) || defined(__PSL1GHT__)
2015-09-16 11:33:53 +02:00
#include "../defines/ps3_defines.h"
2012-03-13 00:44:37 +01:00
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <retro_miscellaneous.h>
2015-03-20 18:18:52 +01:00
#include <net/net_compat.h>
2016-05-02 00:05:33 +02:00
#include <net/net_socket.h>
2012-03-13 00:44:37 +01:00
2015-11-23 12:03:38 +01:00
#include "verbosity.h"
#if !defined(PC_DEVELOPMENT_IP_ADDRESS)
#error "An IP address for the PC logging server was not set in the Makefile, cannot continue."
#endif
#if !defined(PC_DEVELOPMENT_UDP_PORT)
#error "An UDP port for the PC logging server was not set in the Makefile, cannot continue."
#endif
static int g_sid;
static struct sockaddr_in target;
static char sendbuf[4096];
2015-08-30 22:47:50 +02:00
#ifdef VITA
#define NET_INIT_SIZE 512*1024
#endif
2016-05-02 00:05:33 +02:00
static void *net_memory = NULL;
2015-08-29 18:57:07 +02:00
static int network_interface_up(struct sockaddr_in *target, int index,
const char *ip_address, unsigned udp_port, int *s)
{
(void)index;
2015-08-30 16:12:45 +02:00
#if defined(VITA)
2015-08-30 22:47:50 +02:00
if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT)
{
SceNetInitParam initparam;
2016-05-02 00:21:13 +02:00
net_memory = malloc(NET_INIT_SIZE);
2015-08-30 22:47:50 +02:00
initparam.memory = net_memory;
2016-05-02 00:21:13 +02:00
initparam.size = NET_INIT_SIZE;
initparam.flags = 0;
2015-08-30 22:47:50 +02:00
sceNetInit(&initparam);
}
2016-05-02 00:21:13 +02:00
*s = sceNetSocket("RA_netlogger",
PSP2_NET_AF_INET, PSP2_NET_SOCK_DGRAM, 0);
2015-08-30 16:12:45 +02:00
target->sin_family = PSP2_NET_AF_INET;
target->sin_port = sceNetHtons(udp_port);
2016-05-02 00:18:39 +02:00
target->sin_addr = inet_aton(ip_address);
2015-08-30 16:12:45 +02:00
#else
2015-08-29 18:57:07 +02:00
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
2015-08-30 16:12:45 +02:00
int ret = 0;
2015-08-29 18:57:07 +02:00
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;
2015-09-22 18:55:14 +02:00
retro_sleep(500);
2015-08-29 18:57:07 +02:00
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);
2015-08-30 16:12:45 +02:00
#endif
2015-08-29 18:57:07 +02:00
return 0;
}
void logger_init (void)
{
if (network_interface_up(&target, 1,
PC_DEVELOPMENT_IP_ADDRESS,PC_DEVELOPMENT_UDP_PORT, &g_sid) < 0)
printf("Could not initialize network logger interface.\n");
}
void logger_shutdown (void)
{
2016-05-02 00:21:13 +02:00
int ret = socket_close(g_sid);
network_deinit();
if (net_memory)
free(net_memory);
if (ret < 0)
printf("Could not deinitialize network logger interface.\n");
}
2012-03-13 00:44:37 +01:00
void logger_send(const char *__format,...)
{
va_list args;
va_start(args,__format);
2013-12-22 16:42:03 -05:00
logger_send_v(__format, args);
va_end(args);
2013-12-22 16:42:03 -05:00
}
void logger_send_v(const char *__format, va_list args)
{
2014-06-01 16:06:00 +02:00
int len;
2013-12-22 16:42:03 -05:00
vsnprintf(sendbuf,4000,__format, args);
2014-06-01 16:06:00 +02:00
len = strlen(sendbuf);
2016-05-02 00:21:13 +02:00
sendto(g_sid,
sendbuf,
len,
MSG_DONTWAIT,
(struct sockaddr*)&target,
sizeof(target));
}