63 struct timeval timeout;
76 int status_parent, status_child;
85 (
"Testing UDP/IP networking (IPv4 loopback) ................................ ");
87 s1 =
udp_init(
"127.0.0.1", 5004, 5004, 1, 0,
false);
90 printf(
" Cannot initialize socket\n");
97 perror(
" Cannot send packet");
107 perror(
" Select failed");
112 printf(
" No data waiting\n");
117 printf(
" No data on file descriptor\n");
122 perror(
" Receive failed");
125 if (memcmp(buf1, buf2,
BUFSIZE) != 0) {
127 printf(
" Buffer corrupt\n");
138 (
"Testing UDP/IP networking (IPv4 unicast) ................................. ");
140 s1 =
udp_init(hname, 5004, 5005, 1, 0,
false);
143 printf(
" Cannot initialize socket\n");
147 s2 =
udp_init(hname, 5005, 5004, 1, 0,
false);
150 printf(
" Cannot initialize socket\n");
158 perror(
" Cannot send");
169 perror(
" Select failed");
174 printf(
" No data waiting (no route to %s?)\n", hname);
179 printf(
" No data on file descriptor\n");
184 perror(
" Cannot receive");
187 if (memcmp(buf1, buf2,
BUFSIZE) != 0) {
189 printf(
" Buffer corrupt\n");
198 if (getenv(
"GITHUB_REPOSITORY")) {
199 printf(
"Testing UDP/IP networking multicast tests ................................ --\n");
206 (
"Testing UDP/IP networking (IPv4 multicast) ............................... ");
208 s1 =
udp_init(
"224.2.0.1", 5004, 5004, 1, 0,
false);
211 printf(
" Cannot initialize socket\n");
218 perror(
" Cannot send");
219 goto abort_multicast;
228 perror(
" Select failed");
229 goto abort_multicast;
233 printf(
" No data waiting (no multicast loopback route?)\n");
234 goto abort_multicast;
238 printf(
" No data on file descriptor\n");
239 goto abort_multicast;
243 perror(
" Cannot receive");
244 goto abort_multicast;
246 if (memcmp(buf1, buf2,
BUFSIZE) != 0) {
248 printf(
" Buffer corrupt\n");
249 goto abort_multicast;
258 (
"Testing UDP/IP networking (IPv4 length check) ............................ ");
260 s1 =
udp_init(
"224.2.0.1", 5004, 5004, 1, 0,
false);
263 printf(
" Cannot initialize socket\n");
266 for (i = 1; i <
BUFSIZE; i++) {
271 perror(
" Cannot send");
281 perror(
" Select failed");
287 (
" No data waiting (no multicast loopback route?)\n");
292 printf(
" No data on file descriptor\n");
297 perror(
" Cannot receive");
300 if (memcmp(buf1, buf2, i) != 0) {
302 printf(
" Buffer corrupt\n");
314 (
"Testing UDP/IP networking (IPv6 loopback) ................................ ");
316 s1 =
udp_init(
"::1", 5004, 5004, 1, 0,
false);
319 printf(
" Cannot initialize socket\n");
326 perror(
" Cannot send");
327 goto abort_loopback_ipv6;
336 perror(
" Select failed");
337 goto abort_loopback_ipv6;
341 printf(
" No data waiting\n");
342 goto abort_loopback_ipv6;
346 printf(
" No data on file descriptor\n");
347 goto abort_loopback_ipv6;
351 perror(
" Cannot receive");
352 goto abort_loopback_ipv6;
354 if (memcmp(buf1, buf2,
BUFSIZE) != 0) {
356 printf(
" Buffer corrupt\n");
357 goto abort_loopback_ipv6;
367 (
"Testing UDP/IP networking (IPv6 multicast) ............................... ");
369 const char *iface = NULL;
373 s1 =
udp_init_if(
"ff01::2:7ffe", iface, 5004, 5004, 1, 0,
false);
376 printf(
" Cannot initialize socket\n");
383 perror(
" Cannot send");
384 goto abort_multicast_ipv6;
393 perror(
" Select failed");
394 goto abort_multicast_ipv6;
398 printf(
" No data waiting (no multicast loopback route?)\n");
399 goto abort_multicast_ipv6;
403 printf(
" No data on file descriptor\n");
404 goto abort_multicast_ipv6;
408 perror(
" Cannot receive");
409 goto abort_multicast_ipv6;
411 if (memcmp(buf1, buf2,
BUFSIZE) != 0) {
413 printf(
" Buffer corrupt\n");
414 goto abort_multicast_ipv6;
418 abort_multicast_ipv6:
422 (
"Testing UDP/IP networking (IPv6 loopback) ................................ --\n");
424 (
"Testing UDP/IP networking (IPv6 unicast) ................................. --\n");
426 (
"Testing UDP/IP networking (IPv6 multicast) ............................... --\n");
433 (
"Testing UDP/IP networking (FreeBSD bug) .................................. --\n");
436 (
"Testing UDP/IP networking (FreeBSD bug) .................................. ");
440 s1 =
udp_init(
"224.2.0.1", 5004, 5004, 1, 0,
false);
442 printf(
"fail (parent): cannot initialize socket\n");
447 printf(
"fail: cannot fork\n");
449 }
else if (rc == 0) {
451 s2 =
udp_init(
"224.2.0.1", 5004, 5004, 1, 0,
false);
454 printf(
" Child cannot initialize socket\n");
459 perror(
" Child cannot send");
469 perror(
" Child select");
475 (
" Child: no data waiting (no multicast loopback route?)\n");
480 printf(
" Child: no data on file descriptor\n");
486 perror(
" Child cannot receive");
491 printf(
" Child: read size incorrect (%d != %d)\n", rc,
495 if (memcmp(buf1, buf2, 64) != 0) {
497 printf(
" Child: buffer corrupt\n");
511 perror(
" Parent select");
517 (
" Parent: no data waiting (no multicast loopback route?)\n");
522 printf(
" Parent: no data on file descriptor\n");
528 perror(
" Parent cannot receive");
533 printf(
" Parent: read size incorrect (%d != %d)\n", rc,
537 if (memcmp(buf1, buf2, 64) != 0) {
539 printf(
" Parent: buffer corrupt\n");
546 if (status_parent && status_child) {
socket_udp * udp_init(const char *addr, uint16_t rx_port, uint16_t tx_port, int ttl, int force_ip_version, bool multithreaded)
socket_udp * udp_init_if(const char *addr, const char *iface, uint16_t rx_port, uint16_t tx_port, int ttl, int force_ip_version, bool multithreaded)