diff options
Diffstat (limited to 'src/tcp.c')
| -rw-r--r-- | src/tcp.c | 11 |
1 files changed, 7 insertions, 4 deletions
| @@ -18,7 +18,7 @@ | |||
| 18 | \*=========================================================================*/ | 18 | \*=========================================================================*/ |
| 19 | static int global_create(lua_State *L); | 19 | static int global_create(lua_State *L); |
| 20 | static int global_create6(lua_State *L); | 20 | static int global_create6(lua_State *L); |
| 21 | static int global_connect6(lua_State *L); | 21 | static int global_connect(lua_State *L); |
| 22 | static int meth_connect(lua_State *L); | 22 | static int meth_connect(lua_State *L); |
| 23 | static int meth_listen(lua_State *L); | 23 | static int meth_listen(lua_State *L); |
| 24 | static int meth_getfamily(lua_State *L); | 24 | static int meth_getfamily(lua_State *L); |
| @@ -89,7 +89,7 @@ static t_opt optset[] = { | |||
| 89 | static luaL_Reg func[] = { | 89 | static luaL_Reg func[] = { |
| 90 | {"tcp", global_create}, | 90 | {"tcp", global_create}, |
| 91 | {"tcp6", global_create6}, | 91 | {"tcp6", global_create6}, |
| 92 | {"connect6", global_connect6}, | 92 | {"connect", global_connect}, |
| 93 | {NULL, NULL} | 93 | {NULL, NULL} |
| 94 | }; | 94 | }; |
| 95 | 95 | ||
| @@ -408,6 +408,7 @@ static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, | |||
| 408 | freeaddrinfo(resolved); | 408 | freeaddrinfo(resolved); |
| 409 | return err; | 409 | return err; |
| 410 | } | 410 | } |
| 411 | tcp->family = iterator->ai_family; | ||
| 411 | /* all sockets initially non-blocking */ | 412 | /* all sockets initially non-blocking */ |
| 412 | socket_setnonblocking(&tcp->sock); | 413 | socket_setnonblocking(&tcp->sock); |
| 413 | } | 414 | } |
| @@ -424,11 +425,12 @@ static const char *tryconnect6(const char *remoteaddr, const char *remoteserv, | |||
| 424 | return err; | 425 | return err; |
| 425 | } | 426 | } |
| 426 | 427 | ||
| 427 | static int global_connect6(lua_State *L) { | 428 | static int global_connect(lua_State *L) { |
| 428 | const char *remoteaddr = luaL_checkstring(L, 1); | 429 | const char *remoteaddr = luaL_checkstring(L, 1); |
| 429 | const char *remoteserv = luaL_checkstring(L, 2); | 430 | const char *remoteserv = luaL_checkstring(L, 2); |
| 430 | const char *localaddr = luaL_optstring(L, 3, NULL); | 431 | const char *localaddr = luaL_optstring(L, 3, NULL); |
| 431 | const char *localserv = luaL_optstring(L, 4, "0"); | 432 | const char *localserv = luaL_optstring(L, 4, "0"); |
| 433 | int family = inet_optfamily(L, 5, "unspec"); | ||
| 432 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); | 434 | p_tcp tcp = (p_tcp) lua_newuserdata(L, sizeof(t_tcp)); |
| 433 | struct addrinfo bindhints, connecthints; | 435 | struct addrinfo bindhints, connecthints; |
| 434 | const char *err = NULL; | 436 | const char *err = NULL; |
| @@ -441,7 +443,7 @@ static int global_connect6(lua_State *L) { | |||
| 441 | /* allow user to pick local address and port */ | 443 | /* allow user to pick local address and port */ |
| 442 | memset(&bindhints, 0, sizeof(bindhints)); | 444 | memset(&bindhints, 0, sizeof(bindhints)); |
| 443 | bindhints.ai_socktype = SOCK_STREAM; | 445 | bindhints.ai_socktype = SOCK_STREAM; |
| 444 | bindhints.ai_family = PF_UNSPEC; | 446 | bindhints.ai_family = family; |
| 445 | bindhints.ai_flags = AI_PASSIVE; | 447 | bindhints.ai_flags = AI_PASSIVE; |
| 446 | if (localaddr) { | 448 | if (localaddr) { |
| 447 | err = inet_trybind(&tcp->sock, localaddr, localserv, &bindhints); | 449 | err = inet_trybind(&tcp->sock, localaddr, localserv, &bindhints); |
| @@ -450,6 +452,7 @@ static int global_connect6(lua_State *L) { | |||
| 450 | lua_pushstring(L, err); | 452 | lua_pushstring(L, err); |
| 451 | return 2; | 453 | return 2; |
| 452 | } | 454 | } |
| 455 | tcp->family = bindhints.ai_family; | ||
| 453 | } | 456 | } |
| 454 | /* try to connect to remote address and port */ | 457 | /* try to connect to remote address and port */ |
| 455 | memset(&connecthints, 0, sizeof(connecthints)); | 458 | memset(&connecthints, 0, sizeof(connecthints)); |
