Skip to content

Fix Bugzilla issue 24404 - ifaddrs union fields incorrectly name on Linux.#16233

Merged
RazvanN7 merged 1 commit intodlang:masterfrom
jmdavis:issue_24404
Feb 26, 2024
Merged

Fix Bugzilla issue 24404 - ifaddrs union fields incorrectly name on Linux.#16233
RazvanN7 merged 1 commit intodlang:masterfrom
jmdavis:issue_24404

Conversation

@jmdavis
Copy link
Member

@jmdavis jmdavis commented Feb 23, 2024

You can see the correct declaration for ifaddrs on Linux here:

https://www.man7.org/linux/man-pages/man3/getifaddrs.3.html

What the fields are supposed to be named is ifa_broadaddr and ifa_dstaddr. However, because Linux defines them using a union, it gives them different names within the union - ifu_broadaddr and ifu_dstaddr - and then #defines the proper names to access the union names.

What druntime did was use the union names - and then incorrectly name ifu_dtsaddr as if_dstaddr. So, it was doubly wrong for that field.

The two approaches that we could take here would be to either

  1. Turn the union into a type so that we could have an ifa_ifu field to allow accessing the ifu_* names that way - as is technically possible in C - and then add wrapper functions with the ifa_* names (since we couldn't use an alias to access members of the union member variable).

  2. Just rename the fields to ifa_* and ignore the fact that you can technically access the ifu_* fields via the union name in C.

The simpler approach is #2, so that's what this commit does. I'm pretty sure that the ability to access the ifu_* fields via the union name is just an implementation detail - particularly since other platforms just declare the ifa_* names without using a union at all.

Either way, deprecated aliases are provided so that existing code doesn't break.

…inux.

You can see the correct declaration for ifaddrs on Linux here:

https://www.man7.org/linux/man-pages/man3/getifaddrs.3.html

What the fields are supposed to be named is ifa_broadaddr and
ifa_dstaddr. However, because Linux defines them using a union, it gives
them different names within the union - ifu_broadaddr and ifu_dstaddr -
and then #defines the proper names to access the union names.

What druntime did was use the union names - and then incorrectly name
ifu_dtsaddr as if_dstaddr. So, it was doubly wrong for that field.

The two approaches that we could take here would be to either

1. Turn the union into a type so that we could have an ifa_ifu field to
   allow accessing the ifu_* names that way - as is technically possible
   in C - and then add wrapper functions with the ifa_* names (since we
   couldn't use an alias to access members of the union member
   variable).

2. Just rename the fields to ifa_* and ignore the fact that you can
   technically access the ifu_* fields via the union name in C.

The simpler approach is dlang#2, so that's what this commit does. I'm pretty
sure that the ability to access the ifu_* fields via the union name is
just an implementation detail - particularly since other platforms just
declare the ifa_* names without using a union at all.

Either way, deprecated aliases are provided so that existing code
doesn't break.
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @jmdavis!

Bugzilla references

Auto-close Bugzilla Severity Description
24404 normal The names of the union fields in Linux's ifaddrs are named incorrectly.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#16233"

@RazvanN7 RazvanN7 merged commit 40b60f8 into dlang:master Feb 26, 2024
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.

4 participants