You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In types.h you use various "#pragma pack" statements, but unfortunately you do not use push and pop, so the last #pragma pack(4) is enabled for other files included after types.h. This is obviously very dangerous if you are not aware of it.
In Hostdb.cc you include gb-include.h, which includes types.h. Further down the code you include sys/types.h and ifaddrs.h. The strucs in these files are impacted by the open #pragma pack(4) :-(
The ugly hack to "swap ints" in the getLocalIps function is a direct result of a problem caused by this open #pragma pack. It modifies the layout of the ifaddrs struct, causing you to use a misaligned address pointer.
Move the include of the two system files up above the gb-include.h file, and you can remove the swapInts function and have the ifa_addr work as expected.
The correct fix of types.h (and zlib.h) would be to use #pragma pack(push, 4) and #pragma pack(pop), but who knows what that will break now that #pragma pack(4) has been "standard" in all files.
In types.h you use various "#pragma pack" statements, but unfortunately you do not use push and pop, so the last #pragma pack(4) is enabled for other files included after types.h. This is obviously very dangerous if you are not aware of it.
In Hostdb.cc you include gb-include.h, which includes types.h. Further down the code you include sys/types.h and ifaddrs.h. The strucs in these files are impacted by the open #pragma pack(4) :-(
The ugly hack to "swap ints" in the getLocalIps function is a direct result of a problem caused by this open #pragma pack. It modifies the layout of the ifaddrs struct, causing you to use a misaligned address pointer.
Move the include of the two system files up above the gb-include.h file, and you can remove the swapInts function and have the ifa_addr work as expected.
The correct fix of types.h (and zlib.h) would be to use #pragma pack(push, 4) and #pragma pack(pop), but who knows what that will break now that #pragma pack(4) has been "standard" in all files.
Try this code:
printf("offsetof struct ifaddrs.ifa_next: %zu\n", offsetof(struct ifaddrs, ifa_next));
printf("offsetof struct ifaddrs.ifa_name: %zu\n", offsetof(struct ifaddrs, ifa_name));
printf("offsetof struct ifaddrs.ifa_flags: %zu\n", offsetof(struct ifaddrs, ifa_flags));
printf("offsetof struct ifaddrs.ifa_addr: %zu\n", offsetof(struct ifaddrs, ifa_addr));
printf("offsetof struct ifaddrs.ifa_netmask: %zu\n", offsetof(struct ifaddrs, ifa_netmask));
With no types.h included:
offsetof struct ifaddrs.ifa_next: 0
offsetof struct ifaddrs.ifa_name: 8
offsetof struct ifaddrs.ifa_flags: 16
offsetof struct ifaddrs.ifa_addr: 24
offsetof struct ifaddrs.ifa_netmask: 32
With types.h included (or just #pragma pack(4) specified):
offsetof struct ifaddrs.ifa_next: 0
offsetof struct ifaddrs.ifa_name: 8
offsetof struct ifaddrs.ifa_flags: 16
offsetof struct ifaddrs.ifa_addr: 20
offsetof struct ifaddrs.ifa_netmask: 28
Notice the ifa_addr offset ...
Partial fix in our fork: privacore@f360546
The text was updated successfully, but these errors were encountered: