mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 12:15:34 +08:00
Remote desk client supports Linux platform
This commit is contained in:
@@ -7,9 +7,16 @@
|
|||||||
#include <net/if_types.h>
|
#include <net/if_types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#elif __linux__
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -211,8 +218,8 @@ std::string GetMac(char *mac_addr) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#elif __APPLE__
|
||||||
std::string ifName = "en0";
|
std::string if_name = "en0";
|
||||||
|
|
||||||
struct ifaddrs *addrs;
|
struct ifaddrs *addrs;
|
||||||
struct ifaddrs *cursor;
|
struct ifaddrs *cursor;
|
||||||
@@ -225,7 +232,7 @@ std::string GetMac(char *mac_addr) {
|
|||||||
(const struct sockaddr_dl *)cursor->ifa_addr;
|
(const struct sockaddr_dl *)cursor->ifa_addr;
|
||||||
if ((cursor->ifa_addr->sa_family == AF_LINK) &&
|
if ((cursor->ifa_addr->sa_family == AF_LINK) &&
|
||||||
(socAddr->sdl_type == IFT_ETHER) &&
|
(socAddr->sdl_type == IFT_ETHER) &&
|
||||||
strcmp("en0", cursor->ifa_name) == 0) {
|
strcmp(if_name, cursor->ifa_name) == 0) {
|
||||||
dlAddr = (const struct sockaddr_dl *)cursor->ifa_addr;
|
dlAddr = (const struct sockaddr_dl *)cursor->ifa_addr;
|
||||||
const unsigned char *base =
|
const unsigned char *base =
|
||||||
(const unsigned char *)&dlAddr->sdl_data[dlAddr->sdl_nlen];
|
(const unsigned char *)&dlAddr->sdl_data[dlAddr->sdl_nlen];
|
||||||
@@ -237,6 +244,40 @@ std::string GetMac(char *mac_addr) {
|
|||||||
}
|
}
|
||||||
freeifaddrs(addrs);
|
freeifaddrs(addrs);
|
||||||
}
|
}
|
||||||
|
#elif __linux__
|
||||||
|
int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (sock < 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
struct ifreq ifr;
|
||||||
|
struct ifconf ifc;
|
||||||
|
char buf[1024];
|
||||||
|
ifc.ifc_len = sizeof(buf);
|
||||||
|
ifc.ifc_buf = buf;
|
||||||
|
if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
|
||||||
|
close(sock);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
struct ifreq *it = ifc.ifc_req;
|
||||||
|
const struct ifreq *const end = it + (ifc.ifc_len / sizeof(struct ifreq));
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
std::strcpy(ifr.ifr_name, it->ifr_name);
|
||||||
|
if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ifr.ifr_flags & IFF_LOOPBACK) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::string mac_address;
|
||||||
|
for (int i = 0; i < 6; ++i) {
|
||||||
|
len += sprintf(mac_addr + len, "%.2X", ifr.ifr_hwaddr.sa_data[i] & 0xff);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
close(sock);
|
||||||
#endif
|
#endif
|
||||||
return mac_addr;
|
return mac_addr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ target("remote_desk_client")
|
|||||||
add_packages("log")
|
add_packages("log")
|
||||||
if is_os("windows") then
|
if is_os("windows") then
|
||||||
add_packages("vcpkg::sdl2")
|
add_packages("vcpkg::sdl2")
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") or is_os("linux")then
|
||||||
-- add_packages("vcpkg::sdl2")
|
|
||||||
add_packages("sdl2")
|
add_packages("sdl2")
|
||||||
add_packages("ffmpeg")
|
add_packages("ffmpeg")
|
||||||
end
|
end
|
||||||
@@ -70,7 +69,7 @@ target("remote_desk_client")
|
|||||||
if is_os("windows") then
|
if is_os("windows") then
|
||||||
add_links("SDL2-static", "SDL2main", "gdi32", "winmm",
|
add_links("SDL2-static", "SDL2main", "gdi32", "winmm",
|
||||||
"setupapi", "version", "Imm32", "iphlpapi")
|
"setupapi", "version", "Imm32", "iphlpapi")
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") or is_os("linux") then
|
||||||
add_links("SDL2")
|
add_links("SDL2")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user