mirror of
https://github.com/libretro/RetroArch
synced 2025-03-20 01:21:03 +00:00
Merge pull request #7424 from natinusala/libnx-network-info
libnx: add network interfaces info
This commit is contained in:
commit
264c1ee381
@ -70,7 +70,7 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
include Makefile.common
|
include Makefile.common
|
||||||
BLACKLIST := $(LIBRETRO_COMM_DIR)/net/net_ifinfo.o
|
BLACKLIST :=
|
||||||
|
|
||||||
OBJ := $(filter-out $(BLACKLIST),$(OBJ))
|
OBJ := $(filter-out $(BLACKLIST),$(OBJ))
|
||||||
|
|
||||||
|
@ -191,6 +191,7 @@ static void frontend_switch_deinit(void *data)
|
|||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
#ifdef HAVE_LIBNX
|
#ifdef HAVE_LIBNX
|
||||||
|
nifmExit();
|
||||||
#if defined(SWITCH) && defined(NXLINK)
|
#if defined(SWITCH) && defined(NXLINK)
|
||||||
socketExit();
|
socketExit();
|
||||||
#endif
|
#endif
|
||||||
@ -607,6 +608,7 @@ static void frontend_switch_init(void *data)
|
|||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
#ifdef HAVE_LIBNX
|
#ifdef HAVE_LIBNX
|
||||||
|
nifmInitialize();
|
||||||
#ifndef HAVE_OPENGL
|
#ifndef HAVE_OPENGL
|
||||||
/* Init Resolution before initDefault */
|
/* Init Resolution before initDefault */
|
||||||
gfxInitResolution(1280, 720);
|
gfxInitResolution(1280, 720);
|
||||||
|
@ -38,9 +38,11 @@
|
|||||||
#ifdef WANT_IFADDRS
|
#ifdef WANT_IFADDRS
|
||||||
#include <compat/ifaddrs.h>
|
#include <compat/ifaddrs.h>
|
||||||
#else
|
#else
|
||||||
|
#ifndef HAVE_LIBNX
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <net/net_ifinfo.h>
|
#include <net/net_ifinfo.h>
|
||||||
|
|
||||||
@ -71,10 +73,77 @@ void net_ifinfo_free(net_ifinfo_t *list)
|
|||||||
free(list->entries);
|
free(list->entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBNX
|
||||||
|
static void convert_ip(char *dst, size_t size, uint32_t ip, bool inverted)
|
||||||
|
{
|
||||||
|
unsigned char bytes[4];
|
||||||
|
bytes[0] = ip & 0xFF;
|
||||||
|
bytes[1] = (ip >> 8) & 0xFF;
|
||||||
|
bytes[2] = (ip >> 16) & 0xFF;
|
||||||
|
bytes[3] = (ip >> 24) & 0xFF;
|
||||||
|
|
||||||
|
if (inverted)
|
||||||
|
snprintf(dst, size, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]);
|
||||||
|
else
|
||||||
|
snprintf(dst, size, "%d.%d.%d.%d", bytes[3], bytes[2], bytes[1], bytes[0]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool net_ifinfo_new(net_ifinfo_t *list)
|
bool net_ifinfo_new(net_ifinfo_t *list)
|
||||||
{
|
{
|
||||||
unsigned k = 0;
|
unsigned k = 0;
|
||||||
#if defined(_WIN32) && !defined(_XBOX)
|
#ifdef HAVE_LIBNX
|
||||||
|
uint32_t id;
|
||||||
|
Result rc;
|
||||||
|
|
||||||
|
char hostname[128];
|
||||||
|
struct net_ifinfo_entry *ptr = NULL;
|
||||||
|
|
||||||
|
memset(list, 0, sizeof(net_ifinfo_t));
|
||||||
|
|
||||||
|
/* loopback */
|
||||||
|
convert_ip(hostname, sizeof(hostname), INADDR_LOOPBACK, false);
|
||||||
|
|
||||||
|
ptr = (struct net_ifinfo_entry*)
|
||||||
|
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
list->entries = ptr;
|
||||||
|
|
||||||
|
list->entries[k].name = strdup("lo");
|
||||||
|
list->entries[k].host = strdup(hostname);
|
||||||
|
list->size = k + 1;
|
||||||
|
|
||||||
|
k++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
actual interface
|
||||||
|
can be wlan or eth (with a wiiu adapter)
|
||||||
|
so we just use "switch" as a name
|
||||||
|
*/
|
||||||
|
rc = nifmGetCurrentIpAddress(&id);
|
||||||
|
|
||||||
|
if (!R_SUCCEEDED(rc)) /* not connected to any network */
|
||||||
|
return true;
|
||||||
|
|
||||||
|
convert_ip(hostname, sizeof(hostname), id, true);
|
||||||
|
|
||||||
|
ptr = (struct net_ifinfo_entry*)
|
||||||
|
realloc(list->entries, (k+1) * sizeof(struct net_ifinfo_entry));
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
list->entries = ptr;
|
||||||
|
|
||||||
|
list->entries[k].name = strdup("switch");
|
||||||
|
list->entries[k].host = strdup(hostname);
|
||||||
|
list->size = k + 1;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#elif defined(_WIN32) && !defined(_XBOX)
|
||||||
PIP_ADAPTER_ADDRESSES adapter_addresses = NULL, aa = NULL;
|
PIP_ADAPTER_ADDRESSES adapter_addresses = NULL, aa = NULL;
|
||||||
PIP_ADAPTER_UNICAST_ADDRESS ua = NULL;
|
PIP_ADAPTER_UNICAST_ADDRESS ua = NULL;
|
||||||
#ifdef _WIN32_WINNT_WINXP
|
#ifdef _WIN32_WINNT_WINXP
|
||||||
@ -173,7 +242,7 @@ error:
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (adapter_addresses)
|
if (adapter_addresses)
|
||||||
free(adapter_addresses);
|
free(adapter_addresses);
|
||||||
#else
|
#elif !defined(HAVE_LIBNX)
|
||||||
freeifaddrs(ifaddr);
|
freeifaddrs(ifaddr);
|
||||||
#endif
|
#endif
|
||||||
net_ifinfo_free(list);
|
net_ifinfo_free(list);
|
||||||
|
@ -184,7 +184,7 @@ static bool natt_open_port(struct natt_status *status,
|
|||||||
bool natt_open_port_any(struct natt_status *status,
|
bool natt_open_port_any(struct natt_status *status,
|
||||||
uint16_t port, enum socket_protocol proto)
|
uint16_t port, enum socket_protocol proto)
|
||||||
{
|
{
|
||||||
#if !defined(HAVE_SOCKET_LEGACY) && !defined(SWITCH)
|
#if !defined(HAVE_SOCKET_LEGACY) && (!defined(SWITCH) || defined(SWITCH) && defined(HAVE_LIBNX))
|
||||||
size_t i;
|
size_t i;
|
||||||
char port_str[6];
|
char port_str[6];
|
||||||
struct net_ifinfo list;
|
struct net_ifinfo list;
|
||||||
|
@ -97,7 +97,7 @@ static enum msg_hash_enums new_type = MSG_UNKNOWN;
|
|||||||
* function pointer callback functions that don't necessarily
|
* function pointer callback functions that don't necessarily
|
||||||
* call each other. */
|
* call each other. */
|
||||||
|
|
||||||
#if !defined(HAVE_SOCKET_LEGACY) && !defined(SWITCH)
|
#if !defined(HAVE_SOCKET_LEGACY) && (!defined(SWITCH) || defined(SWITCH) && defined(HAVE_LIBNX))
|
||||||
#include <net/net_ifinfo.h>
|
#include <net/net_ifinfo.h>
|
||||||
|
|
||||||
static int menu_displaylist_parse_network_info(menu_displaylist_info_t *info)
|
static int menu_displaylist_parse_network_info(menu_displaylist_info_t *info)
|
||||||
@ -4834,7 +4834,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
|
|||||||
break;
|
break;
|
||||||
case DISPLAYLIST_NETWORK_INFO:
|
case DISPLAYLIST_NETWORK_INFO:
|
||||||
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
|
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
|
||||||
#if defined(HAVE_NETWORKING) && !defined(HAVE_SOCKET_LEGACY) && !defined(SWITCH)
|
#if defined(HAVE_NETWORKING) && !defined(HAVE_SOCKET_LEGACY) && (!defined(SWITCH) || defined(SWITCH) && defined(HAVE_LIBNX))
|
||||||
count = menu_displaylist_parse_network_info(info);
|
count = menu_displaylist_parse_network_info(info);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user