| 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 "base/string_tokenizer.h" | |
| 8 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/strings/string_tokenizer.h" |
| 9 | 9 |
| 10 namespace chromeos { | 10 namespace chromeos { |
| 11 | 11 |
| 12 SMS::SMS() : validity(0), msgclass(0) { | 12 SMS::SMS() : validity(0), msgclass(0) { |
| 13 } | 13 } |
| 14 | 14 |
| 15 SMS::~SMS() { | 15 SMS::~SMS() { |
| 16 } | 16 } |
| 17 | 17 |
| 18 WifiAccessPoint::WifiAccessPoint() | 18 WifiAccessPoint::WifiAccessPoint() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 44 int value = remainder == 0 ? 0 : | 44 int value = remainder == 0 ? 0 : |
| 45 ((2L << (remainder - 1)) - 1) << (8 - remainder); | 45 ((2L << (remainder - 1)) - 1) << (8 - remainder); |
| 46 netmask += StringPrintf("%d", value); | 46 netmask += StringPrintf("%d", value); |
| 47 } | 47 } |
| 48 return netmask; | 48 return netmask; |
| 49 } | 49 } |
| 50 | 50 |
| 51 int32 NetmaskToPrefixLength(const std::string& netmask) { | 51 int32 NetmaskToPrefixLength(const std::string& netmask) { |
| 52 int count = 0; | 52 int count = 0; |
| 53 int prefix_length = 0; | 53 int prefix_length = 0; |
| 54 StringTokenizer t(netmask, "."); | 54 base::StringTokenizer t(netmask, "."); |
| 55 while (t.GetNext()) { | 55 while (t.GetNext()) { |
| 56 // If there are more than 4 numbers, then it's invalid. | 56 // If there are more than 4 numbers, then it's invalid. |
| 57 if (count == 4) | 57 if (count == 4) |
| 58 return -1; | 58 return -1; |
| 59 | 59 |
| 60 std::string token = t.token(); | 60 std::string token = t.token(); |
| 61 // If we already found the last mask and the current one is not | 61 // If we already found the last mask and the current one is not |
| 62 // "0" then the netmask is invalid. For example, 255.224.255.0 | 62 // "0" then the netmask is invalid. For example, 255.224.255.0 |
| 63 if (prefix_length / 8 != count) { | 63 if (prefix_length / 8 != count) { |
| 64 if (token != "0") | 64 if (token != "0") |
| (...skipping 22 matching lines...) Expand all Loading... |
| 87 } | 87 } |
| 88 count++; | 88 count++; |
| 89 } | 89 } |
| 90 if (count < 4) | 90 if (count < 4) |
| 91 return -1; | 91 return -1; |
| 92 return prefix_length; | 92 return prefix_length; |
| 93 } | 93 } |
| 94 | 94 |
| 95 } // namespace network_util | 95 } // namespace network_util |
| 96 } // namespace chromeos | 96 } // namespace chromeos |
| OLD | NEW |