Skip to content

Commit

Permalink
Add executable version info.
Browse files Browse the repository at this point in the history
Refactor.
  • Loading branch information
ubihazard committed Oct 1, 2022
1 parent 35244ec commit 968b017
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 53 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ broadcast.exe -b -d

Broadcast packets would be delivered to all network interfaces except the default one. Use <kbd>Ctrl+C</kbd> 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
Expand All @@ -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.*

Expand All @@ -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")!
96 changes: 48 additions & 48 deletions broadcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@

/* -------------------------------------------------------------------------- */

#define numof(carr) (sizeof(carr) / sizeof(carr[0]))

/* -------------------------------------------------------------------------- */

#define APP_TITLE L"BROADcast"
#define APP_VERSION L"1.1"

Expand All @@ -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

Expand All @@ -65,6 +61,10 @@

/* -------------------------------------------------------------------------- */

#define numof(carr) (sizeof(carr) / sizeof(carr[0]))

/* -------------------------------------------------------------------------- */

static HANDLE evnt_stop;
static HANDLE evnt_read;
static HANDLE evnt_write;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 */
Expand All @@ -197,32 +197,32 @@ 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;
}

SetIpInterfaceEntry (&iface_row);
}

runner = runner->Next;
r = r->Next;
}

free (addresses);
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion broadcast.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
</assembly>
18 changes: 18 additions & 0 deletions broadcast.rc
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit 968b017

Please sign in to comment.