mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 16:32:39 +00:00
implemented ORBIS_NET_CTL_INFO_ETHER_ADDR
This commit is contained in:
parent
8e0078b467
commit
642db71695
@ -316,6 +316,8 @@ set(NETWORK_LIBS src/core/libraries/network/http.cpp
|
|||||||
src/core/libraries/network/net_error.h
|
src/core/libraries/network/net_error.h
|
||||||
src/core/libraries/network/epoll.cpp
|
src/core/libraries/network/epoll.cpp
|
||||||
src/core/libraries/network/epoll.h
|
src/core/libraries/network/epoll.h
|
||||||
|
src/core/libraries/network/net_util.cpp
|
||||||
|
src/core/libraries/network/net_util.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(AVPLAYER_LIB src/core/libraries/avplayer/avplayer_common.cpp
|
set(AVPLAYER_LIB src/core/libraries/avplayer/avplayer_common.cpp
|
||||||
|
100
src/core/libraries/network/net_util.cpp
Normal file
100
src/core/libraries/network/net_util.cpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
#ifdef _WIN32
|
||||||
|
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||||
|
#include <Ws2tcpip.h>
|
||||||
|
#include <iphlpapi.h>
|
||||||
|
#include <winsock2.h>
|
||||||
|
typedef SOCKET net_socket;
|
||||||
|
typedef int socklen_t;
|
||||||
|
#else
|
||||||
|
#include <cerrno>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
typedef int net_socket;
|
||||||
|
#endif
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <vector>
|
||||||
|
#include "net_util.h"
|
||||||
|
|
||||||
|
namespace NetUtil {
|
||||||
|
|
||||||
|
const std::array<u8, 6>& NetUtilInternal::GetEthernetAddr() const {
|
||||||
|
return ether_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NetUtilInternal::RetrieveEthernetAddr() {
|
||||||
|
std::scoped_lock lock{m_mutex};
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::vector<u8> adapter_infos(sizeof(IP_ADAPTER_INFO));
|
||||||
|
ULONG size_infos = sizeof(IP_ADAPTER_INFO);
|
||||||
|
|
||||||
|
if (GetAdaptersInfo(reinterpret_cast<PIP_ADAPTER_INFO>(adapter_infos.data()), &size_infos) ==
|
||||||
|
ERROR_BUFFER_OVERFLOW)
|
||||||
|
adapter_infos.resize(size_infos);
|
||||||
|
|
||||||
|
if (GetAdaptersInfo(reinterpret_cast<PIP_ADAPTER_INFO>(adapter_infos.data()), &size_infos) ==
|
||||||
|
NO_ERROR &&
|
||||||
|
size_infos) {
|
||||||
|
PIP_ADAPTER_INFO info = reinterpret_cast<PIP_ADAPTER_INFO>(adapter_infos.data());
|
||||||
|
memcpy(ether_address.data(), info[0].Address, 6);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#elif defined __APPLE__
|
||||||
|
ifaddrs* ifap;
|
||||||
|
|
||||||
|
if (getifaddrs(&ifap) == 0) {
|
||||||
|
ifaddrs* p;
|
||||||
|
for (p = ifap; p; p = p->ifa_next) {
|
||||||
|
if (p->ifa_addr->sa_family == AF_LINK) {
|
||||||
|
sockaddr_dl* sdp = reinterpret_cast<sockaddr_dl*>(p->ifa_addr);
|
||||||
|
memcpy(ether_address.data(), sdp->sdl_data + sdp->sdl_nlen, 6);
|
||||||
|
freeifaddrs(ifap);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
freeifaddrs(ifap);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ifreq ifr;
|
||||||
|
ifconf ifc;
|
||||||
|
char buf[1024];
|
||||||
|
int success = 0;
|
||||||
|
|
||||||
|
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||||
|
if (sock == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ifc.ifc_len = sizeof(buf);
|
||||||
|
ifc.ifc_buf = buf;
|
||||||
|
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ifreq* it = ifc.ifc_req;
|
||||||
|
const ifreq* const end = it + (ifc.ifc_len / sizeof(ifreq));
|
||||||
|
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
strcpy(ifr.ifr_name, it->ifr_name);
|
||||||
|
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
|
||||||
|
if (!(ifr.ifr_flags & IFF_LOOPBACK)) {
|
||||||
|
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) {
|
||||||
|
success = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
memcpy(ether_address.data(), ifr.ifr_hwaddr.sa_data, 6);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} // namespace NetUtil
|
24
src/core/libraries/network/net_util.h
Normal file
24
src/core/libraries/network/net_util.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include "common/types.h"
|
||||||
|
|
||||||
|
namespace NetUtil {
|
||||||
|
|
||||||
|
class NetUtilInternal {
|
||||||
|
public:
|
||||||
|
explicit NetUtilInternal() = default;
|
||||||
|
~NetUtilInternal() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<u8, 6> ether_address{};
|
||||||
|
std::mutex m_mutex;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const std::array<u8, 6>& GetEthernetAddr() const;
|
||||||
|
bool RetrieveEthernetAddr();
|
||||||
|
};
|
||||||
|
} // namespace NetUtil
|
@ -12,11 +12,13 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <common/singleton.h>
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/libraries/error_codes.h"
|
#include "core/libraries/error_codes.h"
|
||||||
#include "core/libraries/libs.h"
|
#include "core/libraries/libs.h"
|
||||||
#include "core/libraries/network/net_ctl_codes.h"
|
#include "core/libraries/network/net_ctl_codes.h"
|
||||||
#include "core/libraries/network/netctl.h"
|
#include "core/libraries/network/netctl.h"
|
||||||
|
#include "net_util.h"
|
||||||
|
|
||||||
namespace Libraries::NetCtl {
|
namespace Libraries::NetCtl {
|
||||||
|
|
||||||
@ -162,6 +164,11 @@ int PS4_SYSV_ABI sceNetCtlGetInfo(int code, OrbisNetCtlInfo* info) {
|
|||||||
case ORBIS_NET_CTL_INFO_DEVICE:
|
case ORBIS_NET_CTL_INFO_DEVICE:
|
||||||
info->device = ORBIS_NET_CTL_DEVICE_WIRED;
|
info->device = ORBIS_NET_CTL_DEVICE_WIRED;
|
||||||
break;
|
break;
|
||||||
|
case ORBIS_NET_CTL_INFO_ETHER_ADDR: {
|
||||||
|
auto* netinfo = Common::Singleton<NetUtil::NetUtilInternal>::Instance();
|
||||||
|
netinfo->RetrieveEthernetAddr();
|
||||||
|
memcpy(info->ether_addr.data, netinfo->GetEthernetAddr().data(), 6);
|
||||||
|
} break;
|
||||||
case ORBIS_NET_CTL_INFO_LINK:
|
case ORBIS_NET_CTL_INFO_LINK:
|
||||||
info->link = ORBIS_NET_CTL_LINK_DISCONNECTED;
|
info->link = ORBIS_NET_CTL_LINK_DISCONNECTED;
|
||||||
break;
|
break;
|
||||||
|
@ -49,9 +49,26 @@ union OrbisNetCtlInfo {
|
|||||||
|
|
||||||
// GetInfo codes
|
// GetInfo codes
|
||||||
constexpr int ORBIS_NET_CTL_INFO_DEVICE = 1;
|
constexpr int ORBIS_NET_CTL_INFO_DEVICE = 1;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_ETHER_ADDR = 2;
|
||||||
constexpr int ORBIS_NET_CTL_INFO_MTU = 3;
|
constexpr int ORBIS_NET_CTL_INFO_MTU = 3;
|
||||||
constexpr int ORBIS_NET_CTL_INFO_LINK = 4;
|
constexpr int ORBIS_NET_CTL_INFO_LINK = 4;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_BSSID = 5;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_SSID = 6;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_WIFI_SECURITY = 7;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_RSSI_DBM = 8;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_RSSI_PERCENTAGE = 9;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_CHANNEL = 10;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_IP_CONFIG = 11;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_DHCP_HOSTNAME = 12;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_PPPOE_AUTH_NAME = 13;
|
||||||
constexpr int ORBIS_NET_CTL_INFO_IP_ADDRESS = 14;
|
constexpr int ORBIS_NET_CTL_INFO_IP_ADDRESS = 14;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_NETMASK = 15;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_DEFAULT_ROUTE = 16;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_PRIMARY_DNS = 17;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_SECONDARY_DNS = 18;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_HTTP_PROXY_CONFIG = 19;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_HTTP_PROXY_SERVER = 20;
|
||||||
|
constexpr int ORBIS_NET_CTL_INFO_HTTP_PROXY_PORT = 21;
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetBweCheckCallbackIpcInt();
|
int PS4_SYSV_ABI sceNetBweCheckCallbackIpcInt();
|
||||||
int PS4_SYSV_ABI sceNetBweClearEventIpcInt();
|
int PS4_SYSV_ABI sceNetBweClearEventIpcInt();
|
||||||
|
Loading…
Reference in New Issue
Block a user