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 "chromeos/network/network_util.h" | 5 #include "chromeos/network/network_util.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_tokenizer.h" | 11 #include "base/strings/string_tokenizer.h" |
9 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
10 #include "chromeos/login/login_state.h" | 13 #include "chromeos/login/login_state.h" |
11 #include "chromeos/network/device_state.h" | 14 #include "chromeos/network/device_state.h" |
12 #include "chromeos/network/managed_network_configuration_handler.h" | 15 #include "chromeos/network/managed_network_configuration_handler.h" |
13 #include "chromeos/network/network_state.h" | 16 #include "chromeos/network/network_state.h" |
14 #include "chromeos/network/network_state_handler.h" | 17 #include "chromeos/network/network_state_handler.h" |
15 #include "chromeos/network/network_ui_data.h" | 18 #include "chromeos/network/network_ui_data.h" |
16 #include "chromeos/network/onc/onc_signature.h" | 19 #include "chromeos/network/onc/onc_signature.h" |
(...skipping 13 matching lines...) Expand all Loading... |
30 } | 33 } |
31 | 34 |
32 CellularScanResult::CellularScanResult() { | 35 CellularScanResult::CellularScanResult() { |
33 } | 36 } |
34 | 37 |
35 CellularScanResult::~CellularScanResult() { | 38 CellularScanResult::~CellularScanResult() { |
36 } | 39 } |
37 | 40 |
38 namespace network_util { | 41 namespace network_util { |
39 | 42 |
40 std::string PrefixLengthToNetmask(int32 prefix_length) { | 43 std::string PrefixLengthToNetmask(int32_t prefix_length) { |
41 std::string netmask; | 44 std::string netmask; |
42 // Return the empty string for invalid inputs. | 45 // Return the empty string for invalid inputs. |
43 if (prefix_length < 0 || prefix_length > 32) | 46 if (prefix_length < 0 || prefix_length > 32) |
44 return netmask; | 47 return netmask; |
45 for (int i = 0; i < 4; i++) { | 48 for (int i = 0; i < 4; i++) { |
46 int remainder = 8; | 49 int remainder = 8; |
47 if (prefix_length >= 8) { | 50 if (prefix_length >= 8) { |
48 prefix_length -= 8; | 51 prefix_length -= 8; |
49 } else { | 52 } else { |
50 remainder = prefix_length; | 53 remainder = prefix_length; |
51 prefix_length = 0; | 54 prefix_length = 0; |
52 } | 55 } |
53 if (i > 0) | 56 if (i > 0) |
54 netmask += "."; | 57 netmask += "."; |
55 int value = remainder == 0 ? 0 : | 58 int value = remainder == 0 ? 0 : |
56 ((2L << (remainder - 1)) - 1) << (8 - remainder); | 59 ((2L << (remainder - 1)) - 1) << (8 - remainder); |
57 netmask += base::IntToString(value); | 60 netmask += base::IntToString(value); |
58 } | 61 } |
59 return netmask; | 62 return netmask; |
60 } | 63 } |
61 | 64 |
62 int32 NetmaskToPrefixLength(const std::string& netmask) { | 65 int32_t NetmaskToPrefixLength(const std::string& netmask) { |
63 int count = 0; | 66 int count = 0; |
64 int prefix_length = 0; | 67 int prefix_length = 0; |
65 base::StringTokenizer t(netmask, "."); | 68 base::StringTokenizer t(netmask, "."); |
66 while (t.GetNext()) { | 69 while (t.GetNext()) { |
67 // If there are more than 4 numbers, then it's invalid. | 70 // If there are more than 4 numbers, then it's invalid. |
68 if (count == 4) | 71 if (count == 4) |
69 return -1; | 72 return -1; |
70 | 73 |
71 std::string token = t.token(); | 74 std::string token = t.token(); |
72 // If we already found the last mask and the current one is not | 75 // If we already found the last mask and the current one is not |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 std::string TranslateShillTypeToONC(const std::string& shill_type) { | 215 std::string TranslateShillTypeToONC(const std::string& shill_type) { |
213 if (shill_type == shill::kTypeEthernet) | 216 if (shill_type == shill::kTypeEthernet) |
214 return ::onc::network_type::kEthernet; | 217 return ::onc::network_type::kEthernet; |
215 std::string onc_type; | 218 std::string onc_type; |
216 onc::TranslateStringToONC(onc::kNetworkTypeTable, shill_type, &onc_type); | 219 onc::TranslateStringToONC(onc::kNetworkTypeTable, shill_type, &onc_type); |
217 return onc_type; | 220 return onc_type; |
218 } | 221 } |
219 | 222 |
220 } // namespace network_util | 223 } // namespace network_util |
221 } // namespace chromeos | 224 } // namespace chromeos |
OLD | NEW |