OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/cros/network_ip_config.h" | 5 #include "chrome/browser/chromeos/cros/network_ip_config.h" |
6 | 6 |
7 #include "base/string_tokenizer.h" | 7 #include "base/string_tokenizer.h" |
8 | 8 |
9 namespace chromeos { | 9 namespace chromeos { |
10 | 10 |
11 namespace { | |
12 #define ENUM_CASE(x) case x: return std::string(#x) | |
13 std::string IPConfigTypeAsString(IPConfigType type) { | |
14 switch (type) { | |
15 ENUM_CASE(IPCONFIG_TYPE_UNKNOWN); | |
16 ENUM_CASE(IPCONFIG_TYPE_IPV4); | |
17 ENUM_CASE(IPCONFIG_TYPE_IPV6); | |
18 ENUM_CASE(IPCONFIG_TYPE_DHCP); | |
19 ENUM_CASE(IPCONFIG_TYPE_BOOTP); | |
20 ENUM_CASE(IPCONFIG_TYPE_ZEROCONF); | |
21 ENUM_CASE(IPCONFIG_TYPE_DHCP6); | |
22 ENUM_CASE(IPCONFIG_TYPE_PPP); | |
23 } | |
stevenjb
2012/05/21 23:59:46
Doesn't this need a NOTREACHED() + return std::str
Greg Spencer (Chromium)
2012/05/22 00:45:14
Done.
| |
24 } | |
25 #undef ENUM_CASE | |
26 } // namespace | |
27 | |
11 NetworkIPConfig::NetworkIPConfig( | 28 NetworkIPConfig::NetworkIPConfig( |
12 const std::string& device_path, IPConfigType type, | 29 const std::string& device_path, IPConfigType type, |
13 const std::string& address, const std::string& netmask, | 30 const std::string& address, const std::string& netmask, |
14 const std::string& gateway, const std::string& name_servers) | 31 const std::string& gateway, const std::string& name_servers) |
15 : device_path(device_path), | 32 : device_path(device_path), |
16 type(type), | 33 type(type), |
17 address(address), | 34 address(address), |
18 netmask(netmask), | 35 netmask(netmask), |
19 gateway(gateway), | 36 gateway(gateway), |
20 name_servers(name_servers) { | 37 name_servers(name_servers) { |
21 } | 38 } |
22 | 39 |
23 NetworkIPConfig::~NetworkIPConfig() {} | 40 NetworkIPConfig::~NetworkIPConfig() {} |
24 | 41 |
42 std::string NetworkIPConfig::ToString() const { | |
43 return std::string("path: ") + device_path | |
44 + " type: " + IPConfigTypeAsString(type) | |
45 + " address: " + address | |
46 + " netmask: " + netmask | |
47 + " gateway: " + gateway | |
48 + " name_servers: " + name_servers; | |
49 } | |
50 | |
25 int32 NetworkIPConfig::GetPrefixLength() const { | 51 int32 NetworkIPConfig::GetPrefixLength() const { |
26 int count = 0; | 52 int count = 0; |
27 int prefixlen = 0; | 53 int prefixlen = 0; |
28 StringTokenizer t(netmask, "."); | 54 StringTokenizer t(netmask, "."); |
29 while (t.GetNext()) { | 55 while (t.GetNext()) { |
30 // If there are more than 4 numbers, then it's invalid. | 56 // If there are more than 4 numbers, then it's invalid. |
31 if (count == 4) { | 57 if (count == 4) { |
32 return -1; | 58 return -1; |
33 } | 59 } |
34 std::string token = t.token(); | 60 std::string token = t.token(); |
(...skipping 26 matching lines...) Expand all Loading... | |
61 return -1; | 87 return -1; |
62 } | 88 } |
63 count++; | 89 count++; |
64 } | 90 } |
65 if (count < 4) | 91 if (count < 4) |
66 return -1; | 92 return -1; |
67 return prefixlen; | 93 return prefixlen; |
68 } | 94 } |
69 | 95 |
70 } // namespace chromeos | 96 } // namespace chromeos |
OLD | NEW |