From 8ac63679e7fefb234f4700d363cb8d3b5ee1b7a2 Mon Sep 17 00:00:00 2001 From: zhaozg Date: Tue, 30 Aug 2022 15:22:56 +0800 Subject: [PATCH] more safe in tcp.c, avoid errno 61 on AIX --- src/tcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tcp.c b/src/tcp.c index e84db84..25828d6 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -447,7 +447,7 @@ static int global_connect(lua_State *L) { timeout_init(&tcp->tm, -1, -1); buffer_init(&tcp->buf, &tcp->io, &tcp->tm); tcp->sock = SOCKET_INVALID; - tcp->family = AF_UNSPEC; + tcp->family = family; /* allow user to pick local address and port */ memset(&bindhints, 0, sizeof(bindhints)); bindhints.ai_socktype = SOCK_STREAM; @@ -465,6 +465,7 @@ static int global_connect(lua_State *L) { /* try to connect to remote address and port */ memset(&connecthints, 0, sizeof(connecthints)); connecthints.ai_socktype = SOCK_STREAM; + connecthints.ai_protocol = IPPROTO_TCP; /* make sure we try to connect only to the same family */ connecthints.ai_family = tcp->family; err = inet_tryconnect(&tcp->sock, &tcp->family, remoteaddr, remoteserv,