@ -410,13 +410,33 @@ static int win_main(const char *windivert_filter)
WINDIVERT_ADDRESS wa ;
WINDIVERT_ADDRESS wa ;
char ifout [ 22 ] ;
char ifout [ 22 ] ;
if ( ! windivert_init ( windivert_filter ) )
pre_desync ( ) ;
for ( ; ; )
{
if ( ! wlan_filter_match ( & params . ssid_filter ) )
{
printf ( " logical network is not present. waiting it to appear. \n " ) ;
fflush ( stdout ) ;
do
{
if ( bQuit )
{
DLOG ( " QUIT requested \n " )
return 0 ;
}
usleep ( 500000 ) ;
}
while ( ! wlan_filter_match ( & params . ssid_filter ) ) ;
printf ( " logical network now present \n " ) ;
fflush ( stdout ) ;
}
if ( ! windivert_init ( windivert_filter , & params . ssid_filter ) )
return w_win32_error ;
return w_win32_error ;
printf ( " windivert initialized. capture is started. \n " ) ;
printf ( " windivert initialized. capture is started. \n " ) ;
pre_desync ( ) ;
// cygwin auto flush fails when piping
// cygwin auto flush fails when piping
fflush ( stdout ) ;
fflush ( stdout ) ;
fflush ( stderr ) ;
fflush ( stderr ) ;
@ -431,10 +451,16 @@ static int win_main(const char *windivert_filter)
DLOG ( " windivert: ignoring too large packet \n " )
DLOG ( " windivert: ignoring too large packet \n " )
continue ; // too large packet
continue ; // too large packet
}
}
else if ( errno = = ENODEV )
{
printf ( " logical network disappeared. deinitializing windivert. \n " ) ;
rawsend_cleanup ( ) ;
break ;
}
else if ( errno = = EINTR )
else if ( errno = = EINTR )
{
{
DLOG ( " QUIT requested \n " )
DLOG ( " QUIT requested \n " )
break ;
return 0 ;
}
}
fprintf ( stderr , " windivert: recv failed. errno %d \n " , errno ) ;
fprintf ( stderr , " windivert: recv failed. errno %d \n " , errno ) ;
return w_win32_error ;
return w_win32_error ;
@ -477,6 +503,7 @@ static int win_main(const char *windivert_filter)
fflush ( stdout ) ;
fflush ( stdout ) ;
fflush ( stderr ) ;
fflush ( stderr ) ;
}
}
}
return 0 ;
return 0 ;
}
}
@ -521,6 +548,9 @@ static void cleanup_params(void)
StrPoolDestroy ( & params . hostlist_exclude ) ;
StrPoolDestroy ( & params . hostlist_exclude ) ;
StrPoolDestroy ( & params . hostlist ) ;
StrPoolDestroy ( & params . hostlist ) ;
HostFailPoolDestroy ( & params . hostlist_auto_fail_counters ) ;
HostFailPoolDestroy ( & params . hostlist_auto_fail_counters ) ;
# ifdef __CYGWIN__
strlist_destroy ( & params . ssid_filter ) ;
# endif
}
}
static void exit_clean ( int code )
static void exit_clean ( int code )
{
{
@ -760,6 +790,8 @@ static void exithelp(void)
" --wf-udp=[~]port1[-port2] \t \t \t ; UDP port filter. ~ means negation. multiple comma separated values allowed. \n "
" --wf-udp=[~]port1[-port2] \t \t \t ; UDP port filter. ~ means negation. multiple comma separated values allowed. \n "
" --wf-raw=<filter>|@<filename> \t \t \t ; raw windivert filter string or filename \n "
" --wf-raw=<filter>|@<filename> \t \t \t ; raw windivert filter string or filename \n "
" --wf-save=<filename> \t \t \t \t ; save windivert filter string to a file and exit \n "
" --wf-save=<filename> \t \t \t \t ; save windivert filter string to a file and exit \n "
" \n LOGICAL NETWORK FILTER: \n "
" --ssid-filter=ssid1[,ssid2,ssid3,...] \t \t ; enable winws only if any of specified wifi SSIDs connected \n "
# endif
# endif
" \n HOSTLIST FILTER: \n "
" \n HOSTLIST FILTER: \n "
" --hostlist=<filename> \t \t \t \t ; apply dpi desync only to the listed hosts (one host per line, subdomains auto apply, gzip supported, multiple hostlists allowed) \n "
" --hostlist=<filename> \t \t \t \t ; apply dpi desync only to the listed hosts (one host per line, subdomains auto apply, gzip supported, multiple hostlists allowed) \n "
@ -915,7 +947,9 @@ int main(int argc, char **argv)
LIST_INIT ( & params . hostlist_files ) ;
LIST_INIT ( & params . hostlist_files ) ;
LIST_INIT ( & params . hostlist_exclude_files ) ;
LIST_INIT ( & params . hostlist_exclude_files ) ;
# ifndef __CYGWIN__
# ifdef __CYGWIN__
LIST_INIT ( & params . ssid_filter ) ;
# else
if ( can_drop_root ( ) ) // are we root ?
if ( can_drop_root ( ) ) // are we root ?
{
{
params . uid = params . gid = 0x7FFFFFFF ; // default uid:gid
params . uid = params . gid = 0x7FFFFFFF ; // default uid:gid
@ -1002,6 +1036,7 @@ int main(int argc, char **argv)
{ " wf-udp " , required_argument , 0 , 0 } , // optidx=53
{ " wf-udp " , required_argument , 0 , 0 } , // optidx=53
{ " wf-raw " , required_argument , 0 , 0 } , // optidx=54
{ " wf-raw " , required_argument , 0 , 0 } , // optidx=54
{ " wf-save " , required_argument , 0 , 0 } , // optidx=55
{ " wf-save " , required_argument , 0 , 0 } , // optidx=55
{ " ssid-filter " , required_argument , 0 , 0 } , // optidx=56
# endif
# endif
{ NULL , 0 , NULL , 0 }
{ NULL , 0 , NULL , 0 }
} ;
} ;
@ -1499,6 +1534,24 @@ int main(int argc, char **argv)
strncpy ( wf_save_file , optarg , sizeof ( wf_save_file ) ) ;
strncpy ( wf_save_file , optarg , sizeof ( wf_save_file ) ) ;
wf_save_file [ sizeof ( wf_save_file ) - 1 ] = ' \0 ' ;
wf_save_file [ sizeof ( wf_save_file ) - 1 ] = ' \0 ' ;
break ;
break ;
case 56 : /* ssid-filter */
{
char * e , * p = optarg ;
while ( p )
{
e = strchr ( p , ' , ' ) ;
if ( e ) * e + + = 0 ;
if ( * p & & ! strlist_add ( & params . ssid_filter , p ) )
{
fprintf ( stderr , " strlist_add failed \n " ) ;
exit_clean ( 1 ) ;
}
p = e ;
}
}
break ;
# endif
# endif
}
}
}
}