| 194 | |
| 195 | |
| 196 | Try<net::IP::Network> getNonLoopbackIP() |
| 197 | { |
| 198 | Try<set<string>> links = net::links(); |
| 199 | if (links.isError()) { |
| 200 | return Error( |
| 201 | "Unable to retrieve interfaces on this host: " + |
| 202 | links.error()); |
| 203 | } |
| 204 | |
| 205 | foreach (const string& link, links.get()) { |
| 206 | Result<net::IP::Network> hostNetwork = |
| 207 | net::IP::Network::fromLinkDevice(link, AF_INET); |
| 208 | |
| 209 | if (hostNetwork.isError()) { |
| 210 | return Error( |
| 211 | "Unable to find a non-loopback address: " + |
| 212 | hostNetwork.error()); |
| 213 | } |
| 214 | |
| 215 | if (hostNetwork.isSome() && |
| 216 | (hostNetwork.get() != net::IP::Network::LOOPBACK_V4())) { |
| 217 | return hostNetwork.get(); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return Error("No non-loopback addresses available on this host"); |
| 222 | } |
| 223 | |
| 224 | } // namespace tests { |
| 225 | } // namespace internal { |