File tree 1 file changed +17
-3
lines changed
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)
80
80
* erliest phase that nginx allow us to attach those kind of hooks.
81
81
*
82
82
*/
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
+
85
86
const char * client_addr = ngx_str_to_char (addr_text , r -> pool );
86
87
if (client_addr == (char * )-1 ) {
87
88
return NGX_HTTP_INTERNAL_SERVER_ERROR ;
88
89
}
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
+
90
104
old_pool = ngx_http_modsecurity_pcre_malloc_init (r -> pool );
91
105
ret = msc_process_connection (ctx -> modsec_transaction ,
92
106
client_addr , client_port ,
You can’t perform that action at this time.
0 commit comments