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)); memset(&aihint, 0, sizeof(aihint));
aihint.ai_family = udp->family; aihint.ai_family = udp->family;
aihint.ai_socktype = SOCK_DGRAM; 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); err = getaddrinfo(ip, port, &aihint, &ai);
if (err) { if (err) {
lua_pushnil(L); lua_pushnil(L);

View File

@ -440,7 +440,9 @@ LUASOCKET_PRIVATE const char *socket_gaistrerror(int err) {
case EAI_FAMILY: return PIE_FAMILY; case EAI_FAMILY: return PIE_FAMILY;
case EAI_MEMORY: return PIE_MEMORY; case EAI_MEMORY: return PIE_MEMORY;
case EAI_NONAME: return PIE_NONAME; case EAI_NONAME: return PIE_NONAME;
#ifdef EAI_OVERFLOW
case EAI_OVERFLOW: return PIE_OVERFLOW; case EAI_OVERFLOW: return PIE_OVERFLOW;
#endif
#ifdef EAI_PROTOCOL #ifdef EAI_PROTOCOL
case EAI_PROTOCOL: return PIE_PROTOCOL; case EAI_PROTOCOL: return PIE_PROTOCOL;
#endif #endif