What happens if undefined C++ behaviour meets C defined behaviour?

This is defined in both C++ and C. It does not violate strict aliasing regulations as it does not dereference the resulting pointer.

Here's the quote from C++ (thanks to @interjay and @VTT) that allows this:

An object pointer can be explicitly converted to an object pointer of a different type.

Here's the quote from C (thanks @StoryTeller) that allows this:

A pointer to an object type may be converted to a pointer to a different object type.

These specify that one pointer type can be converted to another pointer type (and then optionally converted back) without consequence.

And here's the quote from POSIX that allows this specific case:

The sockaddr_in structure is used to store addresses for the Internet address family. Pointers to this type shall be cast by applications to struct sockaddr * for use with socket functions.

As this function (bind) is part of the C standard library, whatever goes on inside (specifically, dereferencing the type-casted pointer) does not have undefined behavior.


To answer the more general question:

C and C++ are two different languages. If something is defined in C but not in C++, it's defined in C but not in C++. No implied compatibility between the two languages will change that. If you want to use code that is well-defined in C but is undefined in C++, you'll have to use a C compiler to compile that code.