18 #pragma comment(lib, "Ws2_32.lib")
19 #pragma comment(lib, "Mswsock.lib")
20 #pragma comment(lib, "AdvApi32.lib")
33 auto rv = ::WSAStartup(MAKEWORD(2, 2), &wsaData);
43 ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error,
44 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (
sizeof(buf) /
sizeof(
char)), NULL);
64 addr_.sin_family = PF_INET;
65 addr_.sin_port = htons(port);
66 addr_.sin_addr.s_addr = INADDR_ANY;
67 if (InetPtonA(PF_INET, host.c_str(), &
addr_.sin_addr.s_addr) != 1)
69 int last_error = ::WSAGetLastError();
74 socket_ = ::socket(PF_INET, SOCK_DGRAM, 0);
77 int last_error = ::WSAGetLastError();
83 if (::setsockopt(
socket_, SOL_SOCKET, SO_SNDBUF,
reinterpret_cast<const char *
>(&option_value),
sizeof(option_value)) < 0)
85 int last_error = ::WSAGetLastError();
103 socklen_t tolen =
sizeof(
struct sockaddr);
104 if (::sendto(
socket_,
data,
static_cast<int>(n_bytes), 0, (
struct sockaddr *)&
addr_, tolen) == -1)