aboutsummaryrefslogtreecommitdiff
path: root/core/io/ip_address.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/ip_address.cpp')
-rw-r--r--core/io/ip_address.cpp74
1 files changed, 36 insertions, 38 deletions
diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp
index 69c7df619..fa0eab4f0 100644
--- a/core/io/ip_address.cpp
+++ b/core/io/ip_address.cpp
@@ -33,32 +33,32 @@ IP_Address::operator Variant() const {
return operator String();
}*/
-#include <string.h>
#include <stdio.h>
+#include <string.h>
IP_Address::operator String() const {
- if(!valid)
+ if (!valid)
return "";
- if(is_ipv4())
+ if (is_ipv4())
// IPv4 address mapped to IPv6
- return itos(field8[12])+"."+itos(field8[13])+"."+itos(field8[14])+"."+itos(field8[15]);
+ return itos(field8[12]) + "." + itos(field8[13]) + "." + itos(field8[14]) + "." + itos(field8[15]);
String ret;
- for (int i=0; i<8; i++) {
+ for (int i = 0; i < 8; i++) {
if (i > 0)
ret = ret + ":";
- uint16_t num = (field8[i*2] << 8) + field8[i*2+1];
+ uint16_t num = (field8[i * 2] << 8) + field8[i * 2 + 1];
ret = ret + String::num_int64(num, 16);
};
return ret;
}
-static void _parse_hex(const String& p_string, int p_start, uint8_t* p_dst) {
+static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
uint16_t ret = 0;
- for (int i=p_start; i<p_start + 4; i++) {
+ for (int i = p_start; i < p_start + 4; i++) {
if (i >= p_string.length()) {
break;
@@ -87,17 +87,17 @@ static void _parse_hex(const String& p_string, int p_start, uint8_t* p_dst) {
p_dst[1] = ret & 0xff;
};
-void IP_Address::_parse_ipv6(const String& p_string) {
+void IP_Address::_parse_ipv6(const String &p_string) {
static const int parts_total = 8;
- int parts[parts_total] = {0};
+ int parts[parts_total] = { 0 };
int parts_count = 0;
bool part_found = false;
bool part_skip = false;
bool part_ipv4 = false;
int parts_idx = 0;
- for (int i=0; i<p_string.length(); i++) {
+ for (int i = 0; i < p_string.length(); i++) {
CharType c = p_string[i];
if (c == ':') {
@@ -133,26 +133,25 @@ void IP_Address::_parse_ipv6(const String& p_string) {
};
int idx = 0;
- for (int i=0; i<parts_idx; i++) {
+ for (int i = 0; i < parts_idx; i++) {
if (parts[i] == -1) {
- for (int j=0; j<parts_extra; j++) {
+ for (int j = 0; j < parts_extra; j++) {
field16[idx++] = 0;
};
continue;
};
if (part_ipv4 && i == parts_idx - 1) {
- _parse_ipv4(p_string, parts[i], (uint8_t*)&field16[idx]); // should be the last one
+ _parse_ipv4(p_string, parts[i], (uint8_t *)&field16[idx]); // should be the last one
} else {
- _parse_hex(p_string, parts[i], (uint8_t*)&(field16[idx++]));
+ _parse_hex(p_string, parts[i], (uint8_t *)&(field16[idx++]));
};
};
-
};
-void IP_Address::_parse_ipv4(const String& p_string, int p_start, uint8_t* p_ret) {
+void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) {
String ip;
if (p_start != 0) {
@@ -162,12 +161,12 @@ void IP_Address::_parse_ipv4(const String& p_string, int p_start, uint8_t* p_ret
};
int slices = ip.get_slice_count(".");
- if (slices!=4) {
- ERR_EXPLAIN("Invalid IP Address String: "+ip);
+ if (slices != 4) {
+ ERR_EXPLAIN("Invalid IP Address String: " + ip);
ERR_FAIL();
}
- for(int i=0;i<4;i++) {
- p_ret[i]=ip.get_slicec('.',i).to_int();
+ for (int i = 0; i < 4; i++) {
+ p_ret[i] = ip.get_slicec('.', i).to_int();
}
};
@@ -178,34 +177,34 @@ void IP_Address::clear() {
wildcard = false;
};
-bool IP_Address::is_ipv4() const{
- return (field32[0]==0 && field32[1]==0 && field16[4]==0 && field16[5]==0xffff);
+bool IP_Address::is_ipv4() const {
+ return (field32[0] == 0 && field32[1] == 0 && field16[4] == 0 && field16[5] == 0xffff);
}
-const uint8_t *IP_Address::get_ipv4() const{
- ERR_FAIL_COND_V(!is_ipv4(),0);
+const uint8_t *IP_Address::get_ipv4() const {
+ ERR_FAIL_COND_V(!is_ipv4(), 0);
return &(field8[12]);
}
void IP_Address::set_ipv4(const uint8_t *p_ip) {
clear();
valid = true;
- field16[5]=0xffff;
- field32[3]=*((const uint32_t *)p_ip);
+ field16[5] = 0xffff;
+ field32[3] = *((const uint32_t *)p_ip);
}
-const uint8_t *IP_Address::get_ipv6() const{
+const uint8_t *IP_Address::get_ipv6() const {
return field8;
}
void IP_Address::set_ipv6(const uint8_t *p_buf) {
clear();
valid = true;
- for (int i=0; i<16; i++)
+ for (int i = 0; i < 16; i++)
field8[i] = p_buf[i];
}
-IP_Address::IP_Address(const String& p_string) {
+IP_Address::IP_Address(const String &p_string) {
clear();
@@ -229,7 +228,7 @@ IP_Address::IP_Address(const String& p_string) {
}
}
-_FORCE_INLINE_ static void _32_to_buf(uint8_t* p_dst, uint32_t p_n) {
+_FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) {
p_dst[0] = (p_n >> 24) & 0xff;
p_dst[1] = (p_n >> 16) & 0xff;
@@ -237,17 +236,17 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t* p_dst, uint32_t p_n) {
p_dst[3] = (p_n >> 0) & 0xff;
};
-IP_Address::IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, bool is_v6) {
+IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) {
clear();
valid = true;
if (!is_v6) {
// Mapped to IPv6
- field16[5]=0xffff;
- field8[12]=p_a;
- field8[13]=p_b;
- field8[14]=p_c;
- field8[15]=p_d;
+ field16[5] = 0xffff;
+ field8[12] = p_a;
+ field8[13] = p_b;
+ field8[14] = p_c;
+ field8[15] = p_d;
} else {
_32_to_buf(&field8[0], p_a);
@@ -255,5 +254,4 @@ IP_Address::IP_Address(uint32_t p_a,uint32_t p_b,uint32_t p_c,uint32_t p_d, bool
_32_to_buf(&field8[8], p_c);
_32_to_buf(&field8[12], p_d);
}
-
}