Compare commits

...

4 Commits

Author SHA1 Message Date
bol-van
0098926ca4 winws: minor 2024-06-22 21:40:02 +03:00
bol-van
103f65b155 winws: save some exe size 2024-06-22 21:38:28 +03:00
bol-van
f95be5c603 winws: do not close handle twice 2024-06-22 21:12:55 +03:00
bol-van
fb7fe79022 winws: prevent multiple instances with the same filter 2024-06-22 20:59:26 +03:00
4 changed files with 33 additions and 0 deletions

Binary file not shown.

View File

@ -759,6 +759,13 @@ static bool wf_make_filter(
return true;
}
static unsigned int hash_jen(const void *data,unsigned int len)
{
unsigned int hash;
HASH_JEN(data,len,hash);
return hash;
}
#endif
@ -901,6 +908,7 @@ int main(int argc, char **argv)
char windivert_filter[8192], wf_pf_tcp_src[256], wf_pf_tcp_dst[256], wf_pf_udp_src[256], wf_pf_udp_dst[256], wf_save_file[256];
bool wf_ipv4=true, wf_ipv6=true;
unsigned int IfIdx=0, SubIfIdx=0;
unsigned int hash_wf_tcp=0,hash_wf_udp=0,hash_wf_raw=0,hash_ssid_filter=0;
*windivert_filter = *wf_pf_tcp_src = *wf_pf_tcp_dst = *wf_pf_udp_src = *wf_pf_udp_dst = *wf_save_file = 0;
#endif
@ -1502,6 +1510,7 @@ int main(int argc, char **argv)
}
break;
case 52: /* wf-tcp */
hash_wf_tcp=hash_jen(optarg,strlen(optarg));
if (!wf_make_pf(optarg,"tcp","SrcPort",wf_pf_tcp_src,sizeof(wf_pf_tcp_src)) ||
!wf_make_pf(optarg,"tcp","DstPort",wf_pf_tcp_dst,sizeof(wf_pf_tcp_dst)))
{
@ -1510,6 +1519,7 @@ int main(int argc, char **argv)
}
break;
case 53: /* wf-udp */
hash_wf_udp=hash_jen(optarg,strlen(optarg));
if (!wf_make_pf(optarg,"udp","SrcPort",wf_pf_udp_src,sizeof(wf_pf_udp_src)) ||
!wf_make_pf(optarg,"udp","DstPort",wf_pf_udp_dst,sizeof(wf_pf_udp_dst)))
{
@ -1518,6 +1528,7 @@ int main(int argc, char **argv)
}
break;
case 54: /* wf-raw */
hash_wf_raw=hash_jen(optarg,strlen(optarg));
if (optarg[0]=='@')
{
size_t sz = sizeof(windivert_filter)-1;
@ -1535,6 +1546,7 @@ int main(int argc, char **argv)
wf_save_file[sizeof(wf_save_file) - 1] = '\0';
break;
case 56: /* ssid-filter */
hash_ssid_filter=hash_jen(optarg,strlen(optarg));
{
char *e,*p = optarg;
while (p)
@ -1596,6 +1608,20 @@ int main(int argc, char **argv)
exit_clean(1);
}
}
HANDLE hMutexArg;
{
char mutex_name[128];
snprintf(mutex_name,sizeof(mutex_name),"Global\\winws_arg_%u_%u_%u_%u_%u_%u_%u_%u",hash_wf_tcp,hash_wf_udp,hash_wf_raw,hash_ssid_filter,IfIdx,SubIfIdx,wf_ipv4,wf_ipv6);
hMutexArg = CreateMutexA(NULL,TRUE,mutex_name);
if (hMutexArg && GetLastError()==ERROR_ALREADY_EXISTS)
{
CloseHandle(hMutexArg); hMutexArg = NULL;
printf("A copy of winws is already running with the same filter\n");
goto exiterr;
}
}
#endif
// not specified - use desync_ttl value instead
@ -1644,6 +1670,13 @@ int main(int argc, char **argv)
ex:
rawsend_cleanup();
cleanup_params();
#ifdef __CYGWIN__
if (hMutexArg)
{
ReleaseMutex(hMutexArg);
CloseHandle(hMutexArg);
}
#endif
return result;
exiterr:
result = 1;