Skip to content

Commit 4d95273

Browse files
author
Virens
committed
format code
1 parent a8c8c50 commit 4d95273

File tree

2 files changed

+93
-91
lines changed

2 files changed

+93
-91
lines changed

Diff for: cores/arduino/IPv6Address.cpp

+34-34
Original file line numberDiff line numberDiff line change
@@ -23,68 +23,68 @@
2323

2424
IPv6Address::IPv6Address()
2525
{
26-
memset(_address.bytes, 0, sizeof(_address.bytes));
26+
memset(_address.bytes, 0, sizeof(_address.bytes));
2727
}
2828

2929
IPv6Address::IPv6Address(const uint8_t *address)
3030
{
31-
memcpy(_address.bytes, address, sizeof(_address.bytes));
31+
memcpy(_address.bytes, address, sizeof(_address.bytes));
3232
}
3333

3434
IPv6Address::IPv6Address(const uint32_t *address)
3535
{
36-
memcpy(_address.bytes, (const uint8_t *)address, sizeof(_address.bytes));
36+
memcpy(_address.bytes, (const uint8_t *)address, sizeof(_address.bytes));
3737
}
3838

3939
IPv6Address& IPv6Address::operator=(const uint8_t *address)
4040
{
41-
memcpy(_address.bytes, address, sizeof(_address.bytes));
42-
return *this;
41+
memcpy(_address.bytes, address, sizeof(_address.bytes));
42+
return *this;
4343
}
4444

4545
bool IPv6Address::operator==(const uint8_t* addr) const
4646
{
47-
return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
47+
return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
4848
}
4949

5050
size_t IPv6Address::printTo(Print& p) const
5151
{
52-
size_t n = 0;
53-
for(int i = 0; i < 16; i+=2) {
54-
if(i){
55-
n += p.print(':');
56-
}
57-
n += p.printf("%02x", _address.bytes[i]);
58-
n += p.printf("%02x", _address.bytes[i+1]);
59-
52+
size_t n = 0;
53+
for(int i = 0; i < 16; i+=2) {
54+
if(i){
55+
n += p.print(':');
6056
}
61-
return n;
57+
n += p.printf("%02x", _address.bytes[i]);
58+
n += p.printf("%02x", _address.bytes[i+1]);
59+
60+
}
61+
return n;
6262
}
6363

6464
String IPv6Address::toString() const
6565
{
66-
char szRet[40];
67-
sprintf(szRet,"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
68-
_address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3],
69-
_address.bytes[4], _address.bytes[5], _address.bytes[6], _address.bytes[7],
70-
_address.bytes[8], _address.bytes[9], _address.bytes[10], _address.bytes[11],
71-
_address.bytes[12], _address.bytes[13], _address.bytes[14], _address.bytes[15]);
72-
return String(szRet);
66+
char szRet[40];
67+
sprintf(szRet,"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
68+
_address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3],
69+
_address.bytes[4], _address.bytes[5], _address.bytes[6], _address.bytes[7],
70+
_address.bytes[8], _address.bytes[9], _address.bytes[10], _address.bytes[11],
71+
_address.bytes[12], _address.bytes[13], _address.bytes[14], _address.bytes[15]);
72+
return String(szRet);
7373
}
7474

7575
bool IPv6Address::fromString(const char *address)
7676
{
77-
//format 0011:2233:4455:6677:8899:aabb:ccdd:eeff
78-
if(strlen(address) != 39){
79-
return false;
80-
}
81-
char * pos = (char *)address;
82-
size_t i = 0;
83-
for(i = 0; i < 16; i+=2) {
84-
if(!sscanf(pos, "%2hhx", &_address.bytes[i]) || !sscanf(pos+2, "%2hhx", &_address.bytes[i+1])){
85-
return false;
86-
}
87-
pos += 5;
77+
//format 0011:2233:4455:6677:8899:aabb:ccdd:eeff
78+
if(strlen(address) != 39){
79+
return false;
80+
}
81+
char * pos = (char *)address;
82+
size_t i = 0;
83+
for(i = 0; i < 16; i+=2) {
84+
if(!sscanf(pos, "%2hhx", &_address.bytes[i]) || !sscanf(pos+2, "%2hhx", &_address.bytes[i+1])){
85+
return false;
8886
}
89-
return true;
87+
pos += 5;
88+
}
89+
return true;
9090
}

Diff for: cores/arduino/IPv6Address.h

+59-57
Original file line numberDiff line numberDiff line change
@@ -29,65 +29,67 @@
2929
class IPv6Address: public Printable
3030
{
3131
private:
32-
union {
33-
uint8_t bytes[16]; // IPv4 address
34-
uint32_t dword[4];
35-
} _address;
36-
37-
// Access the raw byte array containing the address. Because this returns a pointer
38-
// to the internal structure rather than a copy of the address this function should only
39-
// be used when you know that the usage of the returned uint8_t* will be transient and not
40-
// stored.
41-
uint8_t* raw_address()
42-
{
43-
return _address.bytes;
44-
}
32+
union {
33+
uint8_t bytes[16]; // IPv4 address
34+
uint32_t dword[4];
35+
} _address;
36+
37+
// Access the raw byte array containing the address. Because this returns a pointer
38+
// to the internal structure rather than a copy of the address this function should only
39+
// be used when you know that the usage of the returned uint8_t* will be transient and not
40+
// stored.
41+
uint8_t* raw_address()
42+
{
43+
return _address.bytes;
44+
}
4545

4646
public:
47-
// Constructors
48-
IPv6Address();
49-
IPv6Address(const uint8_t *address);
50-
IPv6Address(const uint32_t *address);
51-
52-
bool fromString(const char *address);
53-
bool fromString(const String &address) { return fromString(address.c_str()); }
54-
55-
operator const uint8_t*() const
56-
{
57-
return _address.bytes;
58-
}
59-
operator const uint32_t*() const
60-
{
61-
return _address.dword;
62-
}
63-
bool operator==(const IPv6Address& addr) const
64-
{
65-
return (_address.dword[0] == addr._address.dword[0])
66-
&& (_address.dword[1] == addr._address.dword[1])
67-
&& (_address.dword[2] == addr._address.dword[2])
68-
&& (_address.dword[3] == addr._address.dword[3]);
69-
}
70-
bool operator==(const uint8_t* addr) const;
71-
72-
// Overloaded index operator to allow getting and setting individual octets of the address
73-
uint8_t operator[](int index) const
74-
{
75-
return _address.bytes[index];
76-
}
77-
uint8_t& operator[](int index)
78-
{
79-
return _address.bytes[index];
80-
}
81-
82-
// Overloaded copy operators to allow initialisation of IPv6Address objects from other types
83-
IPv6Address& operator=(const uint8_t *address);
84-
85-
virtual size_t printTo(Print& p) const;
86-
String toString() const;
87-
88-
friend class UDP;
89-
friend class Client;
90-
friend class Server;
47+
// Constructors
48+
IPv6Address();
49+
IPv6Address(const uint8_t *address);
50+
IPv6Address(const uint32_t *address);
51+
52+
bool fromString(const char *address);
53+
bool fromString(const String &address) {
54+
return fromString(address.c_str());
55+
}
56+
57+
operator const uint8_t*() const
58+
{
59+
return _address.bytes;
60+
}
61+
operator const uint32_t*() const
62+
{
63+
return _address.dword;
64+
}
65+
bool operator==(const IPv6Address& addr) const
66+
{
67+
return (_address.dword[0] == addr._address.dword[0])
68+
&& (_address.dword[1] == addr._address.dword[1])
69+
&& (_address.dword[2] == addr._address.dword[2])
70+
&& (_address.dword[3] == addr._address.dword[3]);
71+
}
72+
bool operator==(const uint8_t* addr) const;
73+
74+
// Overloaded index operator to allow getting and setting individual octets of the address
75+
uint8_t operator[](int index) const
76+
{
77+
return _address.bytes[index];
78+
}
79+
uint8_t& operator[](int index)
80+
{
81+
return _address.bytes[index];
82+
}
83+
84+
// Overloaded copy operators to allow initialisation of IPv6Address objects from other types
85+
IPv6Address& operator=(const uint8_t *address);
86+
87+
virtual size_t printTo(Print& p) const;
88+
String toString() const;
89+
90+
friend class UDP;
91+
friend class Client;
92+
friend class Server;
9193
};
9294

9395
#endif

0 commit comments

Comments
 (0)