File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -80,13 +80,27 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
8080 * erliest phase that nginx allow us to attach those kind of hooks.
8181 *
8282 */
83- int client_port = htons (((struct sockaddr_in * ) connection -> sockaddr )-> sin_port );
84- int server_port = htons (((struct sockaddr_in * ) connection -> listening -> sockaddr )-> sin_port );
83+ int client_port = ngx_inet_get_port (connection -> sockaddr );
84+ int server_port = ngx_inet_get_port (connection -> local_sockaddr );
85+
8586 const char * client_addr = ngx_str_to_char (addr_text , r -> pool );
8687 if (client_addr == (char * )-1 ) {
8788 return NGX_HTTP_INTERNAL_SERVER_ERROR ;
8889 }
89- const char * server_addr = inet_ntoa (((struct sockaddr_in * ) connection -> sockaddr )-> sin_addr );
90+
91+ ngx_str_t s ;
92+ u_char addr [NGX_SOCKADDR_STRLEN ];
93+ s .len = NGX_SOCKADDR_STRLEN ;
94+ s .data = addr ;
95+ if (ngx_connection_local_sockaddr (r -> connection , & s , 0 ) != NGX_OK ) {
96+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
97+ }
98+
99+ const char * server_addr = ngx_str_to_char (s , r -> pool );
100+ if (server_addr == (char * )-1 ) {
101+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
102+ }
103+
90104 old_pool = ngx_http_modsecurity_pcre_malloc_init (r -> pool );
91105 ret = msc_process_connection (ctx -> modsec_transaction ,
92106 client_addr , client_port ,
You can’t perform that action at this time.
0 commit comments