From abdf612221db39f31abde0ef211bad28e272dde0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 29 Jul 2024 19:49:32 +0200 Subject: [PATCH] tool_operate: more defensive socket code - use 'struct sockaddr' to getsockname() and its sa_family member - use 'curl_socklen_t' instead of 'socklen_t' - check for AF_INET6 to exist instead assuming it does Should be generally more portable. Reported-by: Harry Sintonen Closes #14304 --- src/tool_operate.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/tool_operate.c b/src/tool_operate.c index 38d3c979d7..f6ae64dd3d 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -154,14 +154,10 @@ static bool is_pkcs11_uri(const char *string) #ifdef IP_TOS static int get_address_family(curl_socket_t sockfd) { - struct sockaddr_storage addr; - socklen_t addrlen = sizeof(addr); + struct sockaddr addr; + curl_socklen_t addrlen = sizeof(addr); if(getsockname(sockfd, (struct sockaddr *)&addr, &addrlen) == 0) -# ifdef __TANDEM - return addr.__ss_family; -# else - return addr.ss_family; -# endif + return addr.sa_family; return AF_UNSPEC; } #endif @@ -185,12 +181,12 @@ static int sockopt_callback(void *clientp, curl_socket_t curlfd, result = setsockopt(curlfd, SOL_IP, IP_TOS, (void *)&tos, sizeof(tos)); #endif break; +#if defined(IPV6_TCLASS) && defined(AF_INET6) case AF_INET6: -#ifdef IPV6_TCLASS result = setsockopt(curlfd, IPPROTO_IPV6, IPV6_TCLASS, (void *)&tos, sizeof(tos)); -#endif break; +#endif } if(result < 0) { int error = errno;