diff options
-rw-r--r-- | src/testing/Makefile.am | 10 | ||||
-rw-r--r-- | src/testing/bindfail.c | 35 | ||||
-rw-r--r-- | src/testing/bindok.c | 30 |
3 files changed, 75 insertions, 0 deletions
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index b028e1ab1..4f1d8fe17 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am | |||
@@ -101,3 +101,13 @@ test_testing_sharedservices_LDADD = \ | |||
101 | 101 | ||
102 | EXTRA_DIST = \ | 102 | EXTRA_DIST = \ |
103 | test_testing_defaults.conf | 103 | test_testing_defaults.conf |
104 | |||
105 | |||
106 | noinst_PROGRAMS = \ | ||
107 | bindfail bindok | ||
108 | |||
109 | bindok_SOURCES = bindok.c | ||
110 | |||
111 | bindfail_SOURCES = bindfail.c | ||
112 | bindfail_LDADD = $(top_builddir)/src/util/libgnunetutil.la | ||
113 | |||
diff --git a/src/testing/bindfail.c b/src/testing/bindfail.c new file mode 100644 index 000000000..7ff7c6138 --- /dev/null +++ b/src/testing/bindfail.c | |||
@@ -0,0 +1,35 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_util_lib.h" | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | uint16_t port = 12035; | ||
7 | struct GNUNET_NETWORK_Handle *sock1; | ||
8 | struct GNUNET_NETWORK_Handle *sock2; | ||
9 | struct sockaddr_in addr; | ||
10 | |||
11 | (void) memset (&addr, 0, sizeof (struct sockaddr_in)); | ||
12 | sock1 = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); | ||
13 | sock2 = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); | ||
14 | |||
15 | addr.sin_port = htons (port); | ||
16 | addr.sin_addr.s_addr = INADDR_ANY; | ||
17 | |||
18 | if (GNUNET_SYSERR == | ||
19 | GNUNET_NETWORK_socket_bind (sock1, (const struct sockaddr *) &addr, | ||
20 | sizeof (addr), 0)) | ||
21 | { | ||
22 | fprintf (stderr, "first bind failed. check port\n"); | ||
23 | return 1; | ||
24 | } | ||
25 | if (GNUNET_SYSERR == | ||
26 | GNUNET_NETWORK_socket_bind (sock2, (const struct sockaddr *) &addr, | ||
27 | sizeof (addr), 0)) | ||
28 | { | ||
29 | printf ("All OK\n"); | ||
30 | return 0; | ||
31 | } | ||
32 | fprintf (stderr, "Second bind succeeded! WTF!!\n"); | ||
33 | fgetc (stdin); | ||
34 | return 1; | ||
35 | } | ||
diff --git a/src/testing/bindok.c b/src/testing/bindok.c new file mode 100644 index 000000000..a4b74e7a0 --- /dev/null +++ b/src/testing/bindok.c | |||
@@ -0,0 +1,30 @@ | |||
1 | #include "platform.h" | ||
2 | |||
3 | int main() | ||
4 | { | ||
5 | uint16_t port = 12035; | ||
6 | int sock1; | ||
7 | int sock2; | ||
8 | struct sockaddr_in addr; | ||
9 | |||
10 | (void) memset (&addr, 0, sizeof (struct sockaddr_in)); | ||
11 | sock1 = socket (AF_INET, SOCK_DGRAM, 0); | ||
12 | sock2 = socket (AF_INET, SOCK_DGRAM, 0); | ||
13 | |||
14 | addr.sin_port = htons (port); | ||
15 | addr.sin_addr.s_addr = INADDR_ANY; | ||
16 | |||
17 | if (0 != bind (sock1, (const struct sockaddr *) &addr, sizeof (addr))) | ||
18 | { | ||
19 | perror ("bind"); | ||
20 | return 1; | ||
21 | } | ||
22 | if (0 != bind (sock2, (const struct sockaddr *) &addr, sizeof (addr))) | ||
23 | { | ||
24 | printf ("All OK\n"); | ||
25 | return 0; | ||
26 | } | ||
27 | fprintf (stderr, "Second bind succeeded! WTF!!\n"); | ||
28 | fgetc (stdin); | ||
29 | return 1; | ||
30 | } | ||