sources/network/ipaddress.cpp

branch
protocol5
changeset 141
d9073c13dc98
parent 137
485cb6d6b98c
child 145
d0aedc9be448
equal deleted inserted replaced
136:8fb1c657e0b0 141:d9073c13dc98
96 96
97 // ----------------------------------------------------------------------------- 97 // -----------------------------------------------------------------------------
98 // 98 //
99 bool IPAddress::compare (const IPAddress& other) const 99 bool IPAddress::compare (const IPAddress& other) const
100 { 100 {
101 for (int i = 0; i < 4; ++i) 101 for (int i : range(4))
102 { 102 {
103 if (octet (i) != other.octet (i)) 103 if (octet (i) != other.octet (i))
104 return false; 104 return false;
105 } 105 }
106 106
116 116
117 // ----------------------------------------------------------------------------- 117 // -----------------------------------------------------------------------------
118 // 118 //
119 bool IPAddress::operator< (const IPAddress& other) const 119 bool IPAddress::operator< (const IPAddress& other) const
120 { 120 {
121 for (int i = 0; i < 4; ++i) 121 for (int i : range(4))
122 { 122 {
123 if (octet (i) != other.octet (i)) 123 if (octet (i) != other.octet (i))
124 return octet (i) < other.octet (i); 124 return octet (i) < other.octet (i);
125 } 125 }
126 126
149 IPAddress value; 149 IPAddress value;
150 150
151 // Try scanf the IPv4 host first 151 // Try scanf the IPv4 host first
152 if (sscanf (addressString, "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3])) 152 if (sscanf (addressString, "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3]))
153 { 153 {
154 for (short i = 0; i < 4; ++i) 154 for (int i : range(4))
155 value.set_octet (i, parts[i]); 155 value.set_octet (i, parts[i]);
156 } 156 }
157 else 157 else
158 { 158 {
159 // Possibly a hostname, try resolve it 159 // Possibly a hostname, try resolve it

mercurial