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

Copy scope id when binding to IPv6 Link-Local address #2969

Open
wants to merge 2 commits into
base: fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr
memcpy(&((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr,
&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr,
sizeof(struct in6_addr));

((struct sockaddr_in6 *)rp->ai_addr)->sin6_scope_id = ((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_scope_id;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why the memcpy call in line 673 isn't sufficient to copy this value already?

Copy link
Author

Choose a reason for hiding this comment

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

Is your question why only copying the in6_addr is not enough? That's because for link-local addresses they are only valid for a specific interface, you can specify which interface the address belongs to with the scope id.

If your question is why I didn't group everything into a single memcpy call. That was for readability.


freeifaddrs(ifaddr);
return MOSQ_ERR_SUCCESS;
}
Expand Down
2 changes: 2 additions & 0 deletions test/broker/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ Numbering is as follows:
10: Listener tests
11: Persistence tests
12: Property tests
13: Malformed tests
14: Dynamic security tests