sources/network/ipaddress.cpp

changeset 185
e83ec58cc458
parent 184
afd63357a03d
child 186
9330b93d9946
equal deleted inserted replaced
184:afd63357a03d 185:e83ec58cc458
78 78
79 // ----------------------------------------------------------------------------- 79 // -----------------------------------------------------------------------------
80 // 80 //
81 bool IPAddress::compare (const IPAddress& other) const 81 bool IPAddress::compare (const IPAddress& other) const
82 { 82 {
83 for (int i : range(4)) 83 for (int i = 0; i < 4; i += 1)
84 { 84 {
85 if (octet (i) != other.octet (i)) 85 if (octet (i) != other.octet (i))
86 return false; 86 return false;
87 } 87 }
88 88
98 98
99 // ----------------------------------------------------------------------------- 99 // -----------------------------------------------------------------------------
100 // 100 //
101 bool IPAddress::operator< (const IPAddress& other) const 101 bool IPAddress::operator< (const IPAddress& other) const
102 { 102 {
103 for (int i : range(4)) 103 for (int i = 0; i < 4; i += 1)
104 { 104 {
105 if (octet (i) != other.octet (i)) 105 if (octet (i) != other.octet (i))
106 return octet (i) < other.octet (i); 106 return octet (i) < other.octet (i);
107 } 107 }
108 108
131 IPAddress value; 131 IPAddress value;
132 132
133 // Try scanf the IPv4 host first 133 // Try scanf the IPv4 host first
134 if (sscanf(addressString.data(), "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3])) 134 if (sscanf(addressString.data(), "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3]))
135 { 135 {
136 for (int i : range(4)) 136 for (int i = 0; i < 4; i += 1)
137 value.set_octet (i, parts[i]); 137 value.set_octet (i, parts[i]);
138 } 138 }
139 else 139 else
140 { 140 {
141 // Possibly a hostname, try resolve it 141 // Possibly a hostname, try resolve it

mercurial