diff options
-rw-r--r-- | client.c | 38 | ||||
-rw-r--r-- | client.h | 6 | ||||
-rw-r--r-- | protocol.h | 12 |
3 files changed, 52 insertions, 4 deletions
@@ -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); + } } @@ -6,6 +6,10 @@ #ifndef CLIENT_H #define CLIENT_H -int connect_to_server(const char interface[]); +#include <stdbool.h> + +bool is_server_in_allowed_ips(const char interface[]); +int connect_to_server(); +void close_connection(int sock); #endif diff --git a/protocol.h b/protocol.h new file mode 100644 index 0000000..ff6c04d --- /dev/null +++ b/protocol.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright (C) 2018 Wireguard LLC + */ + +#ifndef PROTOCOL_H +#define PROTOCOL_H + +#define WG_DYNAMIC_SERVER_IP "::1" +#define WG_DYNAMIC_SERVER_PORT 51820 + +#endif |