Add QR code pairing
This commit is contained in:
@@ -567,6 +567,9 @@ namespace platf {
|
||||
std::string
|
||||
get_mac_address(const std::string_view &address);
|
||||
|
||||
std::string
|
||||
get_local_ip_for_gateway();
|
||||
|
||||
std::string
|
||||
from_sockaddr(const sockaddr *const);
|
||||
std::pair<std::uint16_t, std::string>
|
||||
|
||||
@@ -239,6 +239,83 @@ namespace platf {
|
||||
return "00:00:00:00:00:00"s;
|
||||
}
|
||||
|
||||
std::string
|
||||
get_local_ip_for_gateway() {
|
||||
int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
if (fd < 0) {
|
||||
BOOST_LOG(warning) << "Socket creation failed";
|
||||
return "";
|
||||
}
|
||||
|
||||
char buffer[8192];
|
||||
struct nlmsghdr *nlMsg = (struct nlmsghdr *)buffer;
|
||||
struct rtmsg *rtMsg = (struct rtmsg *)NLMSG_DATA(nlMsg);
|
||||
struct rtattr *rtAttr;
|
||||
int len = 0;
|
||||
|
||||
memset(nlMsg, 0, sizeof(struct nlmsghdr));
|
||||
nlMsg->nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
||||
nlMsg->nlmsg_type = RTM_GETROUTE;
|
||||
nlMsg->nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST;
|
||||
nlMsg->nlmsg_seq = 1;
|
||||
nlMsg->nlmsg_pid = getpid();
|
||||
|
||||
if (send(fd, nlMsg, nlMsg->nlmsg_len, 0) < 0) {
|
||||
close(fd);
|
||||
BOOST_LOG(warning) << "Send message failed";
|
||||
return "";
|
||||
}
|
||||
|
||||
len = recv(fd, nlMsg, sizeof(buffer), 0);
|
||||
if (len < 0) {
|
||||
close(fd);
|
||||
BOOST_LOG(warning) << "Receive message failed";
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string local_ip;
|
||||
|
||||
for (; NLMSG_OK(nlMsg, len); nlMsg = NLMSG_NEXT(nlMsg, len)) {
|
||||
rtMsg = (struct rtmsg *)NLMSG_DATA(nlMsg);
|
||||
if (rtMsg->rtm_family != AF_INET || rtMsg->rtm_table != RT_TABLE_MAIN)
|
||||
continue;
|
||||
|
||||
rtAttr = (struct rtattr *)RTM_RTA(rtMsg);
|
||||
int rtLen = RTM_PAYLOAD(nlMsg);
|
||||
|
||||
in_addr gateway;
|
||||
in_addr local;
|
||||
memset(&gateway, 0, sizeof(gateway));
|
||||
memset(&local, 0, sizeof(local));
|
||||
|
||||
for (; RTA_OK(rtAttr, rtLen); rtAttr = RTA_NEXT(rtAttr, rtLen)) {
|
||||
switch(rtAttr->rta_type) {
|
||||
case RTA_GATEWAY:
|
||||
gateway.s_addr = *reinterpret_cast<uint32_t *>(RTA_DATA(rtAttr));
|
||||
break;
|
||||
case RTA_PREFSRC:
|
||||
local.s_addr = *reinterpret_cast<uint32_t *>(RTA_DATA(rtAttr));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (gateway.s_addr != 0 && local.s_addr != 0) {
|
||||
local_ip = inet_ntoa(local);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
if (local_ip.empty()) {
|
||||
BOOST_LOG(warning) << "No associated IP address found for the default gateway";
|
||||
}
|
||||
|
||||
return local_ip;
|
||||
}
|
||||
|
||||
bp::child
|
||||
run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) {
|
||||
if (!group) {
|
||||
|
||||
@@ -168,6 +168,12 @@ namespace platf {
|
||||
return "00:00:00:00:00:00"s;
|
||||
}
|
||||
|
||||
// TODO: return actual IP
|
||||
std::string
|
||||
get_local_ip_for_gateway() {
|
||||
return "";
|
||||
}
|
||||
|
||||
bp::child
|
||||
run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) {
|
||||
if (!group) {
|
||||
|
||||
@@ -190,6 +190,62 @@ namespace platf {
|
||||
return "00:00:00:00:00:00"s;
|
||||
}
|
||||
|
||||
std::string
|
||||
get_local_ip_for_gateway() {
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
PIP_ADAPTER_INFO pAdapter = nullptr;
|
||||
DWORD dwRetVal = 0;
|
||||
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
||||
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
|
||||
if (pAdapterInfo == nullptr) {
|
||||
BOOST_LOG(warning) << "Error allocating memory needed to call GetAdaptersInfo";
|
||||
return "";
|
||||
}
|
||||
|
||||
// Make an initial call to GetAdaptersInfo to get the necessary size into the ulOutBufLen variable
|
||||
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
|
||||
free(pAdapterInfo);
|
||||
pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen);
|
||||
if (pAdapterInfo == nullptr) {
|
||||
BOOST_LOG(warning) << "Error allocating memory needed to call GetAdaptersInfo";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) != NO_ERROR) {
|
||||
if (pAdapterInfo) {
|
||||
free(pAdapterInfo);
|
||||
}
|
||||
BOOST_LOG(warning) << "GetAdaptersInfo failed with error: " + std::to_string(dwRetVal);
|
||||
return "";
|
||||
}
|
||||
|
||||
pAdapter = pAdapterInfo;
|
||||
std::string local_ip;
|
||||
|
||||
// Iterate through the list of adapters
|
||||
while (pAdapter) {
|
||||
IP_ADDR_STRING* pGateway = &pAdapter->GatewayList;
|
||||
if (pGateway && pGateway->IpAddress.String[0] != '\0') {
|
||||
// This adapter has a default gateway, use its IP address
|
||||
local_ip = pAdapter->IpAddressList.IpAddress.String;
|
||||
break;
|
||||
}
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
|
||||
if (pAdapterInfo) {
|
||||
free(pAdapterInfo);
|
||||
}
|
||||
|
||||
if (local_ip.empty()) {
|
||||
BOOST_LOG(warning) << "No associated IP address found for the default gateway";
|
||||
}
|
||||
|
||||
return local_ip;
|
||||
}
|
||||
|
||||
HDESK
|
||||
syncThreadDesktop() {
|
||||
auto hDesk = OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, FALSE, GENERIC_ALL);
|
||||
|
||||
Reference in New Issue
Block a user