2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2012-02-27 12:43:44 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2012-02-27 12:43:44 +00:00
|
|
|
* 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 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2012-02-27 12:43:44 +00:00
|
|
|
* 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 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2012-02-27 12:43:44 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-08-29 14:24:38 +00:00
|
|
|
#if defined(__CELLOS_LV2__) || defined(__PSL1GHT__)
|
2015-08-10 21:11:40 +00:00
|
|
|
#include "../../defines/ps3_defines.h"
|
2012-03-12 23:44:37 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2012-02-27 12:43:44 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2015-08-29 13:24:23 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2015-03-20 17:18:52 +00:00
|
|
|
#include <net/net_compat.h>
|
2012-03-12 23:44:37 +00:00
|
|
|
|
2015-08-29 14:48:53 +00:00
|
|
|
#include <retro_log.h>
|
2012-02-27 12:43:44 +00:00
|
|
|
|
2012-02-28 15:32:52 +00:00
|
|
|
#if !defined(PC_DEVELOPMENT_IP_ADDRESS)
|
2012-07-28 15:43:45 +00:00
|
|
|
#error "An IP address for the PC logging server was not set in the Makefile, cannot continue."
|
2012-02-28 15:32:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(PC_DEVELOPMENT_UDP_PORT)
|
2012-07-28 15:43:45 +00:00
|
|
|
#error "An UDP port for the PC logging server was not set in the Makefile, cannot continue."
|
2012-02-28 15:32:52 +00:00
|
|
|
#endif
|
2012-02-27 12:43:44 +00:00
|
|
|
|
|
|
|
static int g_sid;
|
|
|
|
static int sock;
|
|
|
|
static struct sockaddr_in target;
|
|
|
|
static char sendbuf[4096];
|
|
|
|
|
2015-08-29 16:57:07 +00: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 14:12:45 +00:00
|
|
|
#if defined(VITA)
|
|
|
|
*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);
|
|
|
|
target->sin_len = 8;
|
|
|
|
|
|
|
|
sceNetInetPton(PSP2_NET_AF_INET, ip_address, &target->sin_addr);
|
|
|
|
#else
|
|
|
|
|
2015-08-29 16:57:07 +00:00
|
|
|
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
|
2015-08-30 14:12:45 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2015-08-29 16:57:07 +00: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;
|
|
|
|
|
|
|
|
rarch_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);
|
2015-08-30 14:12:45 +00:00
|
|
|
#endif
|
2015-08-29 16:57:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int network_interface_down(struct sockaddr_in *target, int *s)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
#if defined(_WIN32) && !defined(_XBOX360)
|
|
|
|
/* WinSock has headers from the stone age. */
|
|
|
|
ret = closesocket(*s);
|
|
|
|
#elif defined(__CELLOS_LV2__)
|
|
|
|
ret = socketclose(*s);
|
|
|
|
#else
|
|
|
|
ret = close(*s);
|
|
|
|
#endif
|
|
|
|
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
|
|
|
|
cellNetCtlTerm();
|
|
|
|
#elif defined(GEKKO) && !defined(HW_DOL)
|
|
|
|
net_deinit();
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-29 14:24:38 +00:00
|
|
|
void logger_init (void)
|
2012-02-27 12:43:44 +00:00
|
|
|
{
|
2015-08-29 14:24:38 +00:00
|
|
|
if (network_interface_up(&target, 1,
|
|
|
|
PC_DEVELOPMENT_IP_ADDRESS,PC_DEVELOPMENT_UDP_PORT, &g_sid) < 0)
|
2012-04-10 19:23:42 +00:00
|
|
|
{
|
2015-08-29 14:24:38 +00:00
|
|
|
printf("Could not initialize network logger interface.\n");
|
2012-04-10 19:23:42 +00:00
|
|
|
}
|
2012-02-27 12:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void logger_shutdown (void)
|
|
|
|
{
|
2015-08-29 14:24:38 +00:00
|
|
|
if (network_interface_down(&target, &g_sid) < 0)
|
|
|
|
{
|
|
|
|
printf("Could not deinitialize network logger interface.\n");
|
|
|
|
}
|
2012-02-27 12:43:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 23:44:37 +00:00
|
|
|
void logger_send(const char *__format,...)
|
2012-02-27 12:43:44 +00:00
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
va_list args;
|
2012-02-27 12:43:44 +00:00
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
va_start(args,__format);
|
2013-12-22 21:42:03 +00:00
|
|
|
logger_send_v(__format, args);
|
2012-04-10 19:23:42 +00:00
|
|
|
va_end(args);
|
2013-12-22 21:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void logger_send_v(const char *__format, va_list args)
|
|
|
|
{
|
2014-06-01 14:06:00 +00:00
|
|
|
int len;
|
2013-12-22 21:42:03 +00:00
|
|
|
vsnprintf(sendbuf,4000,__format, args);
|
2014-06-01 14:06:00 +00:00
|
|
|
len = strlen(sendbuf);
|
2012-04-10 19:23:42 +00:00
|
|
|
sendto(sock,sendbuf,len,MSG_DONTWAIT,(struct sockaddr*)&target,sizeof(target));
|
2012-02-27 12:43:44 +00:00
|
|
|
}
|