[Bug nscd/34483] New: getaddrinfo with hint AF_INET does not cache

josef at oderland dot se via Glibc-bugs <[email protected]>
Newsgroups gmane.comp.lib.glibc.bugs
Message-ID <[email protected]/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=34483

            Bug ID: 34483
           Summary: getaddrinfo with hint AF_INET does not cache
           Product: glibc
           Version: 2.45
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: nscd
          Assignee: unassigned at sourceware dot org
          Reporter: josef at oderland dot se
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Given the code

```
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int              sfd, s;
    struct addrinfo  hints;
    struct addrinfo  *result, *rp;

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET;    /* Allow IPv4 or IPv6 */
    hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
    hints.ai_flags = 0;
    hints.ai_protocol = 0;          /* Any protocol */

    s = getaddrinfo("example.com", "80", &hints, &result);
    if (s != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
        exit(EXIT_FAILURE);
    }

    exit(EXIT_SUCCESS);
}
```

nscd returns

```
root@6cfc07995929:/data# ./test-inet
Wed Aug  5 08:54:07 2026 - 77899: handle_request: request received (Version =
2) from PID 78071
Wed Aug  5 08:54:07 2026 - 77899:       GETFDHST
Wed Aug  5 08:54:07 2026 - 77899: handle_request: request received (Version =
2) from PID 78071
Wed Aug  5 08:54:07 2026 - 77899:       GETHOSTBYNAME (example.com)
Wed Aug  5 08:54:07 2026 - 77899: Haven't found "example.com" in hosts cache!
root@6cfc07995929:/data# ./test-inet
Wed Aug  5 08:54:08 2026 - 77899: handle_request: request received (Version =
2) from PID 78072
Wed Aug  5 08:54:08 2026 - 77899:       GETFDHST
Wed Aug  5 08:54:08 2026 - 77899: handle_request: request received (Version =
2) from PID 78072
Wed Aug  5 08:54:08 2026 - 77899:       GETHOSTBYNAME (example.com)
Wed Aug  5 08:54:08 2026 - 77899: Haven't found "example.com" in hosts cache!
```

Using AF_UNSPEC as hint works, since it will do a GETAI (example.com) instead.

This turned out to be a problem since cURL have started to do two lookups
instead of one in their getaddrinfo, one with AF_INET and one with AF_INET6.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.