Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: net/base/address_tracker_linux_unittest.cc

Issue 1158923005: Use the exact-width integer types defined in <stdint.h> rather than (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak comments. Exclude mime_sniffer*. Rebase. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "net/base/address_tracker_linux.h" 6 #include "net/base/address_tracker_linux.h"
7 7
8 #include <linux/if.h> 8 #include <linux/if.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 base::hash_set<std::string> ignored_interfaces_; 107 base::hash_set<std::string> ignored_interfaces_;
108 scoped_ptr<AddressTrackerLinux> tracker_; 108 scoped_ptr<AddressTrackerLinux> tracker_;
109 AddressTrackerLinux::GetInterfaceNameFunction original_get_interface_name_; 109 AddressTrackerLinux::GetInterfaceNameFunction original_get_interface_name_;
110 }; 110 };
111 111
112 namespace { 112 namespace {
113 113
114 class NetlinkMessage { 114 class NetlinkMessage {
115 public: 115 public:
116 explicit NetlinkMessage(uint16 type) : buffer_(NLMSG_HDRLEN) { 116 explicit NetlinkMessage(uint16_t type) : buffer_(NLMSG_HDRLEN) {
117 header()->nlmsg_type = type; 117 header()->nlmsg_type = type;
118 Align(); 118 Align();
119 } 119 }
120 120
121 void AddPayload(const void* data, size_t length) { 121 void AddPayload(const void* data, size_t length) {
122 CHECK_EQ(static_cast<size_t>(NLMSG_HDRLEN), 122 CHECK_EQ(static_cast<size_t>(NLMSG_HDRLEN),
123 buffer_.size()) << "Payload must be added first"; 123 buffer_.size()) << "Payload must be added first";
124 Append(data, length); 124 Append(data, length);
125 Align(); 125 Align();
126 } 126 }
127 127
128 void AddAttribute(uint16 type, const void* data, size_t length) { 128 void AddAttribute(uint16_t type, const void* data, size_t length) {
129 struct nlattr attr; 129 struct nlattr attr;
130 attr.nla_len = NLA_HDRLEN + length; 130 attr.nla_len = NLA_HDRLEN + length;
131 attr.nla_type = type; 131 attr.nla_type = type;
132 Append(&attr, sizeof(attr)); 132 Append(&attr, sizeof(attr));
133 Align(); 133 Align();
134 Append(data, length); 134 Append(data, length);
135 Align(); 135 Align();
136 } 136 }
137 137
138 void AppendTo(Buffer* output) const { 138 void AppendTo(Buffer* output) const {
(...skipping 17 matching lines...) Expand all
156 156
157 struct nlmsghdr* header() { 157 struct nlmsghdr* header() {
158 return reinterpret_cast<struct nlmsghdr*>(&buffer_[0]); 158 return reinterpret_cast<struct nlmsghdr*>(&buffer_[0]);
159 } 159 }
160 160
161 Buffer buffer_; 161 Buffer buffer_;
162 }; 162 };
163 163
164 #define INFINITY_LIFE_TIME 0xFFFFFFFF 164 #define INFINITY_LIFE_TIME 0xFFFFFFFF
165 165
166 void MakeAddrMessageWithCacheInfo(uint16 type, 166 void MakeAddrMessageWithCacheInfo(uint16_t type,
167 uint8 flags, 167 uint8_t flags,
168 uint8 family, 168 uint8_t family,
169 int index, 169 int index,
170 const IPAddressNumber& address, 170 const IPAddressNumber& address,
171 const IPAddressNumber& local, 171 const IPAddressNumber& local,
172 uint32 preferred_lifetime, 172 uint32_t preferred_lifetime,
173 Buffer* output) { 173 Buffer* output) {
174 NetlinkMessage nlmsg(type); 174 NetlinkMessage nlmsg(type);
175 struct ifaddrmsg msg = {}; 175 struct ifaddrmsg msg = {};
176 msg.ifa_family = family; 176 msg.ifa_family = family;
177 msg.ifa_flags = flags; 177 msg.ifa_flags = flags;
178 msg.ifa_index = index; 178 msg.ifa_index = index;
179 nlmsg.AddPayload(&msg, sizeof(msg)); 179 nlmsg.AddPayload(&msg, sizeof(msg));
180 if (address.size()) 180 if (address.size())
181 nlmsg.AddAttribute(IFA_ADDRESS, &address[0], address.size()); 181 nlmsg.AddAttribute(IFA_ADDRESS, &address[0], address.size());
182 if (local.size()) 182 if (local.size())
183 nlmsg.AddAttribute(IFA_LOCAL, &local[0], local.size()); 183 nlmsg.AddAttribute(IFA_LOCAL, &local[0], local.size());
184 struct ifa_cacheinfo cache_info = {}; 184 struct ifa_cacheinfo cache_info = {};
185 cache_info.ifa_prefered = preferred_lifetime; 185 cache_info.ifa_prefered = preferred_lifetime;
186 cache_info.ifa_valid = INFINITY_LIFE_TIME; 186 cache_info.ifa_valid = INFINITY_LIFE_TIME;
187 nlmsg.AddAttribute(IFA_CACHEINFO, &cache_info, sizeof(cache_info)); 187 nlmsg.AddAttribute(IFA_CACHEINFO, &cache_info, sizeof(cache_info));
188 nlmsg.AppendTo(output); 188 nlmsg.AppendTo(output);
189 } 189 }
190 190
191 void MakeAddrMessage(uint16 type, 191 void MakeAddrMessage(uint16_t type,
192 uint8 flags, 192 uint8_t flags,
193 uint8 family, 193 uint8_t family,
194 int index, 194 int index,
195 const IPAddressNumber& address, 195 const IPAddressNumber& address,
196 const IPAddressNumber& local, 196 const IPAddressNumber& local,
197 Buffer* output) { 197 Buffer* output) {
198 MakeAddrMessageWithCacheInfo(type, flags, family, index, address, local, 198 MakeAddrMessageWithCacheInfo(type, flags, family, index, address, local,
199 INFINITY_LIFE_TIME, output); 199 INFINITY_LIFE_TIME, output);
200 } 200 }
201 201
202 void MakeLinkMessage(uint16 type, uint32 flags, uint32 index, Buffer* output) { 202 void MakeLinkMessage(uint16_t type,
203 uint32_t flags,
204 uint32_t index,
205 Buffer* output) {
203 NetlinkMessage nlmsg(type); 206 NetlinkMessage nlmsg(type);
204 struct ifinfomsg msg = {}; 207 struct ifinfomsg msg = {};
205 msg.ifi_index = index; 208 msg.ifi_index = index;
206 msg.ifi_flags = flags; 209 msg.ifi_flags = flags;
207 nlmsg.AddPayload(&msg, sizeof(msg)); 210 nlmsg.AddPayload(&msg, sizeof(msg));
208 output->clear(); 211 output->clear();
209 nlmsg.AppendTo(output); 212 nlmsg.AppendTo(output);
210 } 213 }
211 214
212 const unsigned char kAddress0[] = { 127, 0, 0, 1 }; 215 const unsigned char kAddress0[] = { 127, 0, 0, 1 };
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 635
633 TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) { 636 TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) {
634 AddressTrackerLinux tracker; 637 AddressTrackerLinux tracker;
635 tracker.Init(); 638 tracker.Init();
636 } 639 }
637 640
638 } // namespace 641 } // namespace
639 642
640 } // namespace internal 643 } // namespace internal
641 } // namespace net 644 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698