diff --git a/README.md b/README.md index 6fdd01b..7fe411f 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ broadcast.exe -b -d Broadcast packets would be delivered to all network interfaces except the default one. Use Ctrl+C to exit BROADcast cleanly. -As a bonus feature BROADcast allows to make any interface the default (or preferred). It does so by taking the current metric value of the interface you desire to turn into default and adding it to each other interface metric value, making it the lowest metric value of all: +As a bonus feature, BROADcast allows to make any interface the default (or preferred) one. It does so by taking the current metric value of the interface you desire to turn into default and adding it to each other interface metric value, making it the lowest metric value of all: ```bat BROADcast.exe -i "Interface" -m @@ -81,7 +81,7 @@ broadcast.exe [install | uninstall] ### OpenVPN -BROADcast repository contains an example OpenVPN configuration and scripts for running BROADcast after starting a OpenVPN server using a TAP device. +BROADcast repository contains an example OpenVPN configuration and scripts for running BROADcast after starting an OpenVPN server using a TAP device. *Note that if you intend to start BROADcast from OpenVPN using its start/stop script functionality, you must also run OpenVPN with administrator privileges, just like BROADcast.* @@ -93,6 +93,6 @@ While not directly related to BROADcast or UDP broadcast at all, another useful Unlike BROADcast, which provides a fix for UDP protocol, ForceBindIP provides a similar fix for TCP protocol by forcing an application to bind (or listen) on a particular network interface instead of the one it automatically chooses (which is often not the one that you want). -## Support +## ⭐ Support -If you find [BROADcast](https://github.com/ubihazard/broadcast) useful, you can [buy me a ☕](https://www.buymeacoffee.com/ubihazard "Show support")! +Making quality software is hard and time-consuming. If you find [BROADcast](https://github.com/ubihazard/broadcast) useful, you can [buy me a ☕](https://www.buymeacoffee.com/ubihazard "Donate")! diff --git a/broadcast.c b/broadcast.c index 215c3a0..1d65ef5 100644 --- a/broadcast.c +++ b/broadcast.c @@ -33,10 +33,6 @@ /* -------------------------------------------------------------------------- */ -#define numof(carr) (sizeof(carr) / sizeof(carr[0])) - -/* -------------------------------------------------------------------------- */ - #define APP_TITLE L"BROADcast" #define APP_VERSION L"1.1" @@ -47,7 +43,7 @@ #define BUF_SIZE 65535 #endif -#if (BUF_SIZE < 256 || BUF_SIZE > 0x10000) +#if BUF_SIZE < 256 || BUF_SIZE > 0x10000 #error "Invalid definition of `BUF_SIZE`" #endif @@ -65,6 +61,10 @@ /* -------------------------------------------------------------------------- */ +#define numof(carr) (sizeof(carr) / sizeof(carr[0])) + +/* -------------------------------------------------------------------------- */ + static HANDLE evnt_stop; static HANDLE evnt_read; static HANDLE evnt_write; @@ -140,7 +140,7 @@ static int metric_update (const wchar_t* const iface, BOOL const manual) ULONG metric = 0; /* Obtain the list of Ethernet & Wi-Fi adapters */ - PIP_ADAPTER_ADDRESSES addresses = NULL, runner; + PIP_ADAPTER_ADDRESSES addresses = NULL, r; DWORD addresses_sz = 0, tries = 0, result; do { @@ -170,23 +170,23 @@ static int metric_update (const wchar_t* const iface, BOOL const manual) /* Look up the requested network interface */ if (manual) { - runner = addresses; + r = addresses; - while (runner != NULL) + while (r != NULL) { - if ((runner->IfType != IF_TYPE_ETHERNET_CSMACD) - && (runner->IfType != IF_TYPE_IEEE80211)) { - runner = runner->Next; + if ((r->IfType != IF_TYPE_ETHERNET_CSMACD) + && (r->IfType != IF_TYPE_IEEE80211)) { + r = r->Next; continue; } - if (_wcsicmp (iface, runner->FriendlyName) == 0) { + if (_wcsicmp (iface, r->FriendlyName) == 0) { /* Remember old metric */ - metric = runner->Ipv4Metric; + metric = r->Ipv4Metric; break; } - runner = runner->Next; + r = r->Next; } /* Couldn't find */ @@ -197,24 +197,24 @@ static int metric_update (const wchar_t* const iface, BOOL const manual) } /* Update metric values */ - runner = addresses; + r = addresses; - while (runner != NULL) { - if ((runner->IfType != IF_TYPE_ETHERNET_CSMACD) - && (runner->IfType != IF_TYPE_IEEE80211)) { - runner = runner->Next; + while (r != NULL) { + if ((r->IfType != IF_TYPE_ETHERNET_CSMACD) + && (r->IfType != IF_TYPE_IEEE80211)) { + r = r->Next; continue; } - if (_wcsicmp (iface, runner->FriendlyName) != 0) { + if (_wcsicmp (iface, r->FriendlyName) != 0) { MIB_IPINTERFACE_ROW iface_row; InitializeIpInterfaceEntry (&iface_row); - iface_row.InterfaceLuid = runner->Luid; + iface_row.InterfaceLuid = r->Luid; iface_row.Family = AF_INET; if (manual) { iface_row.UseAutomaticMetric = FALSE; - iface_row.Metric = runner->Ipv4Metric + metric; + iface_row.Metric = r->Ipv4Metric + metric; } else { iface_row.UseAutomaticMetric = TRUE; } @@ -222,7 +222,7 @@ static int metric_update (const wchar_t* const iface, BOOL const manual) SetIpInterfaceEntry (&iface_row); } - runner = runner->Next; + r = r->Next; } free (addresses); @@ -231,9 +231,11 @@ static int metric_update (const wchar_t* const iface, BOOL const manual) /* -------------------------------------------------------------------------- */ -BOOL already_stopped; +static void svc_report (DWORD, DWORD, DWORD); + +static BOOL already_stopped; -static void signal_handler (int signum) +static void signal_handler (int const signum) { if (already_stopped) return; already_stopped = TRUE; @@ -519,8 +521,6 @@ static void broadcast_loop (void) HeapFree (GetProcessHeap(), 0, fwd_table); } -static void svc_report (DWORD, DWORD, DWORD); - static void broadcast_start (void) { /* Initialize Winsock */ @@ -606,27 +606,8 @@ static void broadcast_start (void) /* -------------------------------------------------------------------------- */ -static BOOL is_admin (void) -{ - BOOL ret = FALSE; - HANDLE token = NULL; - if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &token)) { - TOKEN_ELEVATION elev; - DWORD size = sizeof(TOKEN_ELEVATION); - if (GetTokenInformation (token, TokenElevation, &elev, sizeof(elev), &size)) { - ret = elev.TokenIsElevated; - } - } - if (token != NULL) { - CloseHandle (token); - } - return ret; -} - -/* -------------------------------------------------------------------------- */ - -SERVICE_STATUS svc_status; -SERVICE_STATUS_HANDLE svc_status_hndl; +static SERVICE_STATUS svc_status; +static SERVICE_STATUS_HANDLE svc_status_hndl; static BOOL svc_install (void) { @@ -724,6 +705,25 @@ static void WINAPI svc_main (DWORD const argc, LPWSTR* const argv) svc_report (SERVICE_STOPPED, fail ? EXIT_FAILURE : EXIT_SUCCESS, 0); } +/* -------------------------------------------------------------------------- */ + +static BOOL is_admin (void) +{ + BOOL ret = FALSE; + HANDLE token = NULL; + if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &token)) { + TOKEN_ELEVATION elev; + DWORD size = sizeof(TOKEN_ELEVATION); + if (GetTokenInformation (token, TokenElevation, &elev, sizeof(elev), &size)) { + ret = elev.TokenIsElevated; + } + } + if (token != NULL) { + CloseHandle (token); + } + return ret; +} + /* ========================================================================== */ int wmain (int argc, wchar_t** argv) diff --git a/broadcast.exe.manifest b/broadcast.exe.manifest index 6bbd910..1853afd 100644 --- a/broadcast.exe.manifest +++ b/broadcast.exe.manifest @@ -20,4 +20,4 @@ - \ No newline at end of file + diff --git a/broadcast.rc b/broadcast.rc index 2c9476f..51d3959 100644 --- a/broadcast.rc +++ b/broadcast.rc @@ -1 +1,19 @@ MAINICON ICON "icon\icon.ico" + +1 VERSIONINFO +FILEVERSION 1,1,0,0 +PRODUCTVERSION 1,1,0,0 +{ + BLOCK "StringFileInfo" + { + BLOCK "040904B0" + { + VALUE "CompanyName", "Ubihazard\0" + VALUE "LegalCopyright", "© Ubihazard\0" + VALUE "ProductName", "BROADcast\0" + VALUE "ProductVersion", "1.1.0.0\0" + VALUE "FileVersion", "1.1.0.0\0" + VALUE "FileDescription", "https://github.com/ubihazard/broadcast\0" + } + } +}