fix: fixed more net.cpp problems

This commit is contained in:
AfonsoCMSousa 2026-01-07 20:30:33 +00:00
parent 9da9cd3c13
commit 159a93317e
2 changed files with 10 additions and 11 deletions

Binary file not shown.

View File

@ -23,7 +23,7 @@ void Socket::connect_server(const char *ip, uint16_t port) {
// Connect to existing UNIX domain socket (e.g., /tmp/socket_path)
void Socket::connect_unix(const char *ip, uint16_t port) {
sock = socket(AF_UNIX, SOCK_DGRAM, 0);
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
throw std::runtime_error("Failed to create UNIX socket");
}
@ -32,7 +32,7 @@ void Socket::connect_unix(const char *ip, uint16_t port) {
this->server_addr_unix.sun_family = AF_UNIX;
strncpy(this->server_addr_unix.sun_path, ip, sizeof(this->server_addr_unix.sun_path) - 1);
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
if (connect(sock, (struct sockaddr *)&server_addr_unix, sizeof(server_addr_unix)) < 0) {
throw std::runtime_error("Failed to connect to UNIX socket");
}
}
@ -45,10 +45,10 @@ void Socket::send_server() {
}
void Socket::send_unix() {
ssize_t sent_bytes = sendto(sock, &packet_data, sizeof(packet_data), 0, (struct sockaddr *)&server_addr_unix, sizeof(server_addr_unix));
if (sent_bytes < 0) {
throw runtime_error("Failed to send data to UNIX socket");
}
ssize_t sent_bytes = send(sock, &packet_data, sizeof(packet_data), 0);
if (sent_bytes < 0) {
throw runtime_error("Failed to send data to UNIX socket");
}
}
void Socket::send_server(const api_packet &data) {
@ -59,10 +59,10 @@ void Socket::send_server(const api_packet &data) {
}
void Socket::send_unix(const api_packet &data) {
ssize_t sent_bytes = sendto(sock, &data, sizeof(data), 0, (struct sockaddr *)&server_addr_unix, sizeof(server_addr_unix));
if (sent_bytes < 0) {
throw runtime_error("Failed to send data to UNIX socket");
}
ssize_t sent_bytes = send(sock, &data, sizeof(data), 0);
if (sent_bytes < 0) {
throw runtime_error("Failed to send data to UNIX socket");
}
}
void Socket::set_packet(const api_packet &data) {
@ -81,4 +81,3 @@ api_packet Socket::create_packet(uint8_t tracker_id) {
api_packet Socket::get_packet() {
return packet_data;
}