aboutsummaryrefslogtreecommitdiffhomepage
path: root/hyprctl
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2022-05-24 19:42:43 +0200
committervaxerski <[email protected]>2022-05-24 19:42:43 +0200
commitba7e3cd9a18d6c74bc1f3819ec7485e25daf3472 (patch)
treefdc6cf727d47b4adc953f1c9edfc0f1686ad8a63 /hyprctl
parentd8d8a29fc2a6e134c15dac64a919991b535acca4 (diff)
downloadHyprland-ba7e3cd9a18d6c74bc1f3819ec7485e25daf3472.tar.gz
Hyprland-ba7e3cd9a18d6c74bc1f3819ec7485e25daf3472.zip
Major IPC Rework + Added Socket2
IPC is now done with UNIX sockets instead of TCP ones (security!), and added Socket2, see Wiki.
Diffstat (limited to 'hyprctl')
-rw-r--r--hyprctl/main.cpp40
1 files changed, 7 insertions, 33 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp
index 9cca9792..5b932441 100644
--- a/hyprctl/main.cpp
+++ b/hyprctl/main.cpp
@@ -7,6 +7,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/un.h>
#include <unistd.h>
#include <iostream>
@@ -29,7 +30,7 @@ usage: hyprctl [command] [(opt)args]
)#";
void request(std::string arg) {
- const auto SERVERSOCKET = socket(AF_INET, SOCK_STREAM, 0);
+ const auto SERVERSOCKET = socket(AF_UNIX, SOCK_STREAM, 0);
if (SERVERSOCKET < 0) {
std::cout << "Couldn't open a socket (1)";
@@ -43,39 +44,12 @@ void request(std::string arg) {
return;
}
- sockaddr_in serverAddress = {0};
- serverAddress.sin_family = AF_INET;
- bcopy((char*)SERVER->h_addr, (char*)&serverAddress.sin_addr.s_addr, SERVER->h_length);
+ sockaddr_un serverAddress = {0};
+ serverAddress.sun_family = AF_UNIX;
+ strcpy(serverAddress.sun_path, "/tmp/hypr/.socket.sock");
- std::ifstream socketPortStream;
- socketPortStream.open("/tmp/hypr/.socket");
-
- if (!socketPortStream.good()) {
- std::cout << "No socket port file (2a)";
- return;
- }
-
- std::string port = "";
- std::getline(socketPortStream, port);
- socketPortStream.close();
-
- int portInt = 0;
- try {
- portInt = std::stoi(port.c_str());
- } catch (...) {
- std::cout << "Port not an int?! (2b)";
- return;
- }
-
- if (portInt == 0) {
- std::cout << "Port not an int?! (2c)";
- return;
- }
-
- serverAddress.sin_port = portInt;
-
- if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, sizeof(serverAddress)) < 0) {
- std::cout << "Couldn't connect to port " << port << " (3) Is Hyprland running?";
+ if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) {
+ std::cout << "Couldn't connect to /tmp/hypr/.socket.sock. (3) Is Hyprland running?";
return;
}