116 unsigned int parts[4]; |
116 unsigned int parts[4]; |
117 int colonpos = input.find (":"); |
117 int colonpos = input.find (":"); |
118 String addressString = colonpos == -1 ? input : input.mid (0, colonpos); |
118 String addressString = colonpos == -1 ? input : input.mid (0, colonpos); |
119 IPAddress value; |
119 IPAddress value; |
120 |
120 |
121 // Try scanf the IPv4 host first. If it's not an IP string, it could |
121 // Try scanf the IPv4 host first |
122 // be a hostname; thus try resolve it. |
|
123 if (sscanf (addressString, "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3])) |
122 if (sscanf (addressString, "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3])) |
124 { |
123 { |
125 for (short i = 0; i < 4; ++i) |
124 for (short i = 0; i < 4; ++i) |
126 value.set_octet (i, parts[i]); |
125 value.set_octet (i, parts[i]); |
127 } |
126 } |
128 else |
127 else |
129 { |
128 { |
130 // try resolve it |
129 // Possibly a hostname, try resolve it |
131 return IPAddress::resolve (addressString, ok); |
130 value = IPAddress::resolve (addressString, ok); |
|
131 |
|
132 if (*ok == false) |
|
133 return value; |
132 } |
134 } |
133 |
135 |
134 if (colonpos != -1) |
136 if (colonpos != -1) |
135 value.port = atoi (input.mid (colonpos + 1, -1)); |
137 value.port = input.mid (colonpos + 1, -1).to_int(); |
136 |
138 |
137 return value; |
139 return value; |
138 } |
140 } |
139 |
141 |
140 // ----------------------------------------------------------------------------- |
142 // ----------------------------------------------------------------------------- |