From 70c90bbac564f07e97a7ee6a3958c86ccd91dd77 Mon Sep 17 00:00:00 2001 From: Sellier Alexis Date: Tue, 2 Jun 2015 18:01:10 +0200 Subject: [PATCH] Display socket port number for each rtmp connection --- ngx_rtmp_stat_module.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ngx_rtmp_stat_module.c b/ngx_rtmp_stat_module.c index 326a811..1704d22 100644 --- a/ngx_rtmp_stat_module.c +++ b/ngx_rtmp_stat_module.c @@ -329,7 +329,10 @@ ngx_rtmp_stat_client(ngx_http_request_t *r, ngx_chain_t ***lll, ngx_rtmp_session_t *s) { u_char buf[NGX_INT_T_LEN]; - + struct sockaddr_in *tmp; + struct sockaddr_in sa; + socklen_t len = sizeof(struct sockaddr); + #ifdef NGX_RTMP_POOL_DEBUG ngx_rtmp_stat_dump_pool(r, lll, s->connection->pool); #endif @@ -342,6 +345,24 @@ ngx_rtmp_stat_client(ngx_http_request_t *r, ngx_chain_t ***lll, NGX_RTMP_STAT_ES(&s->connection->addr_text); NGX_RTMP_STAT_L(""); + /* + ** Displays socket port number + */ + NGX_RTMP_STAT_L(""); + if (s->connection->listening) + { + tmp = (struct sockaddr_in *) s->connection->listening->sockaddr; + NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), "%ui", + (ngx_uint_t) ntohs(tmp->sin_port)) - buf); + } + else if (getsockname(s->connection->fd, (struct sockaddr *) &sa, &len) != -1) + { + NGX_RTMP_STAT(buf, ngx_snprintf(buf, sizeof(buf), "%ui", + (ngx_uint_t) ntohs(sa.sin_port)) - buf); + } + NGX_RTMP_STAT_L(""); + + NGX_RTMP_STAT_L("