aboutsummaryrefslogtreecommitdiffstats
path: root/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'client.c')
-rw-r--r--client.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/client.c b/client.c
index 2c2f091..1a839b9 100644
--- a/client.c
+++ b/client.c
@@ -3,8 +3,40 @@
* Copyright (C) 2018 Wireguard LLC
*/
-int connect_to_server(const char interface[])
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <unistd.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[])
+{
+ /* TODO: check if IP is in wg allowed ips, etc */
+ return true;
+}
+
+int connect_to_server()
+{
+ int sock = -1;
+ struct sockaddr_in6 addr;
+
+ sock = socket(AF_INET6, SOCK_STREAM, 0);
+ 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));
+
+ return sock;
+}
+
+void close_connection(int sock)
{
- /* TODO */
- return -1;
+ if (close(sock) < 0) {
+ perror("error closing socket to server");
+ exit(EXIT_FAILURE);
+ }
}