commit 5de0432534aa0630523a5de2c7103762336efd10
parent eacb0fc19a4a3bc734ce80ae88d032d41be5fc9c
Author: hhvn <dev@hhvn.uk>
Date: Sat, 16 Jul 2022 11:59:07 +0100
Network handlers: add copyright + clean up
Diffstat:
M | plain.c | | | 37 | ++++++++++++++++++++++++++----------- |
M | tls.c | | | 22 | +++++++++++++++++++++- |
2 files changed, 47 insertions(+), 12 deletions(-)
diff --git a/plain.c b/plain.c
@@ -1,36 +1,51 @@
+/*
+ * zygo/plain.c
+ *
+ * Copyright (c) 2022 hhvn <dev@hhvn.uk>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
#include <unistd.h>
#include <netdb.h>
+#include <sys/socket.h>
#include "zygo.h"
static int fd;
-
-#define net_free() \
- if (ai) freeaddrinfo(ai)
+static struct addrinfo *ai = NULL;
int
net_connect(Elem *e, int silent) {
- struct addrinfo *ai = NULL;
int ret;
+ if (ai)
+ freeaddrinfo(ai);
+
if ((ret = getaddrinfo(e->server, e->port, NULL, &ai)) != 0 || ai == NULL) {
if (!silent)
error("could not lookup %s:%s", e->server, e->port);
- goto fail;
+ return -1;
}
if ((fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1 ||
connect(fd, ai->ai_addr, ai->ai_addrlen) == -1) {
if (!silent)
error("could not connect to %s:%s", e->server, e->port);
- goto fail;
+ return -1;
}
- net_free();
return 0;
-
-fail:
- net_free();
- return -1;
}
int
diff --git a/tls.c b/tls.c
@@ -1,6 +1,26 @@
+/*
+ * zygo/tls.c
+ *
+ * Copyright (c) 2022 hhvn <dev@hhvn.uk>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
#include <unistd.h>
#include <netdb.h>
#include <tls.h>
+#include <sys/socket.h>
#include "zygo.h"
struct tls *ctx = NULL;
@@ -138,7 +158,7 @@ net_close(void) {
if (tls) {
do {
ret = tls_close(ctx);
- } while (ret == TLS_WANT_POLLIN || TLS_WANT_POLLOUT);
+ } while (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT);
tls_free(ctx);
ctx = NULL;
tls_config_free(conf);