add WIN32 code for finding system MAC address

don't buffer stdout in WIN32 when debug_log=false
This commit is contained in:
fduncanh
2022-09-03 03:32:37 -04:00
parent 1408b07415
commit c3b31d5edf
5 changed files with 46 additions and 11 deletions

View File

@@ -461,9 +461,7 @@ compiler)</h2>
<p>Limitations: “<code>sudo make install</code>” does not work (due to
lack of “sudo” equivalent on this platform); GStreamer sound was so far
only confirmed to work with the DirectSound audiosink option
<code>-as directsoundsink</code>”. The identification of the “true” MAC
address of the UxPlay server is not yet implemented on Windows, so a
random MAC address is used.</p>
<code>-as directsoundsink</code>”.</p>
<ol type="1">
<li><p>Download and install <strong>Bonjour SDK for Windows
v3.0</strong> from the official Apple site <a

View File

@@ -383,12 +383,14 @@ as the device is rotated).
## Building UxPlay on Windows (tested on Windows 10 64bit, using MSYS2 and MinGW-64 compiler)
Limitations: "`sudo make install`" does not work (due to lack of "sudo" equivalent on this platform); GStreamer sound was so far only confirmed to work with the DirectSound audiosink option "`-as directsoundsink`". The identification of the "true" MAC address of the UxPlay server is not yet implemented on Windows, so a random MAC address is used.
Limitations: "`sudo make install`" does not work (due to lack of "sudo" equivalent on this platform);
GStreamer sound was so far only confirmed to work with the DirectSound audiosink option "`-as directsoundsink`".
1. Download and install **Bonjour SDK for Windows v3.0** from the official Apple site
[https://developer.apple.com/download](https://developer.apple.com/download/all/?q=Bonjour%20SDK%20for%20Windows)
2. (This is for the MSYS2 build enviroment; other build environments may also work, but are not yet tested): download and install MSYS2 from the official site https://www.msys2.org/
2. (This is for the MSYS2 build enviroment; other build environments may also work, but are not yet tested):
download and install MSYS2 from the official site https://www.msys2.org/
3. For building on Windows 64 bit, install the **MinGW-64** compiler and cmake ([MSYS2 packages](https://packages.msys2.org/package/) are
installed with a variant of the "pacman" package manager adapted from Arch Linux). After installation, you can add this

View File

@@ -465,8 +465,6 @@ landscape mode as the device is rotated).
Limitations: "`sudo make install`" does not work (due to lack of "sudo"
equivalent on this platform); GStreamer sound was so far only confirmed
to work with the DirectSound audiosink option "`-as directsoundsink`".
The identification of the "true" MAC address of the UxPlay server is not
yet implemented on Windows, so a random MAC address is used.
1. Download and install **Bonjour SDK for Windows v3.0** from the
official Apple site

View File

@@ -63,6 +63,7 @@ elseif( WIN32 )
playfair
llhttp
wsock32
iphlpapi
ws2_32 )
else()
target_link_libraries( airplay PUBLIC

View File

@@ -28,7 +28,8 @@
#ifdef _WIN32 /*modifications for Windows compilation */
#include <glib.h>
#include <unordered_map>
#include <windows.h>
#include <winsock2.h>
#include <iphlpapi.h>
#else
#include <glib-unix.h>
#include <sys/utsname.h>
@@ -288,10 +289,40 @@ static int parse_hw_addr (std::string str, std::vector<char> &hw_addr) {
static std::string find_mac () {
/* finds the MAC address of a network interface *
* in a Linux, *BSD or macOS system. */
* in a Windows, Linux, *BSD or macOS system. */
std::string mac = "";
char str[3];
#ifdef _WIN32
/* for now, don't find true MAC address if compiled for Windows */
ULONG buflen = sizeof(IP_ADAPTER_ADDRESSES);
PIP_ADAPTER_ADDRESSES addresses = (IP_ADAPTER_ADDRESSES*) malloc(buflen);
if (addresses == NULL) {
return mac;
}
if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, addresses, &buflen) == ERROR_BUFFER_OVERFLOW) {
free(addresses);
addresses = (IP_ADAPTER_ADDRESSES*) malloc(buflen);
if (addresses == NULL) {
return mac;
}
}
if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, addresses, &buflen) == NO_ERROR) {
for (PIP_ADAPTER_ADDRESSES address = addresses; address != NULL; address = address->Next) {
if (address->PhysicalAddressLength != 6 /* MAC has 6 octets */
|| (address->IfType != 6 && address->IfType != 71) /* Ethernet or Wireless interface */
|| address->OperStatus != 1) { /* interface is up */
continue;
}
mac.erase();
for (int i = 0; i < 6; i++) {
sprintf(str,"%02x", int(address->PhysicalAddress[i]));
mac = mac + str;
if (i < 5) mac = mac + ":";
}
break;
}
}
free(addresses);
return mac;
#else
struct ifaddrs *ifap, *ifaptr;
int non_null_octets = 0;
@@ -315,7 +346,6 @@ static std::string find_mac () {
#endif
if (non_null_octets) {
mac.erase();
char str[3];
for (int i = 0; i < 6 ; i++) {
sprintf(str,"%02x", octet[i]);
mac = mac + str;
@@ -759,6 +789,12 @@ int main (int argc, char *argv[]) {
use_audio = false;
}
#ifdef _WIN32 /* don't buffer stdout in WIN32 when debug_log = false */
if (!debug_log) {
setbuf(stdout, NULL);
}
#endif
#if __APPLE__
/* force use of -nc option on macOS */
LOGI("macOS detected: use -nc option as workaround for GStreamer problem");