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

CNAME answers to A request #161

Open
maelp opened this issue Aug 14, 2021 · 7 comments
Open

CNAME answers to A request #161

maelp opened this issue Aug 14, 2021 · 7 comments

Comments

@maelp
Copy link

maelp commented Aug 14, 2021

I think that it is possible for a server to answer an A request with a CNAME response, but it seems that pycares, although in both cases using the c-ares ares_parse_a_reply method, forces the result of an A query to be a list of IPs

if query_type == _lib.T_A:

@maelp
Copy link
Author

maelp commented Aug 14, 2021

This seems to work

    if query_type == _lib.T_A:
        host = _ffi.new("struct hostent **")
        addrttls = _ffi.new("struct ares_addrttl[]", PYCARES_ADDRTTL_SIZE)
        naddrttls = _ffi.new("int*", PYCARES_ADDRTTL_SIZE)
        parse_status = _lib.ares_parse_a_reply(abuf, alen, host, addrttls, naddrttls)
        if parse_status != _lib.ARES_SUCCESS:
            result = None
            status = parse_status
        else:
            if host[0].h_aliases[0] != _ffi.NULL:
                result = ares_query_cname_result(host[0])
                _lib.ares_free_hostent(host[0])
            else:
                result = [ares_query_a_result(addrttls[i]) for i in range(naddrttls[0])]
            status = None

@saghul
Copy link
Owner

saghul commented Aug 15, 2021

Nice! Is there a publicly available record we can use to test? If so, mind making a PR?

@maelp
Copy link
Author

maelp commented Aug 15, 2021

Well I guess we'd have to update this https://github.com/saghul/pycares/blob/master/tests/tests.py#L186 but I'm not exactly sure how we are supposed to build the response for each case?

@saghul
Copy link
Owner

saghul commented Aug 15, 2021

Right. Up until this point I've used publicly available records instead of synthetic ones.

@maelp
Copy link
Author

maelp commented Aug 15, 2021

I'm not sure how we should go about generating the synthetic one, perhaps creating a fake server ?

@saghul
Copy link
Owner

saghul commented Aug 15, 2021

Not sure, I suppose it might be tricky to test on Windows, that's why I relied on existing DNS records, though this is not ideal.

@jruere
Copy link

jruere commented Oct 10, 2024

For my use case, I'd like to get the actual record I request. Would this change "help" by returning the A record of the CNAME automatically?

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

3 participants