MCPcopy Create free account
hub / github.com/apache/trafficserver / ts_lua_vconn_get_remote_addr

Function ts_lua_vconn_get_remote_addr

plugins/lua/ts_lua_vconn.cc:55–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55static int
56ts_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
90static int
91ts_lua_vconn_get_fd(lua_State *L)

Callers

nothing calls this directly

Calls 1

TSNetVConnRemoteAddrGetFunction · 0.85

Tested by

no test coverage detected