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

Refactoring of obsolete gethostbyname() in connect_to_rti() #220

Merged
merged 4 commits into from
Jun 10, 2023

Conversation

siljesu
Copy link
Contributor

@siljesu siljesu commented May 22, 2023

According to the linux man-page:

The gethostbyname*(), gethostbyaddr*(), herror(), and hstrerror() functions are obsolete. Applications should use getaddrinfo(3), getnameinfo(3), and gai_strerror(3) instead.

Currently, gethostbyname() is used in connect_to_rti(). This PR modifies the function to use getaddrinfo() instead. The functionality should be unchanged. If no host matches the given hostname, getaddrinfo() will return a non-zero value and exit. If at least one address structure matches the given hostname, it will set the port the be uport and try to connect. Notice that getaddrinfo() returns a linked list of matching address structures, if more than one matches the hostname and hints. According to the man page:

There are several reasons why the linked list may have more than one addrinfo structure, including: the network host is multihomed, accessible over multiple protocols (e.g., both AF_INET and AF_INET6); or the same service is available from multiple socket types (one SOCK_STREAM address and another SOCK_DGRAM address, for example). Normally, the application should try using the addresses in the order in which they are returned.

So in the current application, I think it should never return more than one address structure (the hints structure specifies AF_INET and SOCK_STREAM specifically). And if it does, we essentially ignore all but the first one, and if the first one fails, try with the next port number instead.

@lhstrh lhstrh requested a review from edwardalee May 24, 2023 05:14
@siljesu siljesu mentioned this pull request Jun 2, 2023
Copy link
Contributor

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@edwardalee
Copy link
Contributor

This should be merged, but I don't understand the test failures. There is no information.

@lhstrh lhstrh merged commit fd274c4 into lf-lang:main Jun 10, 2023
25 checks passed
@lhstrh lhstrh changed the title Refactor of obsolete gethostbyname() in connect_to_rti() Refactoring of obsolete gethostbyname() in connect_to_rti() Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants