+ +
5797689 fix(windows): resolve MSVC test linkage, missing unistd, and export declarations
saifmukhtar · 2026-11-24
main
| 1 | /* |
| 2 | * SPDX-License-Identifier: AGPL-3.0-or-later WITH Classpath-exception-2.0 |
| 3 | * Copyright (c) 2026 Saif Mukhtar |
| 4 | * |
| 5 | * OpenAVX - Open Audio-Video eXchange |
| 6 | * test/openavx_ipv6_test.c - Exhaustive IPv6 Dual-Stack & RFC 3986 Bracketed URL Test Suite |
| 7 | */ |
| 8 | |
| 9 | #define _GNU_SOURCE |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <assert.h> |
| 14 | #ifndef _WIN32 |
| 15 | #include <unistd.h> |
| 16 | #include <arpa/inet.h> |
| 17 | #include <netinet/in.h> |
| 18 | #include <sys/socket.h> |
| 19 | #endif |
| 20 | |
| 21 | #include "openavx.h" |
| 22 | #include "avx_platform.h" |
| 23 | #include "avx_internal.h" |
| 24 | #include "avx_discovery_server.h" |
| 25 | |
| 26 | #define TEST_IPV6_PORT 8980 |
| 27 | |
| 28 | static void test_ipv6_address_resolution(void) { |
| 29 | printf("[*] 1. Testing IPv6 & Bracketed Address Resolution...\n"); |
| 30 | |
| 31 | char out_ip[64] = {0}; |
| 32 | |
| 33 | /* IPv4 loopback literal */ |
| 34 | bool ok = avx_net_resolve_interface_or_ip("127.0.0.1", out_ip, sizeof(out_ip)); |
| 35 | assert(ok && strcmp(out_ip, "127.0.0.1") == 0); |
| 36 | printf(" [+] IPv4 literal '127.0.0.1' validated: %s\n", out_ip); |
| 37 | |
| 38 | /* IPv6 loopback literal */ |
| 39 | ok = avx_net_resolve_interface_or_ip("::1", out_ip, sizeof(out_ip)); |
| 40 | assert(ok && strcmp(out_ip, "::1") == 0); |
| 41 | printf(" [+] IPv6 literal '::1' validated: %s\n", out_ip); |
| 42 | |
| 43 | /* Bracketed IPv6 literal (RFC 3986) */ |
| 44 | ok = avx_net_resolve_interface_or_ip("[::1]", out_ip, sizeof(out_ip)); |
| 45 | assert(ok && strcmp(out_ip, "::1") == 0); |
| 46 | printf(" [+] Bracketed IPv6 literal '[::1]' unbracketed and validated: %s\n", out_ip); |
| 47 | |
| 48 | /* Loopback interface name 'lo' */ |
| 49 | ok = avx_net_resolve_interface_or_ip("lo", out_ip, sizeof(out_ip)); |
| 50 | assert(ok && out_ip[0] != '\0'); |
| 51 | printf(" [+] Interface 'lo' resolved: %s\n", out_ip); |
| 52 | } |
| 53 | |
| 54 | static void test_dual_stack_tcp_socket(void) { |
| 55 | printf("[*] 2. Testing Dual-Stack TCP Server (IPv4 & IPv6 Ingress on Same Port)...\n"); |
| 56 | |
| 57 | uint16_t port = TEST_IPV6_PORT; |
| 58 | |
| 59 | /* Wildcard bind: creates AF_INET6 socket with IPV6_V6ONLY = 0 */ |
| 60 | avx_socket_t srv_sock = avx_socket_create_tcp_server_bind(NULL, port); |
| 61 | assert(srv_sock != AVX_INVALID_SOCKET); |
| 62 | printf(" [+] Dual-stack server socket active on port %u\n", port); |
| 63 | |
| 64 | /* Client 1 connects via IPv4 loopback 127.0.0.1 */ |
| 65 | avx_socket_t cli_v4 = avx_socket_connect_tcp("127.0.0.1", port); |
| 66 | assert(cli_v4 != AVX_INVALID_SOCKET); |
| 67 | |
| 68 | struct sockaddr_storage addr1; |
| 69 | avx_socklen_t addr1_len = sizeof(addr1); |
| 70 | avx_socket_t accepted_v4 = accept(srv_sock, (struct sockaddr*)&addr1, &addr1_len); |
| 71 | assert(accepted_v4 != AVX_INVALID_SOCKET); |
| 72 | printf(" [+] Accepted IPv4 connection successfully on dual-stack listener!\n"); |
| 73 | |
| 74 | /* Client 2 connects via IPv6 loopback ::1 */ |
| 75 | avx_socket_t cli_v6 = avx_socket_connect_tcp("::1", port); |
| 76 | assert(cli_v6 != AVX_INVALID_SOCKET); |
| 77 | |
| 78 | struct sockaddr_storage addr2; |
| 79 | avx_socklen_t addr2_len = sizeof(addr2); |
| 80 | avx_socket_t accepted_v6 = accept(srv_sock, (struct sockaddr*)&addr2, &addr2_len); |
| 81 | assert(accepted_v6 != AVX_INVALID_SOCKET); |
| 82 | printf(" [+] Accepted IPv6 connection ('::1') successfully on dual-stack listener!\n"); |
| 83 | |
| 84 | /* Client 3 connects via bracketed IPv6 "[::1]" */ |
| 85 | avx_socket_t cli_v6_bracket = avx_socket_connect_tcp("[::1]", port); |
| 86 | assert(cli_v6_bracket != AVX_INVALID_SOCKET); |
| 87 | |
| 88 | struct sockaddr_storage addr3; |
| 89 | avx_socklen_t addr3_len = sizeof(addr3); |
| 90 | avx_socket_t accepted_v6_b = accept(srv_sock, (struct sockaddr*)&addr3, &addr3_len); |
| 91 | assert(accepted_v6_b != AVX_INVALID_SOCKET); |
| 92 | printf(" [+] Accepted bracketed IPv6 connection ('[::1]') successfully!\n"); |
| 93 | |
| 94 | avx_socket_close(cli_v4); |
| 95 | avx_socket_close(accepted_v4); |
| 96 | avx_socket_close(cli_v6); |
| 97 | avx_socket_close(accepted_v6); |
| 98 | avx_socket_close(cli_v6_bracket); |
| 99 | avx_socket_close(accepted_v6_b); |
| 100 | avx_socket_close(srv_sock); |
| 101 | } |
| 102 | |
| 103 | static void test_ipv6_end_to_end_media_stream(void) { |
| 104 | printf("[*] 3. Testing End-to-End OpenAVX Media Stream over IPv6 Loopback...\n"); |
| 105 | |
| 106 | oavx_context_t *ctx = oavx_context_create(); |
| 107 | assert(ctx != NULL); |
| 108 | |
| 109 | /* 1. Create Sender explicitly bound to IPv6 loopback "::1" */ |
| 110 | oavx_stream_config_t tx_cfg = { |
| 111 | .name = "IPV6_STUDIO_CAMERA", |
| 112 | .groups = "public", |
| 113 | .direction = OAVX_DIR_TRANSMIT, |
| 114 | .clock_sync = false, |
| 115 | .bind_ip = "::1" |
| 116 | }; |
| 117 | |
| 118 | oavx_stream_t *tx = oavx_stream_open(ctx, &tx_cfg); |
| 119 | assert(tx != NULL); |
| 120 | |
| 121 | const oavx_endpoint_t *tx_ep = oavx_stream_get_endpoint(tx); |
| 122 | assert(tx_ep != NULL && tx_ep->address != NULL); |
| 123 | printf(" [+] Sender URL formatted: %s\n", tx_ep->address); |
| 124 | assert(strstr(tx_ep->address, "[::1]") != NULL); |
| 125 | |
| 126 | /* 2. Create Receiver connected to "[::1]:<port>" */ |
| 127 | oavx_stream_config_t rx_cfg = { |
| 128 | .name = "IPV6_VIEWER", |
| 129 | .endpoint = tx_ep->address, |
| 130 | .direction = OAVX_DIR_RECEIVE, |
| 131 | .color_format = OAVX_COLOR_FORMAT_UYVY_BGRA, |
| 132 | .bandwidth = OAVX_BANDWIDTH_HIGHEST, |
| 133 | .clock_sync = false |
| 134 | }; |
| 135 | |
| 136 | oavx_stream_t *rx = oavx_stream_open(ctx, &rx_cfg); |
| 137 | assert(rx != NULL); |
| 138 | |
| 139 | /* Wait briefly for connection */ |
| 140 | int conns = 0; |
| 141 | for (int i = 0; i < 20; ++i) { |
| 142 | conns = oavx_stream_get_connection_count(tx, 50); |
| 143 | if (conns > 0) break; |
| 144 | } |
| 145 | printf(" [+] Active connections on sender: %d\n", conns); |
| 146 | assert(conns >= 1); |
| 147 | |
| 148 | /* Send Video Frame (320x240 UYVY) */ |
| 149 | size_t v_bytes = 320 * 240 * 2; |
| 150 | uint8_t* v_buf = (uint8_t*)malloc(v_bytes); |
| 151 | assert(v_buf != NULL); |
| 152 | memset(v_buf, 0x5A, v_bytes); |
| 153 | |
| 154 | oavx_video_frame_t vf = { |
| 155 | .width = 320, |
| 156 | .height = 240, |
| 157 | .fourcc = OAVX_FOURCC_VIDEO_TYPE_UYVY, |
| 158 | .scan_type = OAVX_SCAN_PROGRESSIVE, |
| 159 | .framerate = { 60000, 1000 }, |
| 160 | .aspect_ratio = { 16, 9 }, |
| 161 | .pts_ns = 123456789LL, |
| 162 | .planes = { v_buf, NULL, NULL, NULL }, |
| 163 | .strides = { 320 * 2, 0, 0, 0 } |
| 164 | }; |
| 165 | |
| 166 | /* Send Audio Frame (48kHz stereo, 480 samples) */ |
| 167 | float a_l[480], a_r[480]; |
| 168 | for (int i = 0; i < 480; ++i) { |
| 169 | a_l[i] = 0.75f; |
| 170 | a_r[i] = -0.75f; |
| 171 | } |
| 172 | oavx_audio_frame_t af = { |
| 173 | .sample_rate = 48000, |
| 174 | .channels = 2, |
| 175 | .frames = 480, |
| 176 | .format = OAVX_AUDIO_FMT_FLT_PLANAR, |
| 177 | .stride_bytes = 480 * sizeof(float), |
| 178 | .pts_ns = 123456789LL, |
| 179 | .planes = { (uint8_t*)a_l, (uint8_t*)a_r, NULL, NULL, NULL, NULL, NULL, NULL } |
| 180 | }; |
| 181 | |
| 182 | /* Send video and audio */ |
| 183 | oavx_stream_send_video(tx, &vf); |
| 184 | oavx_stream_send_audio(tx, &af); |
| 185 | |
| 186 | /* Capture video and audio on receiver */ |
| 187 | oavx_video_frame_t rx_vf; |
| 188 | oavx_audio_frame_t rx_af; |
| 189 | oavx_metadata_frame_t rx_mf; |
| 190 | bool got_video = false; |
| 191 | bool got_audio = false; |
| 192 | |
| 193 | for (int attempts = 0; attempts < 100 && (!got_video || !got_audio); ++attempts) { |
| 194 | oavx_frame_type_t ft = oavx_stream_receive(rx, &rx_vf, &rx_af, &rx_mf, 100); |
| 195 | if (ft == OAVX_FRAME_TYPE_VIDEO && !got_video) { |
| 196 | assert(rx_vf.width == 320 && rx_vf.height == 240); |
| 197 | assert(rx_vf.planes[0] != NULL); |
| 198 | assert(rx_vf.planes[0][0] == 0x5A); |
| 199 | printf(" [+] Captured video frame across IPv6 loopback with 100%% data integrity!\n"); |
| 200 | oavx_stream_release_video(rx, &rx_vf); |
| 201 | got_video = true; |
| 202 | } else if (ft == OAVX_FRAME_TYPE_AUDIO && !got_audio) { |
| 203 | float* samples = (float*)rx_af.planes[0]; |
| 204 | assert(rx_af.sample_rate == 48000 && rx_af.channels == 2); |
| 205 | assert(rx_af.frames == 480); |
| 206 | assert(samples != NULL && samples[0] == 0.75f); |
| 207 | printf(" [+] Captured audio frame across IPv6 loopback!\n"); |
| 208 | oavx_stream_release_audio(rx, &rx_af); |
| 209 | got_audio = true; |
| 210 | } |
| 211 | if (!got_video) oavx_stream_send_video(tx, &vf); |
| 212 | if (!got_audio) oavx_stream_send_audio(tx, &af); |
| 213 | } |
| 214 | assert(got_video); |
| 215 | assert(got_audio); |
| 216 | |
| 217 | /* Teardown */ |
| 218 | oavx_stream_close(rx); |
| 219 | oavx_stream_close(tx); |
| 220 | oavx_context_destroy(ctx); |
| 221 | free(v_buf); |
| 222 | } |
| 223 | |
| 224 | static void test_ipv6_end_to_end_rudp_stream(void) { |
| 225 | printf("[*] 4. Testing End-to-End Media Stream over Native IPv6 with RUDP Transport...\n"); |
| 226 | |
| 227 | oavx_context_t *ctx = oavx_context_create(); |
| 228 | assert(ctx != NULL); |
| 229 | |
| 230 | /* Create Sender in RUDP mode bound to IPv6 loopback "::1" */ |
| 231 | oavx_stream_config_t tx_cfg = { |
| 232 | .name = "IPV6_RUDP_STUDIO", |
| 233 | .groups = "public", |
| 234 | .direction = OAVX_DIR_TRANSMIT, |
| 235 | .transport = OAVX_TRANSPORT_RUDP, |
| 236 | .clock_sync = false, |
| 237 | .bind_ip = "::1" |
| 238 | }; |
| 239 | |
| 240 | oavx_stream_t *tx = oavx_stream_open(ctx, &tx_cfg); |
| 241 | assert(tx != NULL); |
| 242 | |
| 243 | const oavx_endpoint_t *tx_ep = oavx_stream_get_endpoint(tx); |
| 244 | assert(tx_ep != NULL && tx_ep->address != NULL); |
| 245 | printf(" [+] RUDP Sender URL: %s\n", tx_ep->address); |
| 246 | |
| 247 | /* Create Receiver connected to "[::1]:<port>" via RUDP */ |
| 248 | oavx_stream_config_t rx_cfg = { |
| 249 | .name = "IPV6_RUDP_VIEWER", |
| 250 | .endpoint = tx_ep->address, |
| 251 | .direction = OAVX_DIR_RECEIVE, |
| 252 | .transport = OAVX_TRANSPORT_RUDP, |
| 253 | .color_format = OAVX_COLOR_FORMAT_UYVY_BGRA, |
| 254 | .bandwidth = OAVX_BANDWIDTH_HIGHEST, |
| 255 | .clock_sync = false |
| 256 | }; |
| 257 | |
| 258 | oavx_stream_t *rx = oavx_stream_open(ctx, &rx_cfg); |
| 259 | assert(rx != NULL); |
| 260 | |
| 261 | /* Wait for RUDP handshake */ |
| 262 | avx_sleep_ms(150); |
| 263 | |
| 264 | /* Send Video Frame (320x240 UYVY) */ |
| 265 | size_t v_bytes = 320 * 240 * 2; |
| 266 | uint8_t* v_buf = (uint8_t*)malloc(v_bytes); |
| 267 | assert(v_buf != NULL); |
| 268 | memset(v_buf, 0x7E, v_bytes); |
| 269 | |
| 270 | oavx_video_frame_t vf = { |
| 271 | .width = 320, |
| 272 | .height = 240, |
| 273 | .fourcc = OAVX_FOURCC_VIDEO_TYPE_UYVY, |
| 274 | .scan_type = OAVX_SCAN_PROGRESSIVE, |
| 275 | .framerate = { 60000, 1000 }, |
| 276 | .aspect_ratio = { 16, 9 }, |
| 277 | .pts_ns = 987654321LL, |
| 278 | .planes = { v_buf, NULL, NULL, NULL }, |
| 279 | .strides = { 320 * 2, 0, 0, 0 } |
| 280 | }; |
| 281 | |
| 282 | oavx_stream_send_video(tx, &vf); |
| 283 | |
| 284 | /* Capture video on receiver */ |
| 285 | oavx_video_frame_t rx_vf; |
| 286 | bool got_video = false; |
| 287 | |
| 288 | for (int attempts = 0; attempts < 100 && !got_video; ++attempts) { |
| 289 | oavx_frame_type_t ft = oavx_stream_receive(rx, &rx_vf, NULL, NULL, 100); |
| 290 | if (ft == OAVX_FRAME_TYPE_VIDEO) { |
| 291 | assert(rx_vf.width == 320 && rx_vf.height == 240); |
| 292 | assert(rx_vf.planes[0] != NULL); |
| 293 | assert(rx_vf.planes[0][0] == 0x7E); |
| 294 | printf(" [+] Captured video frame across IPv6 RUDP with 100%% byte integrity!\n"); |
| 295 | oavx_stream_release_video(rx, &rx_vf); |
| 296 | got_video = true; |
| 297 | } else { |
| 298 | oavx_stream_send_video(tx, &vf); |
| 299 | } |
| 300 | } |
| 301 | assert(got_video); |
| 302 | |
| 303 | oavx_stream_close(rx); |
| 304 | oavx_stream_close(tx); |
| 305 | oavx_context_destroy(ctx); |
| 306 | free(v_buf); |
| 307 | } |
| 308 | |
| 309 | static void test_ipv6_discovery_server(void) { |
| 310 | printf("[*] 5. Testing Centralized Discovery Server over IPv6 ('::1')...\n"); |
| 311 | |
| 312 | uint16_t ds_port = TEST_IPV6_PORT + 4; |
| 313 | avx_discovery_server_t* srv = avx_discovery_server_create("::1", ds_port); |
| 314 | assert(srv != NULL); |
| 315 | |
| 316 | /* Register source via IPv6 */ |
| 317 | int reg_fd = avx_discovery_client_register("::1", ds_port, "IPV6_CAM_MAIN", "[::1]:7980", "production"); |
| 318 | assert(reg_fd >= 0); |
| 319 | printf(" [+] Registered source 'IPV6_CAM_MAIN' at '[::1]:7980' via IPv6\n"); |
| 320 | |
| 321 | /* Query sources via IPv6 */ |
| 322 | char names[8][256]; |
| 323 | char urls[8][256]; |
| 324 | int count = avx_discovery_client_query("::1", ds_port, names, urls, 8); |
| 325 | assert(count == 1); |
| 326 | assert(strcmp(names[0], "IPV6_CAM_MAIN") == 0); |
| 327 | assert(strcmp(urls[0], "[::1]:7980") == 0); |
| 328 | printf(" [+] Queried source catalog via IPv6: %s -> %s\n", names[0], urls[0]); |
| 329 | |
| 330 | avx_socket_close(reg_fd); |
| 331 | avx_discovery_server_destroy(srv); |
| 332 | } |
| 333 | |
| 334 | static void test_ipv6_udp_transport(void) { |
| 335 | printf("[*] 6. Testing Native IPv6 UDP Datagram Transmission & Fragmentation...\n"); |
| 336 | |
| 337 | uint16_t rx_port = TEST_IPV6_PORT + 10; |
| 338 | uint16_t tx_port = TEST_IPV6_PORT + 11; |
| 339 | |
| 340 | avx_socket_t rx_sock = avx_udp_create_socket_bind("::1", rx_port, true); |
| 341 | avx_socket_t tx_sock = avx_udp_create_socket_bind("::1", tx_port, true); |
| 342 | assert(rx_sock != AVX_INVALID_SOCKET && tx_sock != AVX_INVALID_SOCKET); |
| 343 | |
| 344 | struct sockaddr_in6 rx_addr; |
| 345 | memset(&rx_addr, 0, sizeof(rx_addr)); |
| 346 | rx_addr.sin6_family = AF_INET6; |
| 347 | rx_addr.sin6_port = htons(rx_port); |
| 348 | inet_pton(AF_INET6, "::1", &rx_addr.sin6_addr); |
| 349 | |
| 350 | /* Generate 64 KB test payload */ |
| 351 | size_t payload_len = 64 * 1024; |
| 352 | uint8_t *tx_data = (uint8_t*)malloc(payload_len); |
| 353 | uint8_t *rx_data = (uint8_t*)malloc(payload_len + 4096); |
| 354 | assert(tx_data && rx_data); |
| 355 | |
| 356 | for (size_t i = 0; i < payload_len; ++i) { |
| 357 | tx_data[i] = (uint8_t)((i * 31 + 7) & 0xFF); |
| 358 | } |
| 359 | |
| 360 | uint32_t seq = 201; |
| 361 | uint32_t fourcc = 0x32514853; /* 'SHQ2' */ |
| 362 | int64_t tc = 987654321LL; |
| 363 | |
| 364 | int send_ret = avx_udp_send_frame(tx_sock, &rx_addr, seq, fourcc, tc, tx_data, payload_len); |
| 365 | assert(send_ret == 0); |
| 366 | |
| 367 | size_t rx_size = 0; |
| 368 | uint32_t rx_fourcc = 0; |
| 369 | int64_t rx_tc = 0; |
| 370 | |
| 371 | int recv_ret = avx_udp_recv_frame(rx_sock, rx_data, payload_len + 4096, |
| 372 | &rx_size, &rx_fourcc, &rx_tc, 1000); |
| 373 | assert(recv_ret == 0); |
| 374 | assert(rx_size == payload_len); |
| 375 | assert(rx_fourcc == fourcc); |
| 376 | assert(rx_tc == tc); |
| 377 | assert(memcmp(tx_data, rx_data, payload_len) == 0); |
| 378 | |
| 379 | printf(" [+] Native IPv6 UDP loopback: %zu bytes reassembled with 100%% byte integrity!\n", rx_size); |
| 380 | |
| 381 | avx_socket_close(rx_sock); |
| 382 | avx_socket_close(tx_sock); |
| 383 | free(tx_data); |
| 384 | free(rx_data); |
| 385 | } |
| 386 | |
| 387 | static void test_ipv6_rudp_transport(void) { |
| 388 | printf("[*] 7. Testing Native IPv6 RUDP & Selective NACK ARQ Transport...\n"); |
| 389 | |
| 390 | uint16_t rx_port = TEST_IPV6_PORT + 12; |
| 391 | uint16_t tx_port = TEST_IPV6_PORT + 13; |
| 392 | |
| 393 | avx_socket_t rx_sock = avx_udp_create_socket_bind("::1", rx_port, true); |
| 394 | avx_socket_t tx_sock = avx_udp_create_socket_bind("::1", tx_port, true); |
| 395 | assert(rx_sock != AVX_INVALID_SOCKET && tx_sock != AVX_INVALID_SOCKET); |
| 396 | |
| 397 | avx_udp_rudp_sender_t* s = avx_udp_rudp_sender_create(tx_sock, 8); |
| 398 | avx_udp_rudp_receiver_t* r = avx_udp_rudp_receiver_create(rx_sock); |
| 399 | assert(s && r); |
| 400 | |
| 401 | struct sockaddr_in6 rx_addr; |
| 402 | memset(&rx_addr, 0, sizeof(rx_addr)); |
| 403 | rx_addr.sin6_family = AF_INET6; |
| 404 | rx_addr.sin6_port = htons(rx_port); |
| 405 | inet_pton(AF_INET6, "::1", &rx_addr.sin6_addr); |
| 406 | |
| 407 | struct sockaddr_in6 tx_addr; |
| 408 | memset(&tx_addr, 0, sizeof(tx_addr)); |
| 409 | tx_addr.sin6_family = AF_INET6; |
| 410 | tx_addr.sin6_port = htons(tx_port); |
| 411 | inet_pton(AF_INET6, "::1", &tx_addr.sin6_addr); |
| 412 | |
| 413 | /* Generate 128 KB test payload */ |
| 414 | size_t payload_len = 128 * 1024; |
| 415 | uint8_t *tx_data = (uint8_t*)malloc(payload_len); |
| 416 | uint8_t *rx_data = (uint8_t*)malloc(payload_len + 4096); |
| 417 | assert(tx_data && rx_data); |
| 418 | |
| 419 | for (size_t i = 0; i < payload_len; ++i) { |
| 420 | tx_data[i] = (uint8_t)((i * 47 + 19) & 0xFF); |
| 421 | } |
| 422 | |
| 423 | uint32_t seq = 301; |
| 424 | uint32_t fourcc = 0x32514853; /* 'SHQ2' */ |
| 425 | int64_t tc = 1122334455LL; |
| 426 | |
| 427 | int send_ret = avx_udp_rudp_send_frame(s, &rx_addr, seq, fourcc, tc, tx_data, payload_len); |
| 428 | assert(send_ret == 0); |
| 429 | |
| 430 | size_t rx_size = 0; |
| 431 | uint32_t rx_fourcc = 0; |
| 432 | int64_t rx_tc = 0; |
| 433 | |
| 434 | int recv_ret = avx_udp_rudp_recv_frame(r, &tx_addr, rx_data, payload_len + 4096, |
| 435 | &rx_size, &rx_fourcc, &rx_tc, 1000); |
| 436 | assert(recv_ret == 0); |
| 437 | assert(rx_size == payload_len); |
| 438 | assert(rx_fourcc == fourcc); |
| 439 | assert(rx_tc == tc); |
| 440 | assert(memcmp(tx_data, rx_data, payload_len) == 0); |
| 441 | |
| 442 | printf(" [+] Native IPv6 RUDP transfer: %zu bytes reassembled with 100%% byte integrity!\n", rx_size); |
| 443 | |
| 444 | avx_udp_rudp_sender_destroy(s); |
| 445 | avx_udp_rudp_receiver_destroy(r); |
| 446 | avx_socket_close(rx_sock); |
| 447 | avx_socket_close(tx_sock); |
| 448 | free(tx_data); |
| 449 | free(rx_data); |
| 450 | } |
| 451 | |
| 452 | static void test_multicast_membership(void) { |
| 453 | printf("[*] 8. Testing Multicast Group Joins & Leaves (IGMP / MLD)...\n"); |
| 454 | |
| 455 | /* Create non-blocking socket */ |
| 456 | avx_socket_t sock = avx_udp_create_socket(0, true); |
| 457 | assert(sock != AVX_INVALID_SOCKET); |
| 458 | |
| 459 | /* Test TTL and Loopback configuration */ |
| 460 | bool ok = avx_udp_set_multicast_ttl(sock, 8); |
| 461 | assert(ok); |
| 462 | printf(" [+] Set Multicast TTL / Hops to 8\n"); |
| 463 | |
| 464 | ok = avx_udp_set_multicast_loop(sock, true); |
| 465 | assert(ok); |
| 466 | printf(" [+] Enabled Multicast Loopback\n"); |
| 467 | |
| 468 | /* Test IPv4 Multicast Join / Leave */ |
| 469 | ok = avx_udp_join_multicast(sock, "239.255.0.1", NULL); |
| 470 | assert(ok); |
| 471 | printf(" [+] Joined IPv4 Multicast Group 239.255.0.1 (IGMPv3)\n"); |
| 472 | |
| 473 | ok = avx_udp_leave_multicast(sock, "239.255.0.1", NULL); |
| 474 | assert(ok); |
| 475 | printf(" [+] Left IPv4 Multicast Group 239.255.0.1\n"); |
| 476 | |
| 477 | /* Test IPv6 Multicast Join / Leave (BSD/macOS requires AF_INET6 socket for IPv6 multicast) */ |
| 478 | avx_socket_t sock_v6 = sock; |
| 479 | #if defined(AVX_OS_MACOS) || defined(AVX_OS_BSD) |
| 480 | sock_v6 = avx_udp_create_socket_bind("::", 0, true); |
| 481 | assert(sock_v6 != AVX_INVALID_SOCKET); |
| 482 | #endif |
| 483 | |
| 484 | ok = avx_udp_join_multicast(sock_v6, "ff02::1", NULL); |
| 485 | assert(ok); |
| 486 | printf(" [+] Joined IPv6 Multicast Group ff02::1 (MLDv2)\n"); |
| 487 | |
| 488 | ok = avx_udp_leave_multicast(sock_v6, "ff02::1", NULL); |
| 489 | assert(ok); |
| 490 | printf(" [+] Left IPv6 Multicast Group ff02::1\n"); |
| 491 | |
| 492 | /* Test bracketed IPv6 multicast address */ |
| 493 | ok = avx_udp_join_multicast(sock_v6, "[ff02::1]", NULL); |
| 494 | assert(ok); |
| 495 | ok = avx_udp_leave_multicast(sock_v6, "[ff02::1]", NULL); |
| 496 | assert(ok); |
| 497 | printf(" [+] Joined and left bracketed IPv6 Multicast '[ff02::1]'\n"); |
| 498 | |
| 499 | #if defined(AVX_OS_MACOS) || defined(AVX_OS_BSD) |
| 500 | if (sock_v6 != sock) { |
| 501 | avx_socket_close(sock_v6); |
| 502 | } |
| 503 | #endif |
| 504 | |
| 505 | /* Test invalid multicast addresses */ |
| 506 | assert(!avx_udp_join_multicast(sock, "192.168.1.1", NULL)); |
| 507 | assert(!avx_udp_join_multicast(sock, "2001:db8::1", NULL)); |
| 508 | assert(!avx_udp_join_multicast(sock, "invalid-ip", NULL)); |
| 509 | printf(" [+] Invalid multicast addresses safely rejected\n"); |
| 510 | |
| 511 | avx_socket_close(sock); |
| 512 | } |
| 513 | |
| 514 | int main(void) { |
| 515 | printf("=== OpenAVX IPv6 Dual-Stack Transport Tests ===\n\n"); |
| 516 | |
| 517 | test_ipv6_address_resolution(); |
| 518 | test_dual_stack_tcp_socket(); |
| 519 | test_ipv6_end_to_end_media_stream(); |
| 520 | test_ipv6_end_to_end_rudp_stream(); |
| 521 | test_ipv6_discovery_server(); |
| 522 | test_ipv6_udp_transport(); |
| 523 | test_ipv6_rudp_transport(); |
| 524 | test_multicast_membership(); |
| 525 | |
| 526 | printf("\n[PASS] openavx_ipv6_test\n"); |
| 527 | return 0; |
| 528 | } |