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 @@ -76,13 +76,27 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
76
76
* erliest phase that nginx allow us to attach those kind of hooks.
77
77
*
78
78
*/
79
- int client_port = htons (((struct sockaddr_in * ) connection -> sockaddr )-> sin_port );
80
- int server_port = htons (((struct sockaddr_in * ) connection -> listening -> sockaddr )-> sin_port );
79
+ int client_port = ngx_inet_get_port (connection -> sockaddr );
80
+ int server_port = ngx_inet_get_port (connection -> local_sockaddr );
81
+
81
82
const char * client_addr = ngx_str_to_char (addr_text , r -> pool );
82
83
if (client_addr == (char * )-1 ) {
83
84
return NGX_HTTP_INTERNAL_SERVER_ERROR ;
84
85
}
85
- const char * server_addr = inet_ntoa (((struct sockaddr_in * ) connection -> sockaddr )-> sin_addr );
86
+
87
+ ngx_str_t s ;
88
+ u_char addr [NGX_SOCKADDR_STRLEN ];
89
+ s .len = NGX_SOCKADDR_STRLEN ;
90
+ s .data = addr ;
91
+ if (ngx_connection_local_sockaddr (r -> connection , & s , 0 ) != NGX_OK ) {
92
+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
93
+ }
94
+
95
+ const char * server_addr = ngx_str_to_char (s , r -> pool );
96
+ if (server_addr == (char * )-1 ) {
97
+ return NGX_HTTP_INTERNAL_SERVER_ERROR ;
98
+ }
99
+
86
100
old_pool = ngx_http_modsecurity_pcre_malloc_init (r -> pool );
87
101
ret = msc_process_connection (ctx -> modsec_transaction ,
88
102
client_addr , client_port ,
You can’t perform that action at this time.
0 commit comments