2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
20 ==============================================================================
26 MACAddress::MACAddress() noexcept
28 zeromem (address
, sizeof (address
));
31 MACAddress::MACAddress (const MACAddress
& other
) noexcept
33 memcpy (address
, other
.address
, sizeof (address
));
36 MACAddress
& MACAddress::operator= (const MACAddress
& other
) noexcept
38 memcpy (address
, other
.address
, sizeof (address
));
42 MACAddress::MACAddress (const uint8 bytes
[6]) noexcept
44 memcpy (address
, bytes
, sizeof (address
));
47 MACAddress::MACAddress (StringRef addressString
)
50 hex
.loadFromHexString (addressString
);
52 if (hex
.getSize() == sizeof (address
))
53 memcpy (address
, hex
.getData(), sizeof (address
));
55 zeromem (address
, sizeof (address
));
58 String
MACAddress::toString() const
60 return toString ("-");
63 String
MACAddress::toString (StringRef separator
) const
67 for (size_t i
= 0; i
< sizeof (address
); ++i
)
69 s
<< String::toHexString ((int) address
[i
]).paddedLeft ('0', 2);
71 if (i
< sizeof (address
) - 1)
78 int64
MACAddress::toInt64() const noexcept
82 for (int i
= (int) sizeof (address
); --i
>= 0;)
83 n
= (n
<< 8) | address
[i
];
88 Array
<MACAddress
> MACAddress::getAllAddresses()
90 Array
<MACAddress
> addresses
;
91 findAllAddresses (addresses
);
95 bool MACAddress::isNull() const noexcept
{ return toInt64() == 0; }
97 bool MACAddress::operator== (const MACAddress
& other
) const noexcept
{ return memcmp (address
, other
.address
, sizeof (address
)) == 0; }
98 bool MACAddress::operator!= (const MACAddress
& other
) const noexcept
{ return ! operator== (other
); }