diff options
Diffstat (limited to 'client.c')
-rw-r--r-- | client.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -4,16 +4,16 @@ */ #include <stdlib.h> -#include <stdio.h> #include <stdbool.h> #include <unistd.h> +#include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include "protocol.h" #include "client.h" -bool is_server_in_allowed_ips(const char interface[]) +bool is_server_in_allowed_ips(const char iface[]) { /* TODO: check if IP is in wg allowed ips, etc */ return true; @@ -22,21 +22,30 @@ bool is_server_in_allowed_ips(const char interface[]) int connect_to_server() { int sock = -1; + int ret; struct sockaddr_in6 addr; sock = socket(AF_INET6, SOCK_STREAM, 0); + if (sock < 0) { + return -errno; + } addr.sin6_family = AF_INET6; addr.sin6_port = htons(WG_DYNAMIC_SERVER_PORT); inet_pton(AF_INET6, WG_DYNAMIC_SERVER_IP, &addr.sin6_addr); - connect(sock, (struct sockaddr *)&addr, sizeof(addr)); + ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); + if (ret < 0) { + return -errno; + } return sock; } -void close_connection(int sock) +int close_connection(int sock) { - if (close(sock) < 0) { - perror("error closing socket to server"); - exit(EXIT_FAILURE); + int ret; + ret = close(sock); + if (ret < 0) { + return -errno; } + return 0; } |