Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_addr() should return -1 in case of error #96

Open
aafbsd opened this issue May 5, 2024 · 0 comments
Open

get_addr() should return -1 in case of error #96

aafbsd opened this issue May 5, 2024 · 0 comments

Comments

@aafbsd
Copy link

aafbsd commented May 5, 2024

Subject says it all:
getaddrinfo() returns positive values in case of errors. These get returned
to the caller:

    res = getaddrinfo(host, portnum, &hints, &addr);
    if (res == 0) {
            int addrlen = addr->ai_addrlen;
            /* Grab first result */
            memcpy(out, addr->ai_addr, addr->ai_addrlen);
            freeaddrinfo(addr);
            return addrlen;
    }
    return res;

But the caller check for negative values, e.g.:

    res = get_addr("resolver1.opendns.com", 53, AF_INET, 0, &query.destination);
    if (res < 0) return 1;
    ...
    dns4addr_len = get_addr(listen_ip4, port, AF_INET, AI_PASSIVE, &dns4addr);
    if (dns4addr_len < 0) {
    ...
    int addr6_res = get_addr(listen_ip6, port, AF_INET6, AI_PASSIVE, &dns6addr);
    if (addr6_res < 0) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant