diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2026-03-26 12:53:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-26 12:53:53 +0100 |
| commit | 13e14a6bfd9f29cbfeab0c5161d2a994f97532e7 (patch) | |
| tree | 3aa7186fe092e42783dc7e981dc39a74ea61c466 /gl/getaddrinfo.c | |
| parent | 9d8503f90ef25b2cecd324dc118e441f40233ea8 (diff) | |
| download | monitoring-plugins-13e14a6bfd9f29cbfeab0c5161d2a994f97532e7.tar.gz | |
* Sync with the 202601-stable Gnulib code (4a3650d887)
* Ignore more deps stuff in gnulib
* Remove autogenerated gnulib files
* Ignore more gnulib generated headers
Diffstat (limited to 'gl/getaddrinfo.c')
| -rw-r--r-- | gl/getaddrinfo.c | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/gl/getaddrinfo.c b/gl/getaddrinfo.c index a8c45c21..2b60377b 100644 --- a/gl/getaddrinfo.c +++ b/gl/getaddrinfo.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* Get address information (partial implementation). | 1 | /* Get address information (partial implementation). |
| 2 | Copyright (C) 1997, 2001-2002, 2004-2025 Free Software Foundation, Inc. | 2 | Copyright (C) 1997, 2001-2002, 2004-2026 Free Software Foundation, Inc. |
| 3 | Contributed by Simon Josefsson <simon@josefsson.org>. | 3 | Contributed by Simon Josefsson <simon@josefsson.org>. |
| 4 | 4 | ||
| 5 | This file is free software: you can redistribute it and/or modify | 5 | This file is free software: you can redistribute it and/or modify |
| @@ -40,7 +40,7 @@ | |||
| 40 | #include <stdio.h> | 40 | #include <stdio.h> |
| 41 | 41 | ||
| 42 | #include "gettext.h" | 42 | #include "gettext.h" |
| 43 | #define _(msgid) dgettext ("gnulib", msgid) | 43 | #define _(msgid) dgettext (GNULIB_TEXT_DOMAIN, msgid) |
| 44 | #define N_(msgid) msgid | 44 | #define N_(msgid) msgid |
| 45 | 45 | ||
| 46 | /* BeOS has AF_INET, but not PF_INET. */ | 46 | /* BeOS has AF_INET, but not PF_INET. */ |
| @@ -52,9 +52,40 @@ | |||
| 52 | # define PF_UNSPEC 0 | 52 | # define PF_UNSPEC 0 |
| 53 | #endif | 53 | #endif |
| 54 | 54 | ||
| 55 | #if defined __sun || !HAVE_GETADDRINFO | ||
| 56 | |||
| 57 | static bool | ||
| 58 | is_numeric_host (const char *host, int family) | ||
| 59 | { | ||
| 60 | # if HAVE_IPV4 | ||
| 61 | if (family == PF_INET || family == PF_UNSPEC) | ||
| 62 | { | ||
| 63 | /* glibc supports IPv4 addresses in numbers-and-dots notation, that is, | ||
| 64 | also hexadecimal and octal number formats and formats that don't | ||
| 65 | require all four bytes to be explicitly written, via inet_aton(). | ||
| 66 | But POSIX doesn't require support for these legacy formats. Therefore | ||
| 67 | we are free to use inet_pton() instead of inet_aton(). */ | ||
| 68 | struct in_addr addr; | ||
| 69 | if (inet_pton (AF_INET, host, &addr)) | ||
| 70 | return true; | ||
| 71 | } | ||
| 72 | # endif | ||
| 73 | # if HAVE_IPV6 | ||
| 74 | if (family == PF_INET6 || family == PF_UNSPEC) | ||
| 75 | { | ||
| 76 | struct in6_addr addr; | ||
| 77 | if (inet_pton (AF_INET6, host, &addr)) | ||
| 78 | return true; | ||
| 79 | } | ||
| 80 | # endif | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | |||
| 84 | #endif | ||
| 85 | |||
| 55 | #if HAVE_GETADDRINFO | 86 | #if HAVE_GETADDRINFO |
| 56 | 87 | ||
| 57 | /* Override with cdecl calling convention and mingw fix. */ | 88 | /* Override with cdecl calling convention and Windows and Solaris 10 fixes. */ |
| 58 | 89 | ||
| 59 | int | 90 | int |
| 60 | getaddrinfo (const char *restrict nodename, | 91 | getaddrinfo (const char *restrict nodename, |
| @@ -63,10 +94,18 @@ getaddrinfo (const char *restrict nodename, | |||
| 63 | struct addrinfo **restrict res) | 94 | struct addrinfo **restrict res) |
| 64 | # undef getaddrinfo | 95 | # undef getaddrinfo |
| 65 | { | 96 | { |
| 97 | /* Workaround for native Windows. */ | ||
| 66 | if (hints && (hints->ai_flags & AI_NUMERICSERV) != 0 | 98 | if (hints && (hints->ai_flags & AI_NUMERICSERV) != 0 |
| 67 | && servname && !(*servname >= '0' && *servname <= '9')) | 99 | && servname && !(*servname >= '0' && *servname <= '9')) |
| 68 | return EAI_NONAME; | 100 | return EAI_NONAME; |
| 69 | 101 | ||
| 102 | # ifdef __sun | ||
| 103 | /* Workaround for Solaris 10. */ | ||
| 104 | if (hints && (hints->ai_flags & AI_NUMERICHOST) | ||
| 105 | && nodename && !is_numeric_host (nodename, hints->ai_family)) | ||
| 106 | return EAI_NONAME; | ||
| 107 | # endif | ||
| 108 | |||
| 70 | return getaddrinfo (nodename, servname, hints, res); | 109 | return getaddrinfo (nodename, servname, hints, res); |
| 71 | } | 110 | } |
| 72 | 111 | ||
| @@ -114,14 +153,13 @@ static int | |||
| 114 | use_win32_p (void) | 153 | use_win32_p (void) |
| 115 | { | 154 | { |
| 116 | static int done = 0; | 155 | static int done = 0; |
| 117 | HMODULE h; | ||
| 118 | 156 | ||
| 119 | if (done) | 157 | if (done) |
| 120 | return getaddrinfo_ptr ? 1 : 0; | 158 | return getaddrinfo_ptr ? 1 : 0; |
| 121 | 159 | ||
| 122 | done = 1; | 160 | done = 1; |
| 123 | 161 | ||
| 124 | h = GetModuleHandle ("ws2_32.dll"); | 162 | HMODULE h = GetModuleHandle ("ws2_32.dll"); |
| 125 | 163 | ||
| 126 | if (h) | 164 | if (h) |
| 127 | { | 165 | { |
| @@ -185,33 +223,6 @@ validate_family (int family) | |||
| 185 | return false; | 223 | return false; |
| 186 | } | 224 | } |
| 187 | 225 | ||
| 188 | static bool | ||
| 189 | is_numeric_host (const char *host, int family) | ||
| 190 | { | ||
| 191 | # if HAVE_IPV4 | ||
| 192 | if (family == PF_INET || family == PF_UNSPEC) | ||
| 193 | { | ||
| 194 | /* glibc supports IPv4 addresses in numbers-and-dots notation, that is, | ||
| 195 | also hexadecimal and octal number formats and formats that don't | ||
| 196 | require all four bytes to be explicitly written, via inet_aton(). | ||
| 197 | But POSIX doesn't require support for these legacy formats. Therefore | ||
| 198 | we are free to use inet_pton() instead of inet_aton(). */ | ||
| 199 | struct in_addr addr; | ||
| 200 | if (inet_pton (AF_INET, host, &addr)) | ||
| 201 | return true; | ||
| 202 | } | ||
| 203 | # endif | ||
| 204 | # if HAVE_IPV6 | ||
| 205 | if (family == PF_INET6 || family == PF_UNSPEC) | ||
| 206 | { | ||
| 207 | struct in6_addr addr; | ||
| 208 | if (inet_pton (AF_INET6, host, &addr)) | ||
| 209 | return true; | ||
| 210 | } | ||
| 211 | # endif | ||
| 212 | return false; | ||
| 213 | } | ||
| 214 | |||
| 215 | /* Translate name of a service location and/or a service name to set of | 226 | /* Translate name of a service location and/or a service name to set of |
| 216 | socket addresses. */ | 227 | socket addresses. */ |
| 217 | int | 228 | int |
| @@ -221,11 +232,6 @@ getaddrinfo (const char *restrict nodename, | |||
| 221 | struct addrinfo **restrict res) | 232 | struct addrinfo **restrict res) |
| 222 | #undef getaddrinfo | 233 | #undef getaddrinfo |
| 223 | { | 234 | { |
| 224 | struct addrinfo *tmp; | ||
| 225 | int port = 0; | ||
| 226 | struct hostent *he; | ||
| 227 | void *storage; | ||
| 228 | size_t size; | ||
| 229 | # if HAVE_IPV6 | 235 | # if HAVE_IPV6 |
| 230 | struct v6_pair { | 236 | struct v6_pair { |
| 231 | struct addrinfo addrinfo; | 237 | struct addrinfo addrinfo; |
| @@ -281,6 +287,7 @@ getaddrinfo (const char *restrict nodename, | |||
| 281 | # endif | 287 | # endif |
| 282 | } | 288 | } |
| 283 | 289 | ||
| 290 | int port = 0; | ||
| 284 | if (servname) | 291 | if (servname) |
| 285 | { | 292 | { |
| 286 | struct servent *se = NULL; | 293 | struct servent *se = NULL; |
| @@ -306,10 +313,11 @@ getaddrinfo (const char *restrict nodename, | |||
| 306 | } | 313 | } |
| 307 | 314 | ||
| 308 | /* FIXME: Use gethostbyname_r if available. */ | 315 | /* FIXME: Use gethostbyname_r if available. */ |
| 309 | he = gethostbyname (nodename); | 316 | struct hostent *he = gethostbyname (nodename); |
| 310 | if (!he || he->h_addr_list[0] == NULL) | 317 | if (!he || he->h_addr_list[0] == NULL) |
| 311 | return EAI_NONAME; | 318 | return EAI_NONAME; |
| 312 | 319 | ||
| 320 | size_t size; | ||
| 313 | switch (he->h_addrtype) | 321 | switch (he->h_addrtype) |
| 314 | { | 322 | { |
| 315 | # if HAVE_IPV6 | 323 | # if HAVE_IPV6 |
| @@ -328,10 +336,11 @@ getaddrinfo (const char *restrict nodename, | |||
| 328 | return EAI_NODATA; | 336 | return EAI_NODATA; |
| 329 | } | 337 | } |
| 330 | 338 | ||
| 331 | storage = calloc (1, size); | 339 | void *storage = calloc (1, size); |
| 332 | if (!storage) | 340 | if (!storage) |
| 333 | return EAI_MEMORY; | 341 | return EAI_MEMORY; |
| 334 | 342 | ||
| 343 | struct addrinfo *tmp; | ||
| 335 | switch (he->h_addrtype) | 344 | switch (he->h_addrtype) |
| 336 | { | 345 | { |
| 337 | # if HAVE_IPV6 | 346 | # if HAVE_IPV6 |
| @@ -446,9 +455,7 @@ freeaddrinfo (struct addrinfo *ai) | |||
| 446 | 455 | ||
| 447 | while (ai) | 456 | while (ai) |
| 448 | { | 457 | { |
| 449 | struct addrinfo *cur; | 458 | struct addrinfo *cur = ai; |
| 450 | |||
| 451 | cur = ai; | ||
| 452 | ai = ai->ai_next; | 459 | ai = ai->ai_next; |
| 453 | 460 | ||
| 454 | free (cur->ai_canonname); | 461 | free (cur->ai_canonname); |
