Only use EAI_OVERFLOW, AI_NUMERICSERV if defined

Some systems like Mac OS X 10.5 (and lower) do not have EAI_OVERFLOW and
AI_NUMERICSERV defined.

These variables are used to avoid a potentially slow name resolution
for the hostname (which will always be an ip address)
and for service name (which will always be an actual port number).

The code might be slower, but it should still work.

Closes: #242
This commit is contained in:
Mojca Miklavec 2018-03-21 18:02:46 +01:00
parent c0fba03e4f
commit d9afe3fd9c
2 changed files with 6 additions and 1 deletions

View file

@ -188,7 +188,10 @@ static int meth_sendto(lua_State *L) {
memset(&aihint, 0, sizeof(aihint));
aihint.ai_family = udp->family;
aihint.ai_socktype = SOCK_DGRAM;
aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
aihint.ai_flags = AI_NUMERICHOST;
#ifdef AI_NUMERICSERV
aihint.ai_flags |= AI_NUMERICSERV;
#endif
err = getaddrinfo(ip, port, &aihint, &ai);
if (err) {
lua_pushnil(L);