Instead of a gethostname
hack, which is not guaranteed to return all addresses, use the official way of calling GetAdaptersAddresses
to get local network addresses on Windows.
Do the same checks as the UNIX path: interface is up, interface is not loopback.
Suggested by Ava Chow.
Addiional changes:
- Add optional length checking to
CService::SetSockAddr
calls: In almost all cases (the only exception isgetifaddrs
), we know the size of the data passed intoSetSockAddr
, so we can check this to be what is expected, before reading the memory. - Cleanup: move out
FromSockAddr
innetif.cpp
from MacOS and use it everywhere appropriate. This avoids code duplication.