shill: Add HTTP Request object
Add an object that requests an HTTP URL through a given connection.
This will be used by portal detection.
BUG=chromium-os:23318
TEST=New unit tests
Change-Id: I060c1ebf32c84df3f77b321277e5fc652b0366a8
Reviewed-on: https://gerrit.chromium.org/gerrit/14593
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
diff --git a/ip_address.cc b/ip_address.cc
index d1334d0..e71f574 100644
--- a/ip_address.cc
+++ b/ip_address.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,8 @@
#include "shill/byte_string.h"
+using std::string;
+
namespace shill {
// static
@@ -49,7 +51,7 @@
}
}
-bool IPAddress::SetAddressFromString(const std::string &address_string) {
+bool IPAddress::SetAddressFromString(const string &address_string) {
int address_length = GetAddressLength(family_);
if (!address_length) {
@@ -68,4 +70,15 @@
address_ = ByteString(GetAddressLength(family_));
}
+bool IPAddress::ToString(string *address_string) const {
+ // Noting that INET6_ADDRSTRLEN > INET_ADDRSTRLEN
+ char address_buf[INET6_ADDRSTRLEN];
+ if (GetLength() != GetAddressLength(family_) ||
+ !inet_ntop(family_, GetConstData(), address_buf, sizeof(address_buf))) {
+ return false;
+ }
+ *address_string = address_buf;
+ return true;
+}
+
} // namespace shill