| 53 | } |
| 54 | |
| 55 | static int |
| 56 | ts_lua_vconn_get_remote_addr(lua_State *L) |
| 57 | { |
| 58 | ts_lua_vconn_ctx *vconn_ctx; |
| 59 | int port; |
| 60 | int family; |
| 61 | char sip[128]; |
| 62 | |
| 63 | GET_VCONN_CONTEXT(vconn_ctx, L); |
| 64 | |
| 65 | struct sockaddr const *addr = TSNetVConnRemoteAddrGet(vconn_ctx->vconn); |
| 66 | |
| 67 | if (addr == nullptr) { |
| 68 | lua_pushnil(L); |
| 69 | lua_pushnil(L); |
| 70 | lua_pushnil(L); |
| 71 | } else { |
| 72 | if (addr->sa_family == AF_INET) { |
| 73 | port = ntohs(((struct sockaddr_in *)addr)->sin_port); |
| 74 | inet_ntop(AF_INET, (const void *)&((struct sockaddr_in *)addr)->sin_addr, sip, sizeof(sip)); |
| 75 | family = AF_INET; |
| 76 | } else { |
| 77 | port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port); |
| 78 | inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6 *)addr)->sin6_addr, sip, sizeof(sip)); |
| 79 | family = AF_INET6; |
| 80 | } |
| 81 | |
| 82 | lua_pushstring(L, sip); |
| 83 | lua_pushnumber(L, port); |
| 84 | lua_pushnumber(L, family); |
| 85 | } |
| 86 | |
| 87 | return 3; |
| 88 | } |
| 89 | |
| 90 | static int |
| 91 | ts_lua_vconn_get_fd(lua_State *L) |
nothing calls this directly
no test coverage detected