-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Correct hostent_addr h_addrtype typespec #5412
Conversation
56464be
to
4153cd2
Compare
4153cd2
to
dd3a664
Compare
h_addrtype :: inet | inet6 | caa | cname | gid | hinfo | ns | mb | md | mg | ||
| mf | minfo | mx | naptr | null | ptr | soa | spf | srv | txt | ||
| uid | uinfo | unspec | uri | wks, %% host address type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest this should be:
h_addrtype :: inet | inet6 | inet_res:rr_type(),
and that inet_res:rr_type()
should be exported.
This would be a bit incorrect since a
and aaaa
today cannot be in #hostent.h_addrtype
, but future safer since it uses the type that the rest of inet_res
uses for DNS record types, and future additions will be only to inet_res:rr_type()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it perhaps make sense to have a inet_res:dns_sockaddr_record
that could be exported and make the type h_addrtype :: inet | inet6 | inet_res:dns_sockaddr_record()
and make inet_res:rr_type
be
rr_type :: a | aaaa | dns_sockaddr_record()
or for even more clarity
dns_ip_record:: a | aaaa
and rr_type :: dns_ip_record() | dns_sockaddr_record()
It could also be more clear to call rr_type dns_record_type
, longer but much easier to understand!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inet_res:rr_type()
should probably rather be named inet_res:dns_rr_type()
similar to inet_res:dns_name()
and inet_res:dns_class()
...
Other than that I think that subdividing rr_type()
would be artificial since it simply specifies the flat set of RR types.
The name dns_sockaddr_record
is misleading since:
- It is not a record - it is a record type or rather a Resource Record type, which within DNS is abbreviated RR, hence "RR Type". So "record" should be "resource_record_type" or rather an artificial subset thereof.
- It has very little to do with a socket address ("sockaddr"). Normally, when a
#hostent
record is used, the fieldh_addrtype
containsinet
orinet6
, which both are socket address types, a.k.a address families, so there is a connection between this field and a socket address type. But when the field is abused byinet_res:getbyname/2,3
, it contains a DNS RR Type, and the content of a RR need not be an address - it can be a CNAME string, a TXT string and whatnot.
The problem is inet_res:getbyname/2,3
that returns the result as a #hostent
record. That return format is only suitable for RR types a
and aaaa
that have the translations into socket address types inet
and inet6
. For all other RR types the #hostent
record return value is unsuitable and is abused.
So inet_res:getbyname/2,3
creates the type problem and I see no good solution. The least bad I can think of is to type specify #hostent.h_addrtype
to be the union of the address families that can be returned from gethosbyname(), i.e inet | inet6
, and the DNS RR types, i.e inet_res:rr_type()
. That two RR types are translated into socket address types by the function so they can never occur in the result, I think is a minor problem.
But, maybe we should change inet_res:rr_type()
into inet_res:dns_rr_type()
before exporting it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record, I see I misunderstood. We have discussed this internally and will make a different solution to try to make the best of it.
I have created an alternative PR #5803 that instead updates the |
…c_fix/PR-5412/OTP-17986 Correct typespec for inet_res:getbyname/2,3 (PR #5412, OTP-17986)
Fixed by PR #5803 |
Fixes a broken spec for the
hostent
h_addrtype
spec. It covers the results from this function head.