Remove undefined behavior in net sockaddr usage

Remove potential undefined behavior in networking code.
Not Available
$2,250.00
Check Out Task
Task Bounty Details

22613

Bitcoin Issue

Hours

Estimated Effort

Not Available

Current Status

$2,250.00

Paid in USD or equivalent BTC upon acceptance

Bitcoin Issue

From the original issue:

Bitcoin code does contain UB [undefined behavior] in the net code in particular. All of the code that works with `struct sockaddr` needs to be inspected and fixed. For example here:

bitcoin/src/netaddress.cpp (Line 988 in b620b2d)

`struct sockaddr_in *paddrin = (struct sockaddr_in*)paddr;`

It is illegal/UB in C++ to do this type of aliasing and dereference a pointer that is reinterpre_casted in this way. C++ has stricter aliasing rules than C. For reference, see this: https://en.cppreference.com/w/cpp/language/reinterpret_cast#Type_aliasing

Good knowledge of C/C++ is recommended.

Prerequisite Skills

C++

Code Guidelines

Repository Code Guidelines Page

Definition of Done

Get a PR merged which closes the original issue

Check Out Task