43 str.reserve(3 *
length - 1);
72 errmsg.append(
"EUI48 sub-string must be less or equal length 17 but "+std::to_string(str_len)+
": "+str);
75 const char * str_ptr = str.c_str();
77 bool exp_colon =
false;
79 while( j+1 < str_len ) {
80 const bool is_colon =
':' == str[j];
81 if( exp_colon && !is_colon ) {
82 errmsg.append(
"EUI48Sub sub-string not in format '01:02:03:0A:0B:0C', but '"+str+
"', colon missing, pos "+std::to_string(j)+
", len "+std::to_string(str_len));
84 }
else if( is_colon ) {
88 if ( sscanf(str_ptr+j,
"%02hhx", &b_[dest.
length]) != 1 )
90 errmsg.append(
"EUI48Sub sub-string not in format '01:02:03:0A:0B:0C' but '"+str+
"', pos "+std::to_string(j)+
", len "+std::to_string(str_len));
99 for(j=0; j<dest.
length; ++j) {
100 dest.
b[j] = b_[dest.
length-1-j];
103 memcpy(dest.
b, b_, dest.
length);
117 const jau::nsize_t cpsz = std::max<jau::nsize_t>(
sizeof(
b), len_);
131 const uint8_t needle_b[],
const jau::nsize_t needle_length,
133 if( 0 == needle_length ) {
136 if( haystack_length < needle_length ) {
139 const uint8_t first = needle_b[0];
140 const jau::nsize_t outerEnd = haystack_length - needle_length + 1;
144 while( haystack_b[i] != first ) {
145 if( ++i == outerEnd ) {
154 if( ++j == innerEnd ) {
159 return static_cast<jau::snsize_t>(5 - i - ( needle_length - 1 ));
162 }
while( haystack_b[j] == needle_b[++k] );
204 if( 17 != str.length() ) {
205 errmsg.append(
"EUI48 string not of length 17 but ");
206 errmsg.append(std::to_string(str.length()));
207 errmsg.append(
": "+str);
212 scanres = sscanf(str.c_str(),
"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
213 &dest.
b[5], &dest.
b[4], &dest.
b[3], &dest.
b[2], &dest.
b[1], &dest.
b[0]);
215 scanres = sscanf(str.c_str(),
"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
216 &dest.
b[0], &dest.
b[1], &dest.
b[2], &dest.
b[3], &dest.
b[4], &dest.
b[5]);
218 if ( 6 != scanres ) {
219 errmsg.append(
"EUI48 string not in format '01:02:03:0A:0B:0C' but '"+str+
"'");
236 memcpy(
b, source,
sizeof(
b));
244 memcpy(sink,
b,
sizeof(
b));
static uint8_t _EUI48_LOCAL_DEVICE[]
static uint8_t _EUI48_ALL_DEVICE[]
constexpr bool is_little_endian() noexcept
Evaluates true if platform is running in little endian mode, i.e.
constexpr uint16_t bswap(uint16_t const source) noexcept
lb_endian_t
Simplified reduced endian type only covering little- and big-endian.
@ native
Identifier for native platform type, one of the above.
@ little
Identifier for little endian, equivalent to endian::little.
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.
static constexpr void bswap_6bytes(uint8_t *sink, const uint8_t *source) noexcept
void zero_bytes_sec(void *s, size_t n) noexcept __attrdecl_no_optimize__
Wrapper to ::explicit_bzero(), ::bzero() or ::memset(), whichever is available in that order.
std::string & byteHexString(std::string &dest, const uint8_t value, const bool lowerCase) noexcept
Produce a hexadecimal string representation of the given byte value.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
A 48 bit EUI-48 sub-identifier, see EUI48.
jau::nsize_t length
The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
constexpr EUI48Sub() noexcept
uint8_t b[6]
The <= 6 byte EUI48 sub-address.
static const EUI48Sub ALL_DEVICE
EUI48 MAC address matching all device, i.e.
static const EUI48Sub ANY_DEVICE
EUI48 MAC address matching any device, i.e.
static jau::snsize_t indexOf(const uint8_t haystack_b[], const jau::nsize_t haystack_length, const uint8_t needle_b[], const jau::nsize_t needle_length, const lb_endian_t byte_order) noexcept
Find index of needle within haystack in the given byte order.
void clear()
Method clears the underlying byte array b and sets length to zero.
static const EUI48Sub LOCAL_DEVICE
EUI48 MAC address matching local device, i.e.
std::string toString() const noexcept
Returns the EUI48 sub-string representation with MSB first (lb_endian::big), less or equal 17 charact...
static bool scanEUI48Sub(const std::string &str, EUI48Sub &dest, std::string &errmsg)
Fills given EUI48Sub instance via given string representation.
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
static const EUI48 LOCAL_DEVICE
EUI48 MAC address matching local device, i.e.
static const EUI48 ANY_DEVICE
EUI48 MAC address matching any device, i.e.
static const EUI48 ALL_DEVICE
EUI48 MAC address matching all device, i.e.
static bool scanEUI48(const std::string &str, EUI48 &dest, std::string &errmsg)
jau::nsize_t put(uint8_t *const sink, const lb_endian_t byte_order) const noexcept
constexpr EUI48() noexcept
std::string toString() const noexcept