98f2972252
from upstream via tom murphy (maintainer)
111 lines
3.6 KiB
Plaintext
111 lines
3.6 KiB
Plaintext
$OpenBSD: patch-stun_tests_test-bind_c,v 1.2 2009/09/09 22:13:08 jasper Exp $
|
|
--- stun/tests/test-bind.c.orig Tue Mar 31 20:58:55 2009
|
|
+++ stun/tests/test-bind.c Wed Sep 9 16:19:43 2009
|
|
@@ -49,10 +49,6 @@
|
|
#ifdef _WIN32
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
-
|
|
-#define MSG_DONTWAIT 0
|
|
-#define MSG_NOSIGNAL 0
|
|
-
|
|
#define alarm(...)
|
|
#define close closesocket
|
|
#else
|
|
@@ -62,6 +58,11 @@
|
|
#include <netdb.h>
|
|
#endif
|
|
|
|
+#if defined(_WIN32) || defined(__OpenBSD__)
|
|
+#define MSG_DONTWAIT 0
|
|
+#define MSG_NOSIGNAL 0
|
|
+#endif
|
|
+
|
|
#undef NDEBUG /* ensure assertions are built-in */
|
|
#include <assert.h>
|
|
|
|
@@ -216,13 +217,10 @@ static void bad_responses (void)
|
|
val = getsockname (fd, (struct sockaddr *)&addr, &addrlen);
|
|
assert (val == 0);
|
|
|
|
- val = connect (servfd, (struct sockaddr *)&addr, addrlen);
|
|
- assert (val == 0);
|
|
-
|
|
/* Send request instead of response */
|
|
val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen);
|
|
assert (val == 0);
|
|
- len = recv (servfd, buf, 1000, MSG_DONTWAIT);
|
|
+ len = recvfrom (servfd, buf, 1000, MSG_DONTWAIT, NULL, 0);
|
|
assert (len >= 20);
|
|
|
|
assert (stun_agent_validate (&agent, &msg, buf, len, NULL, NULL)
|
|
@@ -283,30 +281,29 @@ static void responses (void)
|
|
fd = socket (addr.ss_family, SOCK_DGRAM, 0);
|
|
assert (fd != -1);
|
|
|
|
- val = connect (fd, (struct sockaddr *)&addr, addrlen);
|
|
- assert (val == 0);
|
|
-
|
|
/* Send to/receive from our client instance only */
|
|
val = getsockname (fd, (struct sockaddr *)&addr, &addrlen);
|
|
assert (val == 0);
|
|
|
|
- val = connect (servfd, (struct sockaddr *)&addr, addrlen);
|
|
- assert (val == 0);
|
|
-
|
|
/* Send error response */
|
|
req_len = stun_usage_bind_create (&agent, &req_msg, req, sizeof(req));
|
|
assert (req_len > 0);
|
|
|
|
- val = send (fd, req, req_len, MSG_DONTWAIT | MSG_NOSIGNAL);
|
|
+ val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen);
|
|
+ assert (val == 0);
|
|
+
|
|
+ val = sendto (fd, req, req_len, MSG_DONTWAIT | MSG_NOSIGNAL,
|
|
+ (struct sockaddr *)&addr, addrlen);
|
|
assert (val >= 0);
|
|
|
|
- val = recv (servfd, buf, 1000, MSG_DONTWAIT);
|
|
+ val = recvfrom (servfd, buf, 1000, MSG_DONTWAIT, NULL, 0);
|
|
assert (val >= 0);
|
|
|
|
assert (stun_agent_validate (&agent, &msg, buf, val, NULL, NULL)
|
|
== STUN_VALIDATION_SUCCESS);
|
|
|
|
- stun_agent_init_error (&agent, &msg, buf, sizeof (buf), &msg, STUN_ERROR_SERVER_ERROR);
|
|
+ stun_agent_init_error (&agent, &msg, buf, sizeof (buf),
|
|
+ &msg, STUN_ERROR_SERVER_ERROR);
|
|
len = stun_agent_finish_message (&agent, &msg, NULL, 0);
|
|
assert (len > 0);
|
|
|
|
@@ -321,7 +318,11 @@ static void responses (void)
|
|
req_len = stun_usage_bind_create (&agent, &req_msg, req, sizeof(req));
|
|
assert (req_len > 0);
|
|
|
|
- val = send (fd, req, req_len, MSG_DONTWAIT | MSG_NOSIGNAL);
|
|
+ val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen);
|
|
+ assert (val == 0);
|
|
+
|
|
+ val = sendto (fd, req, req_len, MSG_DONTWAIT | MSG_NOSIGNAL,
|
|
+ (struct sockaddr *)&addr, addrlen);
|
|
assert (val >= 0);
|
|
|
|
val = recv (servfd, buf, 1000, MSG_DONTWAIT);
|
|
@@ -348,10 +349,14 @@ static void responses (void)
|
|
req_len = stun_usage_bind_create (&agent, &req_msg, req, sizeof(req));
|
|
assert (req_len > 0);
|
|
|
|
- val = send (fd, req, req_len, MSG_DONTWAIT | MSG_NOSIGNAL);
|
|
+ val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen);
|
|
+ assert (val == 0);
|
|
+
|
|
+ val = sendto (fd, req, req_len, MSG_DONTWAIT | MSG_NOSIGNAL,
|
|
+ (struct sockaddr *)&addr, addrlen);
|
|
assert (val >= 0);
|
|
|
|
- val = recv (servfd, buf, 1000, MSG_DONTWAIT);
|
|
+ val = recvfrom (servfd, buf, 1000, MSG_DONTWAIT, NULL, 0);
|
|
assert (val >= 0);
|
|
|
|
assert (stun_agent_validate (&agent, &msg, buf, val, NULL, NULL)
|