aboutsummaryrefslogtreecommitdiff
path: root/src/inet.c
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2015-08-25 15:41:40 -0300
committerDiego Nehab <diego.nehab@gmail.com>2015-08-25 15:41:40 -0300
commit77bba625d7aaa0f9e118879163687fcbcb0b5a7b (patch)
treebbb719610c306b0af3225784164b44e2c509eb7c /src/inet.c
parent96965b179c7311f850f72a8629b9ba6d3a31d117 (diff)
downloadluasocket-77bba625d7aaa0f9e118879163687fcbcb0b5a7b.tar.gz
luasocket-77bba625d7aaa0f9e118879163687fcbcb0b5a7b.tar.bz2
luasocket-77bba625d7aaa0f9e118879163687fcbcb0b5a7b.zip
Fixes suggested by @Florob in #147.
Diffstat (limited to 'src/inet.c')
-rw-r--r--src/inet.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/inet.c b/src/inet.c
index 8f0fac2..331b800 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -352,8 +352,13 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp)
352/*-------------------------------------------------------------------------*\ 352/*-------------------------------------------------------------------------*\
353* Tries to create a new inet socket 353* Tries to create a new inet socket
354\*-------------------------------------------------------------------------*/ 354\*-------------------------------------------------------------------------*/
355const char *inet_trycreate(p_socket ps, int family, int type) { 355const char *inet_trycreate(p_socket ps, int family, int type, int protocol) {
356 return socket_strerror(socket_create(ps, family, type, 0)); 356 const char *err = socket_strerror(socket_create(ps, family, type, protocol));
357 if (err == NULL && family == AF_INET6) {
358 int yes = 1;
359 setsockopt(*ps, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&yes, sizeof(yes));
360 }
361 return err;
357} 362}
358 363
359/*-------------------------------------------------------------------------*\ 364/*-------------------------------------------------------------------------*\
@@ -408,8 +413,8 @@ const char *inet_tryconnect(p_socket ps, int *family, const char *address,
408 * not enter this branch. */ 413 * not enter this branch. */
409 if (current_family != iterator->ai_family || *ps == SOCKET_INVALID) { 414 if (current_family != iterator->ai_family || *ps == SOCKET_INVALID) {
410 socket_destroy(ps); 415 socket_destroy(ps);
411 err = socket_strerror(socket_create(ps, iterator->ai_family, 416 err = inet_trycreate(ps, iterator->ai_family,
412 iterator->ai_socktype, iterator->ai_protocol)); 417 iterator->ai_socktype, iterator->ai_protocol);
413 if (err) continue; 418 if (err) continue;
414 current_family = iterator->ai_family; 419 current_family = iterator->ai_family;
415 /* set non-blocking before connect */ 420 /* set non-blocking before connect */
@@ -466,8 +471,8 @@ const char *inet_trybind(p_socket ps, int *family, const char *address,
466 for (iterator = resolved; iterator; iterator = iterator->ai_next) { 471 for (iterator = resolved; iterator; iterator = iterator->ai_next) {
467 if (current_family != iterator->ai_family || *ps == SOCKET_INVALID) { 472 if (current_family != iterator->ai_family || *ps == SOCKET_INVALID) {
468 socket_destroy(ps); 473 socket_destroy(ps);
469 err = socket_strerror(socket_create(ps, iterator->ai_family, 474 err = inet_trycreate(ps, iterator->ai_family,
470 iterator->ai_socktype, iterator->ai_protocol)); 475 iterator->ai_socktype, iterator->ai_protocol);
471 if (err) continue; 476 if (err) continue;
472 current_family = iterator->ai_family; 477 current_family = iterator->ai_family;
473 } 478 }