fixing issues on linux system with no IPV6 support

master
Steffen Pohle 1 month ago
parent 8511d8c375
commit 6463e8edc8

@ -1,3 +1,6 @@
2026-10-24:
- tcp.cc: on hosts with disabled ipv6, we could not listen on IPV4 only
2026-08-04: 2026-08-04:
- JSON handling with arrays had serval issues. - JSON handling with arrays had serval issues.
added test-json file to test also nested arrays. added test-json file to test also nested arrays.

@ -84,27 +84,55 @@ int TCP::Listen(int port) {
#endif #endif
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
if ((err = getaddrinfo (NULL, itoa(buffer, port, 32), &hints, &res)) != 0) { if ((err = getaddrinfo (NULL, itoa(buffer, port, 32), &hints, &res)) != 0) {
return 0; fprintf (stderr, "getaddrinfo: %s\n", gai_strerror(err));
} return 0;
}
// //
// walk through all results until we could connect // walk through all results until we could connect
// //
for (rp = res; rp != NULL; rp = rp->ai_next) { for (rp = res; rp != NULL; rp = rp->ai_next) {
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sock == -1) continue; if (sock == -1) {
printf ("%s:%d socket error: %s\n", __FILE__, __LINE__, strerror(errno));
//
// in case of an unsupported address family, we will check only for IPV4
//
if (errno == EAFNOSUPPORT) {
printf ("%s:%d try with IPV4 only\n", __FILE__, __LINE__);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
freeaddrinfo (res);
if ((err = getaddrinfo (NULL, itoa(buffer, port, 32), &hints, &res)) != 0) {
fprintf (stderr, "getaddrinfo: %s\n", gai_strerror(err));
return 0;
}
rp = res;
if (res != NULL) {
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock == -1) {
printf ("%s:%d socket error: %s\n", __FILE__, __LINE__, strerror(errno));
continue;
}
}
}
else continue;
}
i = 1; i = 1;
if ((err = setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (char*)&i, sizeof (i))) != 0) { if ((err = setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (char*)&i, sizeof (i))) != 0) {
printf ("%s:%d setsockopt error\n", __FILE__, __LINE__); printf ("%s:%d setsockopt error\n", __FILE__, __LINE__);
} }
if ((err = bind (sock, rp->ai_addr, rp->ai_addrlen)) < 0) { if ((err = bind (sock, rp->ai_addr, rp->ai_addrlen)) < 0) {
printf ("%s:%d bind error: %s\n", __FILE__, __LINE__, strerror(errno));
close (sock); close (sock);
sock = -1; sock = -1;
continue; continue;
} }
if (listen (sock, 8) < 0) { // maximum of 8 connections at the time if (listen (sock, 8) < 0) { // maximum of 8 connections at the time
printf ("%s:%d listen error: %s\n", __FILE__, __LINE__, strerror(errno));
close (sock); close (sock);
sock = -1; sock = -1;
continue; continue;

Loading…
Cancel
Save