Re: Approach to sin_zero
Here's a version that uses getaddrinfo:
sock_type cmw::udp_server (uint16_t port)
{
::std::ostringstream out;
out << port;
addrinfo* res;
addrinfo hints;
::std::memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE;
int err;
if ((err = ::getaddrinfo(nullptr
, out.str().c_str()
, &hints
, &res
)) != 0) {
throw failure("udp_server getaddrinfo: ") << gai_strerror(err);
}
sock_type sd = getSocket(SOCK_DGRAM);
if (::bind(sd, res->ai_addr, res->ai_addrlen)==-1) {
throw failure("udp_server bind: ") << GetError();
}
return sd;
}
The unfortunate thing is the change adds over 2,000 bytes
to an executable. It isn't a big executable and the
percentage increase is close to 3%. That strikes me as
excessive. Are there any other alternatives?