@@ -86,7 +86,8 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
86
86
{
87
87
struct lws_context * cx = a -> vhost -> context ;
88
88
struct lws_context_per_thread * pt ;
89
- int n , opt = 1 , limit = 1 ;
89
+ int n , opt = 1 , limit = 1 , san = 2 ;
90
+ const char * _iface = a -> vhost -> iface ;
90
91
lws_sockfd_type sockfd ;
91
92
struct lws * wsi ;
92
93
int m = 0 , is ;
@@ -97,21 +98,32 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
97
98
(void )method_names ;
98
99
(void )opt ;
99
100
101
+ #ifdef LWS_WITH_IPV6
102
+ if (LWS_IPV6_ENABLED (a -> vhost )) {
103
+ if (_iface && !strcmp (_iface , "fe80::1" ))
104
+ _iface = "lo" ;
105
+ }
106
+ #endif
107
+
100
108
lwsl_info ("%s: af %d\n" , __func__ , (int )a -> af );
101
109
102
110
if (lws_vhost_foreach_listen_wsi (a -> vhost -> context , a , check_extant ))
103
111
return 0 ;
104
112
105
113
deal :
106
114
107
- if (a -> vhost -> iface ) {
115
+ if (!san -- ) {
116
+ return -1 ;
117
+ }
118
+
119
+ if (_iface ) {
108
120
109
121
/*
110
122
* let's check before we do anything else about the disposition
111
123
* of the interface he wants to bind to...
112
124
*/
113
125
is = lws_socket_bind (a -> vhost , NULL , LWS_SOCK_INVALID ,
114
- a -> vhost -> listen_port , a -> vhost -> iface ,
126
+ a -> vhost -> listen_port , _iface ,
115
127
a -> af );
116
128
lwsl_debug ("initial if check says %d\n" , is );
117
129
@@ -158,7 +170,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
158
170
159
171
/* first time */
160
172
lwsl_err ("%s: VH %s: iface %s port %d DOESN'T EXIST\n" ,
161
- __func__ , a -> vhost -> name , a -> vhost -> iface ,
173
+ __func__ , a -> vhost -> name , _iface ,
162
174
a -> vhost -> listen_port );
163
175
164
176
return (a -> info -> options &
@@ -172,7 +184,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
172
184
return -1 ;
173
185
174
186
lwsl_err ("%s: VH %s: iface %s port %d NOT USABLE\n" ,
175
- __func__ , a -> vhost -> name , a -> vhost -> iface ,
187
+ __func__ , a -> vhost -> name , _iface ,
176
188
a -> vhost -> listen_port );
177
189
178
190
return (a -> info -> options &
@@ -273,7 +285,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
273
285
274
286
is = lws_socket_bind (a -> vhost , NULL , sockfd ,
275
287
a -> vhost -> listen_port ,
276
- a -> vhost -> iface , a -> af );
288
+ _iface , a -> af );
277
289
278
290
if (is == LWS_ITOSA_BUSY ) {
279
291
/* treat as fatal */
@@ -288,9 +300,9 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
288
300
* here despite we earlier confirmed it.
289
301
*/
290
302
if (is < 0 ) {
291
- lwsl_info ("%s: lws_socket_bind says %d\n" , __func__ , is );
303
+ lwsl_info ("%s: A lws_socket_bind says %d\n" , __func__ , is );
292
304
compatible_close (sockfd );
293
- if (a -> vhost -> iface )
305
+ if (_iface )
294
306
goto deal ;
295
307
return -1 ;
296
308
}
@@ -316,7 +328,7 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
316
328
wsi -> unix_skt = 1 ;
317
329
a -> vhost -> listen_port = is ;
318
330
319
- lwsl_debug ("%s: lws_socket_bind says %d\n" , __func__ , is );
331
+ lwsl_debug ("%s: B lws_socket_bind says %d\n" , __func__ , is );
320
332
}
321
333
322
334
wsi -> desc .sockfd = sockfd ;
@@ -375,19 +387,19 @@ _lws_vhost_init_server_af(struct vh_sock_args *a)
375
387
& a -> vhost -> context -> lcg [LWSLCG_WSI ],
376
388
& wsi -> lc , "listen|%s|%s|%d" ,
377
389
a -> vhost -> name ,
378
- a -> vhost -> iface ? a -> vhost -> iface : "" ,
390
+ _iface ? _iface : "" ,
379
391
(int )a -> vhost -> listen_port );
380
392
381
393
} /* for each thread able to independently listen */
382
394
383
395
if (!lws_check_opt (cx -> options , LWS_SERVER_OPTION_EXPLICIT_VHOSTS )) {
384
396
#ifdef LWS_WITH_UNIX_SOCK
385
397
if (a -> af == AF_UNIX )
386
- lwsl_info (" Listening on \"%s\"\n" , a -> vhost -> iface );
398
+ lwsl_info (" Listening on \"%s\"\n" , _iface );
387
399
else
388
400
#endif
389
401
lwsl_info (" Listening on %s:%d\n" ,
390
- a -> vhost -> iface ,
402
+ _iface ,
391
403
a -> vhost -> listen_port );
392
404
}
393
405
0 commit comments