-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
+/*
+ utcp-test.c -- Test application for UTCP
+ Copyright (C) 2014-2020 Guus Sliepen <guus@tinc-vpn.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "system.h"
#include <poll.h>
-
+#include <time.h>
#include "utcp.h"
#define debug(...) do {} while(0)
#endif
-static ssize_t do_recv(struct utcp_connection *c, const void *data, size_t len) {
- (void)c;
+static ssize_t do_recv(struct utcp_connection *rc, const void *data, size_t len) {
+ (void)rc;
if(!data || !len) {
if(errno) {
c = nc;
if(bufsize) {
- utcp_set_sndbuf(c, bufsize);
- utcp_set_rcvbuf(c, bufsize);
+ utcp_set_sndbuf(c, NULL, bufsize);
+ utcp_set_rcvbuf(c, NULL, bufsize);
}
utcp_set_accept_cb(c->utcp, NULL, NULL);
}
static void set_mtu(struct utcp *u, int s) {
+#ifdef IP_MTU
+
if(!mtu) {
socklen_t optlen = sizeof(mtu);
getsockopt(s, IPPROTO_IP, IP_MTU, &mtu, &optlen);
}
+#else
+ (void)s;
+#endif
+
if(!mtu || mtu == 65535) {
mtu = 1500;
}
return 1;
}
} else {
+#ifdef SO_NOSIGPIPE
+ int nosigpipe = 1;
+ setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &nosigpipe, sizeof(nosigpipe));
+#endif
+
if(connect(s, ai->ai_addr, ai->ai_addrlen)) {
debug("Could not connect: %s\n", strerror(errno));
return 1;
c = utcp_connect_ex(u, 1, do_recv, NULL, flags);
if(bufsize) {
- utcp_set_sndbuf(c, bufsize);
- utcp_set_rcvbuf(c, bufsize);
+ utcp_set_sndbuf(c, NULL, bufsize);
+ utcp_set_rcvbuf(c, NULL, bufsize);
}
}