Browse Source

Created a new class: MACAddress, which replaces the old MAC address detection functions with a cleaner implementation.

tags/2021-05-28
Julian Storer 15 years ago
parent
commit
cf641969d0
25 changed files with 516 additions and 374 deletions
  1. +6
    -0
      Builds/Linux/Makefile
  2. +6
    -0
      Builds/MacOSX/Juce.xcodeproj/project.pbxproj
  3. +2
    -0
      Builds/VisualStudio2005/Juce.vcproj
  4. +2
    -0
      Builds/VisualStudio2008/Juce.vcproj
  5. +2
    -0
      Builds/VisualStudio2008_DLL/Juce.vcproj
  6. +2
    -0
      Builds/VisualStudio2010/Juce.vcxproj
  7. +6
    -0
      Builds/VisualStudio2010/Juce.vcxproj.filters
  8. +6
    -0
      Builds/iPhone/Juce.xcodeproj/project.pbxproj
  9. +4
    -0
      Juce.jucer
  10. +1
    -0
      amalgamation/juce_amalgamated_template.cpp
  11. +13
    -1
      extras/juce demo/Source/ApplicationStartup.cpp
  12. +132
    -150
      juce_amalgamated.cpp
  13. +71
    -35
      juce_amalgamated.h
  14. +0
    -20
      src/core/juce_SystemStats.cpp
  15. +6
    -37
      src/core/juce_SystemStats.h
  16. +7
    -2
      src/core/juce_Uuid.cpp
  17. +88
    -0
      src/io/network/juce_MACAddress.cpp
  18. +90
    -0
      src/io/network/juce_MACAddress.h
  19. +3
    -0
      src/juce_core_includes.h
  20. +1
    -0
      src/native/juce_linux_NativeCode.cpp
  21. +1
    -0
      src/native/juce_mac_NativeCode.mm
  22. +1
    -0
      src/native/juce_win32_NativeCode.cpp
  23. +7
    -24
      src/native/linux/juce_linux_Network.cpp
  24. +7
    -23
      src/native/mac/juce_mac_Network.mm
  25. +52
    -82
      src/native/windows/juce_win32_Network.cpp

+ 6
- 0
Builds/Linux/Makefile View File

@@ -276,6 +276,7 @@ OBJECTS := \
$(OBJDIR)/juce_NamedPipe_b3a205e0.o \
$(OBJDIR)/juce_TemporaryFile_935f3fc6.o \
$(OBJDIR)/juce_ZipFile_16fbb396.o \
$(OBJDIR)/juce_MACAddress_b81987ed.o \
$(OBJDIR)/juce_Socket_cf39c63b.o \
$(OBJDIR)/juce_URL_d6b7cff1.o \
$(OBJDIR)/juce_BufferedInputStream_c71b2b68.o \
@@ -1548,6 +1549,11 @@ $(OBJDIR)/juce_ZipFile_16fbb396.o: ../../src/io/files/juce_ZipFile.cpp
@echo "Compiling juce_ZipFile.cpp"
@$(CXX) $(CXXFLAGS) -o "$@" -c "$<"
$(OBJDIR)/juce_MACAddress_b81987ed.o: ../../src/io/network/juce_MACAddress.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling juce_MACAddress.cpp"
@$(CXX) $(CXXFLAGS) -o "$@" -c "$<"
$(OBJDIR)/juce_Socket_cf39c63b.o: ../../src/io/network/juce_Socket.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling juce_Socket.cpp"


+ 6
- 0
Builds/MacOSX/Juce.xcodeproj/project.pbxproj View File

@@ -245,6 +245,7 @@
BBCA4C01CEF1EDA75625D6DC = { isa = PBXBuildFile; fileRef = D9B3C04F8EB4228DD59002E7; };
136FB9588C834E6F4A1EEBFB = { isa = PBXBuildFile; fileRef = 17C3AF03FF7AE88AE0C73311; };
274415D1C0AE9BF56FAAE791 = { isa = PBXBuildFile; fileRef = 4035C867821E9B5887AA25FB; };
CBAD975785BD26A0DA9417B6 = { isa = PBXBuildFile; fileRef = EFA58F646B69B227AEF14140; };
2A8F78D412AC7EC0C2998A1A = { isa = PBXBuildFile; fileRef = 06B06C420341B005DFF951D2; };
2DD969525DEF4AD408E9BB59 = { isa = PBXBuildFile; fileRef = AD7A1C2C82EE714EBDD52EFC; };
059B694C912BE81023D5240D = { isa = PBXBuildFile; fileRef = D4211E697F43821CDBCE4F24; };
@@ -888,6 +889,8 @@
75D6F1C676E178DEA8B86849 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_TemporaryFile.h; path = ../../src/io/files/juce_TemporaryFile.h; sourceTree = SOURCE_ROOT; };
4035C867821E9B5887AA25FB = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_ZipFile.cpp; path = ../../src/io/files/juce_ZipFile.cpp; sourceTree = SOURCE_ROOT; };
4D005659935C7DE99C2C01E2 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_ZipFile.h; path = ../../src/io/files/juce_ZipFile.h; sourceTree = SOURCE_ROOT; };
EFA58F646B69B227AEF14140 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_MACAddress.cpp; path = ../../src/io/network/juce_MACAddress.cpp; sourceTree = SOURCE_ROOT; };
7241B187AA9B0217838B6052 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_MACAddress.h; path = ../../src/io/network/juce_MACAddress.h; sourceTree = SOURCE_ROOT; };
06B06C420341B005DFF951D2 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_Socket.cpp; path = ../../src/io/network/juce_Socket.cpp; sourceTree = SOURCE_ROOT; };
286206E754AC14DEAF88FD43 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_Socket.h; path = ../../src/io/network/juce_Socket.h; sourceTree = SOURCE_ROOT; };
AD7A1C2C82EE714EBDD52EFC = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_URL.cpp; path = ../../src/io/network/juce_URL.cpp; sourceTree = SOURCE_ROOT; };
@@ -1663,6 +1666,8 @@
4035C867821E9B5887AA25FB,
4D005659935C7DE99C2C01E2 ); name = files; sourceTree = "<group>"; };
13FBF71BD76A08C8971C6351 = { isa = PBXGroup; children = (
EFA58F646B69B227AEF14140,
7241B187AA9B0217838B6052,
06B06C420341B005DFF951D2,
286206E754AC14DEAF88FD43,
AD7A1C2C82EE714EBDD52EFC,
@@ -2165,6 +2170,7 @@
BBCA4C01CEF1EDA75625D6DC,
136FB9588C834E6F4A1EEBFB,
274415D1C0AE9BF56FAAE791,
CBAD975785BD26A0DA9417B6,
2A8F78D412AC7EC0C2998A1A,
2DD969525DEF4AD408E9BB59,
059B694C912BE81023D5240D,


+ 2
- 0
Builds/VisualStudio2005/Juce.vcproj View File

@@ -807,6 +807,8 @@
<File RelativePath="..\..\src\io\files\juce_ZipFile.h"/>
</Filter>
<Filter Name="network">
<File RelativePath="..\..\src\io\network\juce_MACAddress.cpp"/>
<File RelativePath="..\..\src\io\network\juce_MACAddress.h"/>
<File RelativePath="..\..\src\io\network\juce_Socket.cpp"/>
<File RelativePath="..\..\src\io\network\juce_Socket.h"/>
<File RelativePath="..\..\src\io\network\juce_URL.cpp"/>


+ 2
- 0
Builds/VisualStudio2008/Juce.vcproj View File

@@ -807,6 +807,8 @@
<File RelativePath="..\..\src\io\files\juce_ZipFile.h"/>
</Filter>
<Filter Name="network">
<File RelativePath="..\..\src\io\network\juce_MACAddress.cpp"/>
<File RelativePath="..\..\src\io\network\juce_MACAddress.h"/>
<File RelativePath="..\..\src\io\network\juce_Socket.cpp"/>
<File RelativePath="..\..\src\io\network\juce_Socket.h"/>
<File RelativePath="..\..\src\io\network\juce_URL.cpp"/>


+ 2
- 0
Builds/VisualStudio2008_DLL/Juce.vcproj View File

@@ -809,6 +809,8 @@
<File RelativePath="..\..\src\io\files\juce_ZipFile.h"/>
</Filter>
<Filter Name="network">
<File RelativePath="..\..\src\io\network\juce_MACAddress.cpp"/>
<File RelativePath="..\..\src\io\network\juce_MACAddress.h"/>
<File RelativePath="..\..\src\io\network\juce_Socket.cpp"/>
<File RelativePath="..\..\src\io\network\juce_Socket.h"/>
<File RelativePath="..\..\src\io\network\juce_URL.cpp"/>


+ 2
- 0
Builds/VisualStudio2010/Juce.vcxproj View File

@@ -359,6 +359,7 @@
<ClCompile Include="..\..\src\io\files\juce_NamedPipe.cpp"/>
<ClCompile Include="..\..\src\io\files\juce_TemporaryFile.cpp"/>
<ClCompile Include="..\..\src\io\files\juce_ZipFile.cpp"/>
<ClCompile Include="..\..\src\io\network\juce_MACAddress.cpp"/>
<ClCompile Include="..\..\src\io\network\juce_Socket.cpp"/>
<ClCompile Include="..\..\src\io\network\juce_URL.cpp"/>
<ClCompile Include="..\..\src\io\streams\juce_BufferedInputStream.cpp"/>
@@ -727,6 +728,7 @@
<ClInclude Include="..\..\src\io\files\juce_NamedPipe.h"/>
<ClInclude Include="..\..\src\io\files\juce_TemporaryFile.h"/>
<ClInclude Include="..\..\src\io\files\juce_ZipFile.h"/>
<ClInclude Include="..\..\src\io\network\juce_MACAddress.h"/>
<ClInclude Include="..\..\src\io\network\juce_Socket.h"/>
<ClInclude Include="..\..\src\io\network\juce_URL.h"/>
<ClInclude Include="..\..\src\io\streams\juce_BufferedInputStream.h"/>


+ 6
- 0
Builds/VisualStudio2010/Juce.vcxproj.filters View File

@@ -925,6 +925,9 @@
<ClCompile Include="..\..\src\io\files\juce_ZipFile.cpp">
<Filter>Juce\Source\io\files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\io\network\juce_MACAddress.cpp">
<Filter>Juce\Source\io\network</Filter>
</ClCompile>
<ClCompile Include="..\..\src\io\network\juce_Socket.cpp">
<Filter>Juce\Source\io\network</Filter>
</ClCompile>
@@ -2103,6 +2106,9 @@
<ClInclude Include="..\..\src\io\files\juce_ZipFile.h">
<Filter>Juce\Source\io\files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\io\network\juce_MACAddress.h">
<Filter>Juce\Source\io\network</Filter>
</ClInclude>
<ClInclude Include="..\..\src\io\network\juce_Socket.h">
<Filter>Juce\Source\io\network</Filter>
</ClInclude>


+ 6
- 0
Builds/iPhone/Juce.xcodeproj/project.pbxproj View File

@@ -245,6 +245,7 @@
BBCA4C01CEF1EDA75625D6DC = { isa = PBXBuildFile; fileRef = D9B3C04F8EB4228DD59002E7; };
136FB9588C834E6F4A1EEBFB = { isa = PBXBuildFile; fileRef = 17C3AF03FF7AE88AE0C73311; };
274415D1C0AE9BF56FAAE791 = { isa = PBXBuildFile; fileRef = 4035C867821E9B5887AA25FB; };
CBAD975785BD26A0DA9417B6 = { isa = PBXBuildFile; fileRef = EFA58F646B69B227AEF14140; };
2A8F78D412AC7EC0C2998A1A = { isa = PBXBuildFile; fileRef = 06B06C420341B005DFF951D2; };
2DD969525DEF4AD408E9BB59 = { isa = PBXBuildFile; fileRef = AD7A1C2C82EE714EBDD52EFC; };
059B694C912BE81023D5240D = { isa = PBXBuildFile; fileRef = D4211E697F43821CDBCE4F24; };
@@ -888,6 +889,8 @@
75D6F1C676E178DEA8B86849 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_TemporaryFile.h; path = ../../src/io/files/juce_TemporaryFile.h; sourceTree = SOURCE_ROOT; };
4035C867821E9B5887AA25FB = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_ZipFile.cpp; path = ../../src/io/files/juce_ZipFile.cpp; sourceTree = SOURCE_ROOT; };
4D005659935C7DE99C2C01E2 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_ZipFile.h; path = ../../src/io/files/juce_ZipFile.h; sourceTree = SOURCE_ROOT; };
EFA58F646B69B227AEF14140 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_MACAddress.cpp; path = ../../src/io/network/juce_MACAddress.cpp; sourceTree = SOURCE_ROOT; };
7241B187AA9B0217838B6052 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_MACAddress.h; path = ../../src/io/network/juce_MACAddress.h; sourceTree = SOURCE_ROOT; };
06B06C420341B005DFF951D2 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_Socket.cpp; path = ../../src/io/network/juce_Socket.cpp; sourceTree = SOURCE_ROOT; };
286206E754AC14DEAF88FD43 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_Socket.h; path = ../../src/io/network/juce_Socket.h; sourceTree = SOURCE_ROOT; };
AD7A1C2C82EE714EBDD52EFC = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_URL.cpp; path = ../../src/io/network/juce_URL.cpp; sourceTree = SOURCE_ROOT; };
@@ -1663,6 +1666,8 @@
4035C867821E9B5887AA25FB,
4D005659935C7DE99C2C01E2 ); name = files; sourceTree = "<group>"; };
13FBF71BD76A08C8971C6351 = { isa = PBXGroup; children = (
EFA58F646B69B227AEF14140,
7241B187AA9B0217838B6052,
06B06C420341B005DFF951D2,
286206E754AC14DEAF88FD43,
AD7A1C2C82EE714EBDD52EFC,
@@ -2165,6 +2170,7 @@
BBCA4C01CEF1EDA75625D6DC,
136FB9588C834E6F4A1EEBFB,
274415D1C0AE9BF56FAAE791,
CBAD975785BD26A0DA9417B6,
2A8F78D412AC7EC0C2998A1A,
2DD969525DEF4AD408E9BB59,
059B694C912BE81023D5240D,


+ 4
- 0
Juce.jucer View File

@@ -1201,6 +1201,10 @@
file="src/io/files/juce_ZipFile.h"/>
</GROUP>
<GROUP id="bOzVjzYUR" name="network">
<FILE id="vyRckg9" name="juce_MACAddress.cpp" compile="1" resource="0"
file="src/io/network/juce_MACAddress.cpp"/>
<FILE id="WzxXWpV" name="juce_MACAddress.h" compile="0" resource="0"
file="src/io/network/juce_MACAddress.h"/>
<FILE id="HAyAhTsrK" name="juce_Socket.cpp" compile="1" resource="0"
file="src/io/network/juce_Socket.cpp"/>
<FILE id="HBCQxvfwV" name="juce_Socket.h" compile="0" resource="0"


+ 1
- 0
amalgamation/juce_amalgamated_template.cpp View File

@@ -127,6 +127,7 @@
#include "../src/io/files/juce_TemporaryFile.cpp"
#include "../src/io/network/juce_Socket.cpp"
#include "../src/io/network/juce_URL.cpp"
#include "../src/io/network/juce_MACAddress.cpp"
#include "../src/io/streams/juce_BufferedInputStream.cpp"
#include "../src/io/streams/juce_FileInputSource.cpp"
#include "../src/io/streams/juce_MemoryInputStream.cpp"


+ 13
- 1
extras/juce demo/Source/ApplicationStartup.cpp View File

@@ -120,7 +120,7 @@ private:
<< "\nCPU has SSE2: " << (SystemStats::hasSSE2() ? "yes" : "no")
<< "\nCPU has 3DNOW: " << (SystemStats::has3DNow() ? "yes" : "no")
<< "\nMemory size: " << SystemStats::getMemorySizeInMegabytes() << "MB"
<< "\nFound network card MAC addresses: " << SystemStats::getMACAddressStrings().joinIntoString (", ")
<< "\nFound network card MAC addresses: " << getMacAddressList()
<< "\nCurrent executable file: " << File::getSpecialLocation (File::currentExecutableFile).getFullPathName()
<< "\nCurrent application file: " << File::getSpecialLocation (File::currentApplicationFile).getFullPathName()
<< "\nCurrent working directory: " << File::getCurrentWorkingDirectory().getFullPathName()
@@ -133,6 +133,18 @@ private:
return systemInfo;
}
static const String getMacAddressList()
{
Array <MACAddress> macAddresses;
MACAddress::findAllAddresses (macAddresses);
StringArray addressStrings;
for (int i = 0; i < macAddresses.size(); ++i)
addressStrings.add (macAddresses[i].toString());
return addressStrings.joinIntoString (", ");
}
};


+ 132
- 150
juce_amalgamated.cpp View File

@@ -1682,26 +1682,6 @@ const String SystemStats::getJUCEVersion()
+ "." + String (JUCE_BUILDNUMBER);
}

const StringArray SystemStats::getMACAddressStrings()
{
int64 macAddresses [16];
const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);

StringArray s;

for (int i = 0; i < numAddresses; ++i)
{
s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
}

return s;
}

#ifdef JUCE_DLL

void* juce_Malloc (const int size)
@@ -9738,6 +9718,66 @@ END_JUCE_NAMESPACE
/*** End of inlined file: juce_URL.cpp ***/


/*** Start of inlined file: juce_MACAddress.cpp ***/
BEGIN_JUCE_NAMESPACE

MACAddress::MACAddress()
: asInt64 (0)
{
}

MACAddress::MACAddress (const MACAddress& other)
: asInt64 (other.asInt64)
{
}

MACAddress& MACAddress::operator= (const MACAddress& other)
{
asInt64 = other.asInt64;
return *this;
}

MACAddress::MACAddress (const uint8 bytes[6])
: asInt64 (0)
{
memcpy (asBytes, bytes, sizeof (asBytes));
}

const String MACAddress::toString() const
{
String s;
s.preallocateStorage (18);

for (int i = 0; i < numElementsInArray (asBytes); ++i)
{
s << String::toHexString ((int) asBytes[i]).paddedLeft ('0', 2);

if (i < numElementsInArray (asBytes) - 1)
s << '-';
}

return s;
}

int64 MACAddress::toInt64() const throw()
{
int64 n = 0;

for (int i = numElementsInArray (asBytes); --i >= 0;)
n = (n << 8) | asBytes[i];

return n;
}

bool MACAddress::isNull() const throw() { return asInt64 == 0; }

bool MACAddress::operator== (const MACAddress& other) const throw() { return asInt64 == other.asInt64; }
bool MACAddress::operator!= (const MACAddress& other) const throw() { return asInt64 != other.asInt64; }

END_JUCE_NAMESPACE
/*** End of inlined file: juce_MACAddress.cpp ***/


/*** Start of inlined file: juce_BufferedInputStream.cpp ***/
BEGIN_JUCE_NAMESPACE

@@ -10335,7 +10375,12 @@ Uuid::Uuid()
if (! hasCheckedMacAddresses)
{
hasCheckedMacAddresses = true;
SystemStats::getMACAddresses (macAddresses, 2);

Array<MACAddress> result;
MACAddress::findAllAddresses (result);

for (int i = 0; i < numElementsInArray (macAddresses); ++i)
macAddresses[i] = result[i].toInt64();
}

value.asInt64[0] = macAddresses[0];
@@ -239855,121 +239900,91 @@ void juce_closeInternetFile (void* handle)
}
}

static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
namespace MACAddressHelpers
{
int numFound = 0;

DynamicLibraryLoader dll ("iphlpapi.dll");
DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))

if (getAdaptersInfo != 0)
void getViaGetAdaptersInfo (Array<MACAddress>& result)
{
ULONG len = sizeof (IP_ADAPTER_INFO);
MemoryBlock mb;
PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();

if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
{
mb.setSize (len);
adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
}
DynamicLibraryLoader dll ("iphlpapi.dll");
DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))

if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
if (getAdaptersInfo != 0)
{
PIP_ADAPTER_INFO adapter = adapterInfo;
ULONG len = sizeof (IP_ADAPTER_INFO);
MemoryBlock mb;
PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();

while (adapter != 0)
if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
{
int64 mac = 0;
for (unsigned int i = 0; i < adapter->AddressLength; ++i)
mac = (mac << 8) | adapter->Address[i];

if (littleEndian)
mac = (int64) ByteOrder::swap ((uint64) mac);

if (numFound < maxNum && mac != 0)
addresses [numFound++] = mac;
mb.setSize (len);
adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
}

adapter = adapter->Next;
if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
{
for (PIP_ADAPTER_INFO adapter = adapterInfo; adapter != 0; adapter = adapter->Next)
{
if (adapter->AddressLength >= 6)
result.addIfNotAlreadyThere (MACAddress (adapter->Address));
}
}
}
}

return numFound;
}

static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
{
int numFound = 0;

DynamicLibraryLoader dll ("netapi32.dll");
DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))

if (NetbiosCall != 0)
void getViaNetBios (Array<MACAddress>& result)
{
NCB ncb;
zerostruct (ncb);
DynamicLibraryLoader dll ("netapi32.dll");
DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))

struct ASTAT
if (NetbiosCall != 0)
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
};
NCB ncb;
zerostruct (ncb);

ASTAT astat;
zeromem (&astat, sizeof (astat)); // (can't use zerostruct here in VC6)
struct ASTAT
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
};

LANA_ENUM enums;
zerostruct (enums);
ASTAT astat;
zeromem (&astat, sizeof (astat)); // (can't use zerostruct here in VC6)

ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char*) &enums;
ncb.ncb_length = sizeof (LANA_ENUM);
NetbiosCall (&ncb);
LANA_ENUM enums;
zerostruct (enums);

for (int i = 0; i < enums.length; ++i)
{
zerostruct (ncb);
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = enums.lana[i];
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char*) &enums;
ncb.ncb_length = sizeof (LANA_ENUM);
NetbiosCall (&ncb);

if (NetbiosCall (&ncb) == 0)
for (int i = 0; i < enums.length; ++i)
{
zerostruct (ncb);
memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
ncb.ncb_command = NCBASTAT;
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = enums.lana[i];

ncb.ncb_buffer = (unsigned char*) &astat;
ncb.ncb_length = sizeof (ASTAT);

if (NetbiosCall (&ncb) == 0)
{
if (astat.adapt.adapter_type == 0xfe)
{
uint64 mac = 0;
for (int i = 6; --i >= 0;)
mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
zerostruct (ncb);
memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = enums.lana[i];

if (numFound < maxNum && mac != 0)
addresses [numFound++] = mac;
}
ncb.ncb_buffer = (unsigned char*) &astat;
ncb.ncb_length = sizeof (ASTAT);

if (NetbiosCall (&ncb) == 0 && astat.adapt.adapter_type == 0xfe)
result.addIfNotAlreadyThere (MACAddress (astat.adapt.adapter_address));
}
}
}
}

return numFound;
}

int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
void MACAddress::findAllAddresses (Array<MACAddress>& result)
{
int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);

if (numFound == 0)
numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);

return numFound;
MACAddressHelpers::getViaGetAdaptersInfo (result);
MACAddressHelpers::getViaNetBios (result);
}

bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
@@ -256110,10 +256125,8 @@ int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOut
// compiled on its own).
#if JUCE_INCLUDED_FILE

int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
void MACAddress::findAllAddresses (Array<MACAddress>& result)
{
int numResults = 0;

const int s = socket (AF_INET, SOCK_DGRAM, 0);
if (s != -1)
{
@@ -256130,22 +256143,14 @@ int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littl

if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
&& (ifr.ifr_flags & IFF_LOOPBACK) == 0
&& ioctl (s, SIOCGIFHWADDR, &ifr) == 0
&& numResults < maxNum)
&& ioctl (s, SIOCGIFHWADDR, &ifr) == 0)
{
int64 a = 0;
for (int j = 6; --j >= 0;)
a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];

*addresses++ = a;
++numResults;
result.addIfNotAlreadyThere (MACAddress ((const uint8*) ifr.ifr_hwaddr.sa_data));
}
}

close (s);
}

return numResults;
}

bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
@@ -256251,11 +256256,8 @@ public:
return false;
}

const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
proxyName, proxyPort,
hostPath, url,
headers, postData,
isPost));
const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort, proxyName, proxyPort,
hostPath, url, headers, postData, isPost));
size_t totalHeaderSent = 0;

while (totalHeaderSent < requestHeader.getSize())
@@ -256268,10 +256270,8 @@ public:

const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));

if (send (socketHandle,
((const char*) requestHeader.getData()) + totalHeaderSent,
numToSend, 0)
!= numToSend)
if (send (socketHandle, ((const char*) requestHeader.getData()) + totalHeaderSent, numToSend, 0)
!= numToSend)
{
closeSocket();
return false;
@@ -256290,8 +256290,6 @@ public:

if (responseHeader.isNotEmpty())
{
//DBG (responseHeader);

headerLines.clear();
headerLines.addLines (responseHeader);

@@ -264109,46 +264107,30 @@ void PlatformUtilities::fpuReset()
// compiled on its own).
#if JUCE_INCLUDED_FILE

int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
void MACAddress::findAllAddresses (Array<MACAddress>& result)
{
#ifndef IFT_ETHER
#define IFT_ETHER 6
#endif

ifaddrs* addrs = 0;
int numResults = 0;

if (getifaddrs (&addrs) == 0)
{
const ifaddrs* cursor = addrs;

while (cursor != 0 && numResults < maxNum)
for (const ifaddrs* cursor = addrs; cursor != 0; cursor = cursor->ifa_next)
{
sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
if (sto->ss_family == AF_LINK)
{
const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;

if (sadd->sdl_type == IFT_ETHER)
{
const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
#ifndef IFT_ETHER
#define IFT_ETHER 6
#endif

uint64 a = 0;
for (int i = 6; --i >= 0;)
a = (a << 8) | addr [littleEndian ? i : (5 - i)];

*addresses++ = (int64) a;
++numResults;
}
if (sadd->sdl_type == IFT_ETHER)
result.addIfNotAlreadyThere (MACAddress (((const uint8*) sadd->sdl_data) + sadd->sdl_nlen));
}

cursor = cursor->ifa_next;
}

freeifaddrs (addrs);
}

return numResults;
}

bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,


+ 71
- 35
juce_amalgamated.h View File

@@ -15112,20 +15112,19 @@ public:
static const String getCpuVendor();

/** Checks whether Intel MMX instructions are available. */
static bool hasMMX() throw() { return cpuFlags.hasMMX; }
static bool hasMMX() throw() { return cpuFlags.hasMMX; }

/** Checks whether Intel SSE instructions are available. */
static bool hasSSE() throw() { return cpuFlags.hasSSE; }
static bool hasSSE() throw() { return cpuFlags.hasSSE; }

/** Checks whether Intel SSE2 instructions are available. */
static bool hasSSE2() throw() { return cpuFlags.hasSSE2; }
static bool hasSSE2() throw() { return cpuFlags.hasSSE2; }

/** Checks whether AMD 3DNOW instructions are available. */
static bool has3DNow() throw() { return cpuFlags.has3DNow; }
static bool has3DNow() throw() { return cpuFlags.has3DNow; }

/** Returns the number of CPUs.
*/
static int getNumCpus() throw() { return cpuFlags.numCpus; }
/** Returns the number of CPUs. */
static int getNumCpus() throw() { return cpuFlags.numCpus; }

/** Finds out how much RAM is in the machine.

@@ -15140,34 +15139,6 @@ public:
*/
static int getPageSize();

/** Returns a list of MAC addresses found on this machine.

@param addresses an array into which the MAC addresses should be copied
@param maxNum the number of elements in this array
@param littleEndian the endianness of the numbers to return. If this is true,
the least-significant byte of each number is the first byte
of the mac address. If false, the least significant byte is
the last number. Note that the default values of this parameter
are different on Mac/PC to avoid breaking old software that was
written before this parameter was added (when the two systems
defaulted to using different endiannesses). In newer
software you probably want to specify an explicit value
for this.
@returns the number of MAC addresses that were found
*/
static int getMACAddresses (int64* addresses, int maxNum,
#if JUCE_MAC
bool littleEndian = true);
#else
bool littleEndian = false);
#endif

/** Returns a list of MAC addresses found on this machine.

@returns an array of strings containing the MAC addresses that were found
*/
static const StringArray getMACAddressStrings();

// not-for-public-use platform-specific method gets called at startup to initialise things.
static void initialiseStats();

@@ -16418,6 +16389,71 @@ private:
/*** End of inlined file: juce_ZipFile.h ***/


#endif
#ifndef __JUCE_MACADDRESS_JUCEHEADER__

/*** Start of inlined file: juce_MACAddress.h ***/
#ifndef __JUCE_MACADDRESS_JUCEHEADER__
#define __JUCE_MACADDRESS_JUCEHEADER__

/**
A wrapper for a streaming (TCP) socket.

This allows low-level use of sockets; for an easier-to-use messaging layer on top of
sockets, you could also try the InterprocessConnection class.

@see DatagramSocket, InterprocessConnection, InterprocessConnectionServer
*/
class JUCE_API MACAddress
{
public:

/** Populates a list of the MAC addresses of all the available network cards. */
static void findAllAddresses (Array<MACAddress>& results);

/** Creates a null address (00-00-00-00-00-00). */
MACAddress();

/** Creates a copy of another address. */
MACAddress (const MACAddress& other);

/** Creates a copy of another address. */
MACAddress& operator= (const MACAddress& other);

/** Creates an address from 6 bytes. */
explicit MACAddress (const uint8 bytes[6]);

/** Returns a pointer to the 6 bytes that make up this address. */
const uint8* getBytes() const throw() { return asBytes; }

/** Returns a dash-separated string in the form "11-22-33-44-55-66" */
const String toString() const;

/** Returns the address in the lower 6 bytes of an int64.

This uses a little-endian arrangement, with the first byte of the address being
stored in the least-significant byte of the result value.
*/
int64 toInt64() const throw();

/** Returns true if this address is null (00-00-00-00-00-00). */
bool isNull() const throw();

bool operator== (const MACAddress& other) const throw();
bool operator!= (const MACAddress& other) const throw();

private:
union
{
uint64 asInt64;
uint8 asBytes[6];
};
};

#endif // __JUCE_MACADDRESS_JUCEHEADER__
/*** End of inlined file: juce_MACAddress.h ***/


#endif
#ifndef __JUCE_SOCKET_JUCEHEADER__



+ 0
- 20
src/core/juce_SystemStats.cpp View File

@@ -43,26 +43,6 @@ const String SystemStats::getJUCEVersion()
+ "." + String (JUCE_BUILDNUMBER);
}
const StringArray SystemStats::getMACAddressStrings()
{
int64 macAddresses [16];
const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
StringArray s;
for (int i = 0; i < numAddresses; ++i)
{
s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
+ "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
}
return s;
}
//==============================================================================
#ifdef JUCE_DLL


+ 6
- 37
src/core/juce_SystemStats.h View File

@@ -117,20 +117,19 @@ public:
static const String getCpuVendor();
/** Checks whether Intel MMX instructions are available. */
static bool hasMMX() throw() { return cpuFlags.hasMMX; }
static bool hasMMX() throw() { return cpuFlags.hasMMX; }
/** Checks whether Intel SSE instructions are available. */
static bool hasSSE() throw() { return cpuFlags.hasSSE; }
static bool hasSSE() throw() { return cpuFlags.hasSSE; }
/** Checks whether Intel SSE2 instructions are available. */
static bool hasSSE2() throw() { return cpuFlags.hasSSE2; }
static bool hasSSE2() throw() { return cpuFlags.hasSSE2; }
/** Checks whether AMD 3DNOW instructions are available. */
static bool has3DNow() throw() { return cpuFlags.has3DNow; }
static bool has3DNow() throw() { return cpuFlags.has3DNow; }
/** Returns the number of CPUs.
*/
static int getNumCpus() throw() { return cpuFlags.numCpus; }
/** Returns the number of CPUs. */
static int getNumCpus() throw() { return cpuFlags.numCpus; }
//==============================================================================
/** Finds out how much RAM is in the machine.
@@ -146,36 +145,6 @@ public:
*/
static int getPageSize();
//==============================================================================
/** Returns a list of MAC addresses found on this machine.
@param addresses an array into which the MAC addresses should be copied
@param maxNum the number of elements in this array
@param littleEndian the endianness of the numbers to return. If this is true,
the least-significant byte of each number is the first byte
of the mac address. If false, the least significant byte is
the last number. Note that the default values of this parameter
are different on Mac/PC to avoid breaking old software that was
written before this parameter was added (when the two systems
defaulted to using different endiannesses). In newer
software you probably want to specify an explicit value
for this.
@returns the number of MAC addresses that were found
*/
static int getMACAddresses (int64* addresses, int maxNum,
#if JUCE_MAC
bool littleEndian = true);
#else
bool littleEndian = false);
#endif
/** Returns a list of MAC addresses found on this machine.
@returns an array of strings containing the MAC addresses that were found
*/
static const StringArray getMACAddressStrings();
//==============================================================================
// not-for-public-use platform-specific method gets called at startup to initialise things.
static void initialiseStats();


+ 7
- 2
src/core/juce_Uuid.cpp View File

@@ -30,7 +30,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_Uuid.h"
#include "juce_Random.h"
#include "juce_Time.h"
#include "juce_SystemStats.h"
#include "../io/network/juce_MACAddress.h"
#include "../containers/juce_MemoryBlock.h"
@@ -46,7 +46,12 @@ Uuid::Uuid()
if (! hasCheckedMacAddresses)
{
hasCheckedMacAddresses = true;
SystemStats::getMACAddresses (macAddresses, 2);
Array<MACAddress> result;
MACAddress::findAllAddresses (result);
for (int i = 0; i < numElementsInArray (macAddresses); ++i)
macAddresses[i] = result[i].toInt64();
}
value.asInt64[0] = macAddresses[0];


+ 88
- 0
src/io/network/juce_MACAddress.cpp View File

@@ -0,0 +1,88 @@
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-10 by Raw Material Software Ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the GNU General
Public License (Version 2), as published by the Free Software Foundation.
A copy of the license is included in the JUCE distribution, or can be found
online at www.gnu.org/licenses.
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.rawmaterialsoftware.com/juce for more information.
==============================================================================
*/
#include "../../core/juce_StandardHeader.h"
BEGIN_JUCE_NAMESPACE
#include "juce_MACAddress.h"
//==============================================================================
MACAddress::MACAddress()
: asInt64 (0)
{
}
MACAddress::MACAddress (const MACAddress& other)
: asInt64 (other.asInt64)
{
}
MACAddress& MACAddress::operator= (const MACAddress& other)
{
asInt64 = other.asInt64;
return *this;
}
MACAddress::MACAddress (const uint8 bytes[6])
: asInt64 (0)
{
memcpy (asBytes, bytes, sizeof (asBytes));
}
const String MACAddress::toString() const
{
String s;
s.preallocateStorage (18);
for (int i = 0; i < numElementsInArray (asBytes); ++i)
{
s << String::toHexString ((int) asBytes[i]).paddedLeft ('0', 2);
if (i < numElementsInArray (asBytes) - 1)
s << '-';
}
return s;
}
int64 MACAddress::toInt64() const throw()
{
int64 n = 0;
for (int i = numElementsInArray (asBytes); --i >= 0;)
n = (n << 8) | asBytes[i];
return n;
}
bool MACAddress::isNull() const throw() { return asInt64 == 0; }
bool MACAddress::operator== (const MACAddress& other) const throw() { return asInt64 == other.asInt64; }
bool MACAddress::operator!= (const MACAddress& other) const throw() { return asInt64 != other.asInt64; }
END_JUCE_NAMESPACE

+ 90
- 0
src/io/network/juce_MACAddress.h View File

@@ -0,0 +1,90 @@
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-10 by Raw Material Software Ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the GNU General
Public License (Version 2), as published by the Free Software Foundation.
A copy of the license is included in the JUCE distribution, or can be found
online at www.gnu.org/licenses.
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.rawmaterialsoftware.com/juce for more information.
==============================================================================
*/
#ifndef __JUCE_MACADDRESS_JUCEHEADER__
#define __JUCE_MACADDRESS_JUCEHEADER__
#include "../../containers/juce_Array.h"
//==============================================================================
/**
A wrapper for a streaming (TCP) socket.
This allows low-level use of sockets; for an easier-to-use messaging layer on top of
sockets, you could also try the InterprocessConnection class.
@see DatagramSocket, InterprocessConnection, InterprocessConnectionServer
*/
class JUCE_API MACAddress
{
public:
//==============================================================================
/** Populates a list of the MAC addresses of all the available network cards. */
static void findAllAddresses (Array<MACAddress>& results);
//==============================================================================
/** Creates a null address (00-00-00-00-00-00). */
MACAddress();
/** Creates a copy of another address. */
MACAddress (const MACAddress& other);
/** Creates a copy of another address. */
MACAddress& operator= (const MACAddress& other);
/** Creates an address from 6 bytes. */
explicit MACAddress (const uint8 bytes[6]);
/** Returns a pointer to the 6 bytes that make up this address. */
const uint8* getBytes() const throw() { return asBytes; }
/** Returns a dash-separated string in the form "11-22-33-44-55-66" */
const String toString() const;
/** Returns the address in the lower 6 bytes of an int64.
This uses a little-endian arrangement, with the first byte of the address being
stored in the least-significant byte of the result value.
*/
int64 toInt64() const throw();
/** Returns true if this address is null (00-00-00-00-00-00). */
bool isNull() const throw();
bool operator== (const MACAddress& other) const throw();
bool operator!= (const MACAddress& other) const throw();
//==============================================================================
private:
union
{
uint64 asInt64;
uint8 asBytes[6];
};
};
#endif // __JUCE_MACADDRESS_JUCEHEADER__

+ 3
- 0
src/juce_core_includes.h View File

@@ -182,6 +182,9 @@
#ifndef __JUCE_ZIPFILE_JUCEHEADER__
#include "io/files/juce_ZipFile.h"
#endif
#ifndef __JUCE_MACADDRESS_JUCEHEADER__
#include "io/network/juce_MACAddress.h"
#endif
#ifndef __JUCE_SOCKET_JUCEHEADER__
#include "io/network/juce_Socket.h"
#endif


+ 1
- 0
src/native/juce_linux_NativeCode.cpp View File

@@ -61,6 +61,7 @@ BEGIN_JUCE_NAMESPACE
#include "../io/files/juce_FileOutputStream.h"
#include "../io/files/juce_DirectoryIterator.h"
#include "../io/network/juce_URL.h"
#include "../io/network/juce_MACAddress.h"
#include "../io/streams/juce_MemoryInputStream.h"
#include "../io/streams/juce_MemoryOutputStream.h"
#include "../events/juce_MessageManager.h"


+ 1
- 0
src/native/juce_mac_NativeCode.mm View File

@@ -50,6 +50,7 @@ BEGIN_JUCE_NAMESPACE
#include "../io/files/juce_NamedPipe.h"
#include "../io/files/juce_DirectoryIterator.h"
#include "../io/network/juce_URL.h"
#include "../io/network/juce_MACAddress.h"
#include "../io/streams/juce_MemoryInputStream.h"
#include "../io/streams/juce_BufferedInputStream.h"
#include "../core/juce_PlatformUtilities.h"


+ 1
- 0
src/native/juce_win32_NativeCode.cpp View File

@@ -51,6 +51,7 @@ BEGIN_JUCE_NAMESPACE
#include "../io/files/juce_NamedPipe.h"
#include "../io/files/juce_DirectoryIterator.h"
#include "../io/network/juce_URL.h"
#include "../io/network/juce_MACAddress.h"
#include "../core/juce_PlatformUtilities.h"
#include "../text/juce_LocalisedStrings.h"
#include "../utilities/juce_DeletedAtShutdown.h"


+ 7
- 24
src/native/linux/juce_linux_Network.cpp View File

@@ -29,10 +29,8 @@
//==============================================================================
int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
void MACAddress::findAllAddresses (Array<MACAddress>& result)
{
int numResults = 0;
const int s = socket (AF_INET, SOCK_DGRAM, 0);
if (s != -1)
{
@@ -49,22 +47,14 @@ int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littl
if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
&& (ifr.ifr_flags & IFF_LOOPBACK) == 0
&& ioctl (s, SIOCGIFHWADDR, &ifr) == 0
&& numResults < maxNum)
&& ioctl (s, SIOCGIFHWADDR, &ifr) == 0)
{
int64 a = 0;
for (int j = 6; --j >= 0;)
a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
*addresses++ = a;
++numResults;
result.addIfNotAlreadyThere (MACAddress ((const uint8*) ifr.ifr_hwaddr.sa_data));
}
}
close (s);
}
return numResults;
}
@@ -173,11 +163,8 @@ public:
return false;
}
const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
proxyName, proxyPort,
hostPath, url,
headers, postData,
isPost));
const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort, proxyName, proxyPort,
hostPath, url, headers, postData, isPost));
size_t totalHeaderSent = 0;
while (totalHeaderSent < requestHeader.getSize())
@@ -190,10 +177,8 @@ public:
const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
if (send (socketHandle,
((const char*) requestHeader.getData()) + totalHeaderSent,
numToSend, 0)
!= numToSend)
if (send (socketHandle, ((const char*) requestHeader.getData()) + totalHeaderSent, numToSend, 0)
!= numToSend)
{
closeSocket();
return false;
@@ -212,8 +197,6 @@ public:
if (responseHeader.isNotEmpty())
{
//DBG (responseHeader);
headerLines.clear();
headerLines.addLines (responseHeader);


+ 7
- 23
src/native/mac/juce_mac_Network.mm View File

@@ -28,46 +28,30 @@
#if JUCE_INCLUDED_FILE
//==============================================================================
int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
void MACAddress::findAllAddresses (Array<MACAddress>& result)
{
#ifndef IFT_ETHER
#define IFT_ETHER 6
#endif
ifaddrs* addrs = 0;
int numResults = 0;
if (getifaddrs (&addrs) == 0)
{
const ifaddrs* cursor = addrs;
while (cursor != 0 && numResults < maxNum)
for (const ifaddrs* cursor = addrs; cursor != 0; cursor = cursor->ifa_next)
{
sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
if (sto->ss_family == AF_LINK)
{
const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
if (sadd->sdl_type == IFT_ETHER)
{
const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
uint64 a = 0;
for (int i = 6; --i >= 0;)
a = (a << 8) | addr [littleEndian ? i : (5 - i)];
#ifndef IFT_ETHER
#define IFT_ETHER 6
#endif
*addresses++ = (int64) a;
++numResults;
}
if (sadd->sdl_type == IFT_ETHER)
result.addIfNotAlreadyThere (MACAddress (((const uint8*) sadd->sdl_data) + sadd->sdl_nlen));
}
cursor = cursor->ifa_next;
}
freeifaddrs (addrs);
}
return numResults;
}
//==============================================================================


+ 52
- 82
src/native/windows/juce_win32_Network.cpp View File

@@ -325,121 +325,91 @@ void juce_closeInternetFile (void* handle)
}
//==============================================================================
static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
namespace MACAddressHelpers
{
int numFound = 0;
DynamicLibraryLoader dll ("iphlpapi.dll");
DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
if (getAdaptersInfo != 0)
void getViaGetAdaptersInfo (Array<MACAddress>& result)
{
ULONG len = sizeof (IP_ADAPTER_INFO);
MemoryBlock mb;
PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
DynamicLibraryLoader dll ("iphlpapi.dll");
DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
if (getAdaptersInfo != 0)
{
mb.setSize (len);
adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
}
ULONG len = sizeof (IP_ADAPTER_INFO);
MemoryBlock mb;
PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
{
PIP_ADAPTER_INFO adapter = adapterInfo;
while (adapter != 0)
if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
{
int64 mac = 0;
for (unsigned int i = 0; i < adapter->AddressLength; ++i)
mac = (mac << 8) | adapter->Address[i];
if (littleEndian)
mac = (int64) ByteOrder::swap ((uint64) mac);
if (numFound < maxNum && mac != 0)
addresses [numFound++] = mac;
mb.setSize (len);
adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
}
adapter = adapter->Next;
if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
{
for (PIP_ADAPTER_INFO adapter = adapterInfo; adapter != 0; adapter = adapter->Next)
{
if (adapter->AddressLength >= 6)
result.addIfNotAlreadyThere (MACAddress (adapter->Address));
}
}
}
}
return numFound;
}
static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
{
int numFound = 0;
DynamicLibraryLoader dll ("netapi32.dll");
DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
if (NetbiosCall != 0)
void getViaNetBios (Array<MACAddress>& result)
{
NCB ncb;
zerostruct (ncb);
DynamicLibraryLoader dll ("netapi32.dll");
DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
struct ASTAT
if (NetbiosCall != 0)
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
};
NCB ncb;
zerostruct (ncb);
ASTAT astat;
zeromem (&astat, sizeof (astat)); // (can't use zerostruct here in VC6)
struct ASTAT
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
};
LANA_ENUM enums;
zerostruct (enums);
ASTAT astat;
zeromem (&astat, sizeof (astat)); // (can't use zerostruct here in VC6)
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char*) &enums;
ncb.ncb_length = sizeof (LANA_ENUM);
NetbiosCall (&ncb);
LANA_ENUM enums;
zerostruct (enums);
for (int i = 0; i < enums.length; ++i)
{
zerostruct (ncb);
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = enums.lana[i];
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char*) &enums;
ncb.ncb_length = sizeof (LANA_ENUM);
NetbiosCall (&ncb);
if (NetbiosCall (&ncb) == 0)
for (int i = 0; i < enums.length; ++i)
{
zerostruct (ncb);
memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
ncb.ncb_command = NCBASTAT;
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = enums.lana[i];
ncb.ncb_buffer = (unsigned char*) &astat;
ncb.ncb_length = sizeof (ASTAT);
if (NetbiosCall (&ncb) == 0)
{
if (astat.adapt.adapter_type == 0xfe)
{
uint64 mac = 0;
for (int i = 6; --i >= 0;)
mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
zerostruct (ncb);
memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = enums.lana[i];
if (numFound < maxNum && mac != 0)
addresses [numFound++] = mac;
}
ncb.ncb_buffer = (unsigned char*) &astat;
ncb.ncb_length = sizeof (ASTAT);
if (NetbiosCall (&ncb) == 0 && astat.adapt.adapter_type == 0xfe)
result.addIfNotAlreadyThere (MACAddress (astat.adapt.adapter_address));
}
}
}
}
return numFound;
}
int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
void MACAddress::findAllAddresses (Array<MACAddress>& result)
{
int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
if (numFound == 0)
numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
return numFound;
MACAddressHelpers::getViaGetAdaptersInfo (result);
MACAddressHelpers::getViaNetBios (result);
}
//==============================================================================


Loading…
Cancel
Save