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

Unified Diff: net/base/address_tracker_linux.h

Issue 10689015: [net] Adds AddressTrackerLinux which keeps track of interface addresses using rtnetlink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added NET_EXPORT_PRIVATE for tests. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/address_tracker_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/address_tracker_linux.h
diff --git a/net/base/address_tracker_linux.h b/net/base/address_tracker_linux.h
new file mode 100644
index 0000000000000000000000000000000000000000..a70a14ccd3258e8e724e1fcb2c8982b7471d5938
--- /dev/null
+++ b/net/base/address_tracker_linux.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_ADDRESS_TRACKER_LINUX_H_
+#define NET_BASE_ADDRESS_TRACKER_LINUX_H_
+
+#include <sys/socket.h> // Needed to include netlink.
+// Mask superfluous definition of |struct net|. This is fixed in Linux 2.6.38.
+#define net net_kernel
+#include <linux/rtnetlink.h>
+#undef net
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/compiler_specific.h"
+#include "base/message_loop.h"
+#include "base/synchronization/lock.h"
+#include "net/base/net_util.h"
+
+namespace net {
+namespace internal {
+
+// Keeps track of network interface addresses using rtnetlink. Used by
+// NetworkChangeNotifier to provide signals to registered IPAddressObservers.
+class NET_EXPORT_PRIVATE AddressTrackerLinux
+ : public MessageLoopForIO::Watcher {
+ public:
+ typedef std::map<IPAddressNumber, struct ifaddrmsg> AddressMap;
+
+ // Will run |callback| when the AddressMap changes.
+ explicit AddressTrackerLinux(const base::Closure& callback);
+ virtual ~AddressTrackerLinux();
+
+ // Starts watching system configuration for changes. The current thread must
+ // have a MessageLoopForIO.
+ void Init();
+
+ AddressMap GetAddressMap() const;
+
+ private:
+ friend class AddressTrackerLinuxTest;
+
+ // Returns true if |map_| changed while reading messages from |netlink_fd_|.
+ bool ReadMessages();
+
+ // Returns true if |map_| changed while reading the message from |buffer|.
+ bool HandleMessage(const char* buffer, size_t length);
+
+ // MessageLoopForIO::Watcher:
+ virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
+ virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE;
+
+ base::Closure callback_;
+
+ int netlink_fd_;
+ MessageLoopForIO::FileDescriptorWatcher watcher_;
+
+ mutable base::Lock lock_;
+ AddressMap map_;
+};
+
+} // namespace internal
+} // namespace net
+
+#endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_
« no previous file with comments | « no previous file | net/base/address_tracker_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698