From: Willy Tarreau Date: Wed, 16 Nov 2016 16:00:14 +0000 (+0100) Subject: CLEANUP: lua: avoid directly calling getsockname/getpeername() X-Git-Tag: v1.7.0~86 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a71f642b6258614fd256493c7687a01b25a081c6;p=thirdparty%2Fhaproxy.git CLEANUP: lua: avoid directly calling getsockname/getpeername() We already have per-protocol functions for this, and they already take care of properly setting the CO_FL_ADDR_*_SET flags. --- diff --git a/src/hlua.c b/src/hlua.c index deff4cc830..7e56b7544d 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -10,8 +10,6 @@ * */ -#include - #include #include @@ -27,13 +25,13 @@ #include -#include #include #include #include #include #include +#include #include #include #include @@ -2083,13 +2081,10 @@ __LJMP static int hlua_socket_getpeername(struct lua_State *L) return 1; } + conn_get_to_addr(conn); if (!(conn->flags & CO_FL_ADDR_TO_SET)) { - unsigned int salen = sizeof(conn->addr.to); - if (getpeername(conn->t.sock.fd, (struct sockaddr *)&conn->addr.to, &salen) == -1) { - lua_pushnil(L); - return 1; - } - conn->flags |= CO_FL_ADDR_TO_SET; + lua_pushnil(L); + return 1; } return MAY_LJMP(hlua_socket_info(L, &conn->addr.to)); @@ -2117,13 +2112,10 @@ static int hlua_socket_getsockname(struct lua_State *L) return 1; } + conn_get_from_addr(conn); if (!(conn->flags & CO_FL_ADDR_FROM_SET)) { - unsigned int salen = sizeof(conn->addr.from); - if (getsockname(conn->t.sock.fd, (struct sockaddr *)&conn->addr.from, &salen) == -1) { - lua_pushnil(L); - return 1; - } - conn->flags |= CO_FL_ADDR_FROM_SET; + lua_pushnil(L); + return 1; } return hlua_socket_info(L, &conn->addr.from);