summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2015-01-06 21:27:14 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2015-01-06 21:30:19 +0100
commitfc7bf0059415757ff67f26c16e5a9f9d55f658a0 (patch)
treeb3a7556255d65163beeddd1f564cd0bfb3f32929 /tests
parent066db0b051a048e005f7bb344621b5ea931aeea3 (diff)
downloadgnutls-fc7bf0059415757ff67f26c16e5a9f9d55f658a0.tar.gz
tests: moved udp_socketpair to utils
Diffstat (limited to 'tests')
-rw-r--r--tests/mini-dtls-mtu.c49
-rw-r--r--tests/utils.c54
-rw-r--r--tests/utils.h2
3 files changed, 56 insertions, 49 deletions
diff --git a/tests/mini-dtls-mtu.c b/tests/mini-dtls-mtu.c
index f6b2586c80..189dff17a4 100644
--- a/tests/mini-dtls-mtu.c
+++ b/tests/mini-dtls-mtu.c
@@ -279,56 +279,7 @@ static void server(int fd)
success("server: finished\n");
}
-static int udp_socket(void)
-{
- int on = 1;
- struct sockaddr_in addr = {
- .sin_family = AF_INET,
- .sin_addr = {htonl(INADDR_LOOPBACK)},
- .sin_port = 0
- };
- int fd;
-
- fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on));
-#if defined(SO_REUSEPORT)
- setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&on, sizeof(on));
-#endif
- if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- perror("bind");
- exit(EXIT_FAILURE);
- }
-
- return fd;
-}
-
-static void udp_connect(int fd1, int fd2)
-{
- struct sockaddr_in addr;
- socklen_t addrlen = sizeof(addr);
-
- if (getsockname(fd1, &addr, &addrlen) < 0) {
- perror("getsockname");
- exit(EXIT_FAILURE);
- }
-
- if (connect(fd2, &addr, addrlen) < 0) {
- perror("connect");
- exit(EXIT_FAILURE);
- }
-}
-
-static int udp_socketpair(int *fd)
-{
- fd[0] = udp_socket();
- fd[1] = udp_socket();
-
- udp_connect(fd[0], fd[1]);
- udp_connect(fd[1], fd[0]);
-
- return 0;
-}
void doit(void)
{
diff --git a/tests/utils.c b/tests/utils.c
index b61321d39a..516cc9d60a 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -27,6 +27,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
#include "utils.h"
@@ -151,3 +154,54 @@ int main(int argc, char *argv[])
return error_count ? 1 : 0;
}
+
+static int udp_socket(void)
+{
+ int on = 1;
+ struct sockaddr_in addr = {
+ .sin_family = AF_INET,
+ .sin_addr = {htonl(INADDR_LOOPBACK)},
+ .sin_port = 0
+ };
+ int fd;
+
+ fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on));
+#if defined(SO_REUSEPORT)
+ setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&on, sizeof(on));
+#endif
+
+ if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+ perror("bind");
+ exit(EXIT_FAILURE);
+ }
+
+ return fd;
+}
+
+static void udp_connect(int fd1, int fd2)
+{
+ struct sockaddr_in addr;
+ socklen_t addrlen = sizeof(addr);
+
+ if (getsockname(fd1, &addr, &addrlen) < 0) {
+ perror("getsockname");
+ exit(EXIT_FAILURE);
+ }
+
+ if (connect(fd2, &addr, addrlen) < 0) {
+ perror("connect");
+ exit(EXIT_FAILURE);
+ }
+}
+
+int udp_socketpair(int *fd)
+{
+ fd[0] = udp_socket();
+ fd[1] = udp_socket();
+
+ udp_connect(fd[0], fd[1]);
+ udp_connect(fd[1], fd[0]);
+
+ return 0;
+}
diff --git a/tests/utils.h b/tests/utils.h
index 7d89e8ce97..feabe3e63f 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -57,6 +57,8 @@ extern void escapeprint(const char *str, size_t len);
extern void hexprint(const void *str, size_t len);
extern void binprint(const void *str, size_t len);
+int udp_socketpair(int *fd);
+
/* This must be implemented elsewhere. */
extern void doit(void);