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

sock_resolve_one #357

Merged
merged 2 commits into from
May 31, 2022
Merged

sock_resolve_one #357

merged 2 commits into from
May 31, 2022

Conversation

gperciva
Copy link
Member

No description provided.

@gperciva
Copy link
Member Author

gperciva commented May 21, 2022

New version of #356 with reduced scope, aimed at the source/bind case, not for the target address.

The idea is that this sock_resolve_one can optionally be expanded to handle appending a ":0" to the address (if necessary). This should simplify #353.

@gperciva gperciva marked this pull request as ready for review May 21, 2022 18:12
warn0("Using the first of multiple addresses found for %s",
addr);

/* Allocate a structure. */
Copy link
Member

Choose a reason for hiding this comment

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

Err... we have sock_addr_dup if you want to do it that way. But why not just free the bits we don't want?

sa = sas[0];
for (p = &sas[1]; *p != NULL; p++)
    sock_addr_free(*p);
free(sas);

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh, I never noticed sock_util.h.

I agree that avoiding the malloc is a cleaner solution.

@@ -275,17 +275,13 @@ main(int argc, char * argv[])
}

/* Resolve source address. */
while ((sas_s = sock_resolve(opt_s)) == NULL) {
while ((sa_s = sock_resolve_one(opt_s)) == NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

This changes the behaviour from "error out if there are no addresses" to "keep looping forever".

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I'm not following. I completely believe that I screwed something up, and/or we need to pass an extra argument to sock_resolve_one to handle this case elegantly, but I'm not seeing it.

With git master,

$ ./spiped/spiped -d -s 257.0.0.1:8001 -t 127.0.0.1:8000 -k /dev/null -F
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
$ ./spiped/spiped -d -s 257.0.0.1:8001 -t 127.0.0.1:8000 -k /dev/null -F -D
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error looking up 257.0.0.1: Name does not resolve
^C

(^C indicates me manually pressing ctrl-C, of course)

With this PR,

$ ./spiped/spiped -d -s 257.0.0.1:8001 -t 127.0.0.1:8000 -k /dev/null -F
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
spiped: Error resolving socket address: 257.0.0.1:8001
$ ./spiped/spiped -d -s 257.0.0.1:8001 -t 127.0.0.1:8000 -k /dev/null -F -D
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
spiped: Error looking up 257.0.0.1: Name does not resolve
spiped: Error resolving socket address: 257.0.0.1:8001
^C

Granted, the double error message in the first case isn't ideal. But the "loop / no loop" behaviour looks the same?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I was thinking of the case where we successfully get zero addresses. (i.e. sock_resolve returns sas != NULL but sas[0] == NULL.)

But I'm not even sure that's possible, so let's not worry about that case.

@cperciva
Copy link
Member

Change looks good, please rebase.

@gperciva gperciva force-pushed the sock-resolve-one branch from 7d9e4bc to 7c5c5af Compare May 30, 2022 20:50
@gperciva
Copy link
Member Author

Ready for merge.

@cperciva cperciva merged commit 34866d3 into master May 31, 2022
@gperciva gperciva deleted the sock-resolve-one branch May 31, 2022 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants