1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-12-22 04:02:04 +03:00

Try CI tests for IPv6

This commit is contained in:
bel
2015-07-31 21:38:13 +02:00
parent a2906702ca
commit b904a49127
2 changed files with 68 additions and 17 deletions

View File

@@ -4891,6 +4891,7 @@ static SOCKET conn2(struct mg_context *ctx /* may be null */,
size_t ebuf_len) size_t ebuf_len)
{ {
union usa sa; union usa sa;
int ip_ver = 0;
SOCKET sock = INVALID_SOCKET; SOCKET sock = INVALID_SOCKET;
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
@@ -4931,9 +4932,11 @@ static SOCKET conn2(struct mg_context *ctx /* may be null */,
if (mg_inet_pton(AF_INET, host, &sa.sin, sizeof(sa.sin))) { if (mg_inet_pton(AF_INET, host, &sa.sin, sizeof(sa.sin))) {
sa.sin.sin_port = htons((uint16_t)port); sa.sin.sin_port = htons((uint16_t)port);
ip_ver = 4;
#ifdef USE_IPV6 #ifdef USE_IPV6
} else if (mg_inet_pton(AF_INET6, host, &sa.sin6, sizeof(sa.sin6))) { } else if (mg_inet_pton(AF_INET6, host, &sa.sin6, sizeof(sa.sin6))) {
sa.sin6.sin6_port = htons((uint16_t)port); sa.sin6.sin6_port = htons((uint16_t)port);
ip_ver = 6;
#endif #endif
} else { } else {
mg_snprintf(NULL, mg_snprintf(NULL,
@@ -4945,7 +4948,11 @@ static SOCKET conn2(struct mg_context *ctx /* may be null */,
return INVALID_SOCKET; return INVALID_SOCKET;
} }
sock = socket(PF_INET, SOCK_STREAM, 0); if (ip_ver == 4) {
sock = socket(PF_INET, SOCK_STREAM, 0);
} else if (ip_ver == 6) {
sock = socket(PF_INET6, SOCK_STREAM, 0);
}
if (sock == INVALID_SOCKET) { if (sock == INVALID_SOCKET) {
mg_snprintf(NULL, mg_snprintf(NULL,
@@ -4959,21 +4966,29 @@ static SOCKET conn2(struct mg_context *ctx /* may be null */,
set_close_on_exec(sock, fc(ctx)); set_close_on_exec(sock, fc(ctx));
/* TODO(mid): IPV6 */ if ((ip_ver == 4) &&
if (connect(sock, (struct sockaddr *)&sa.sin, sizeof(sa.sin)) != 0) { (connect(sock, (struct sockaddr *)&sa.sin, sizeof(sa.sin)) == 0)) {
mg_snprintf(NULL, /* connected with IPv4 */
NULL, /* No truncation check for ebuf */ return sock;
ebuf,
ebuf_len,
"connect(%s:%d): %s",
host,
port,
strerror(ERRNO));
closesocket(sock);
sock = INVALID_SOCKET;
} }
return sock; if ((ip_ver == 6) &&
(connect(sock, (struct sockaddr *)&sa.sin6, sizeof(sa.sin6)) == 0)) {
/* connected with IPv6 */
return sock;
}
/* Not connected */
mg_snprintf(NULL,
NULL, /* No truncation check for ebuf */
ebuf,
ebuf_len,
"connect(%s:%d): %s",
host,
port,
strerror(ERRNO));
closesocket(sock);
return INVALID_SOCKET;
} }
int mg_url_encode(const char *src, char *dst, size_t dst_len) int mg_url_encode(const char *src, char *dst, size_t dst_len)

View File

@@ -519,7 +519,11 @@ START_TEST(test_request_handlers)
char buf[1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 8]; char buf[1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 8];
int i; int i;
const char *request = "GET /U7 HTTP/1.0\r\n\r\n"; const char *request = "GET /U7 HTTP/1.0\r\n\r\n";
const char *HTTP_PORT = "8087"; #ifdef USE_IPV6
const char *HTTP_PORT = "8084,[::]:8086";
#else
const char *HTTP_PORT = "8084";
#endif
const char *OPTIONS[8]; /* initializer list here is rejected by CI test */ const char *OPTIONS[8]; /* initializer list here is rejected by CI test */
const char *opt; const char *opt;
FILE *f; FILE *f;
@@ -595,6 +599,32 @@ START_TEST(test_request_handlers)
mg_close_connection(conn); mg_close_connection(conn);
/* Get data from callback using 127.0.0.1 */
conn = mg_download(
"127.0.0.1", atoi(HTTP_PORT), 0, ebuf, sizeof(ebuf), "%s", request);
ck_assert(conn != NULL);
ri = mg_get_request_info(conn);
ck_assert(ri != NULL);
ck_assert_str_eq(ri->uri, "200");
i = mg_read(conn, buf, sizeof(buf));
ck_assert_int_eq(i, 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10);
mg_close_connection(conn);
/* Get data from callback using [::1] */
conn = mg_download(
"[::1]", atoi(HTTP_PORT), 0, ebuf, sizeof(ebuf), "%s", request);
ck_assert(conn != NULL);
ri = mg_get_request_info(conn);
ck_assert(ri != NULL);
ck_assert_str_eq(ri->uri, "200");
i = mg_read(conn, buf, sizeof(buf));
ck_assert_int_eq(i, 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10);
mg_close_connection(conn);
/* It seems to be impossible to find out what the actual working /* It seems to be impossible to find out what the actual working
* directory of the CI test environment is. Before breaking another * directory of the CI test environment is. Before breaking another
* dozen of builds by trying blindly with different paths, just * dozen of builds by trying blindly with different paths, just
@@ -684,6 +714,8 @@ START_TEST(test_request_handlers)
ck_assert_str_eq(ri->uri, "401"); /* not authorized */ ck_assert_str_eq(ri->uri, "401"); /* not authorized */
mg_close_connection(conn); mg_close_connection(conn);
/* TODO: Test websockets */
/* Close the server */ /* Close the server */
g_ctx = NULL; g_ctx = NULL;
@@ -740,7 +772,7 @@ Suite *make_public_suite(void)
return suite; return suite;
} }
#if 0 #ifdef REPLACE_CHECK_FOR_LOCAL_DEBUGGING
/* Used to debug test cases without using the check framework */ /* Used to debug test cases without using the check framework */
void main(void) void main(void)
{ {
@@ -751,7 +783,11 @@ void main(void)
void _ck_assert_failed(const char *file, int line, const char *expr, ...) void _ck_assert_failed(const char *file, int line, const char *expr, ...)
{ {
fprintf(stderr, "error!\n"); va_list va;
va_start(va, expr);
fprintf(stderr, "Error: %s, line %i\n", file, line); /* breakpoint here ! */
vfprintf(stderr, expr, va);
va_end(va);
} }
void _mark_point(const char *file, int line) {} void _mark_point(const char *file, int line) {}