summaryrefslogtreecommitdiffstats
path: root/net/tools
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-16 20:23:12 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-16 20:23:12 +0000
commit11db6c2a71141a3fe28d8bc9080b7b341ce7563a (patch)
treea9e519a718726382c91b6abaeb319c16d3109a71 /net/tools
parent899bbef82cc9477e59870bcfcb2e4c6418d17d2a (diff)
downloadchromium_src-11db6c2a71141a3fe28d8bc9080b7b341ce7563a.zip
chromium_src-11db6c2a71141a3fe28d8bc9080b7b341ce7563a.tar.gz
chromium_src-11db6c2a71141a3fe28d8bc9080b7b341ce7563a.tar.bz2
Replace setsockopt(IP_PKTINFO) and setsockopt(IPV6_RECVPKTINFO) calls by
gfe_quic::QuicSocketUtils::SetGetAddressInfo() calls. Update gfe_quic::QuicSocketUtils::SetGetAddressInfo() to the best-known implementation. Merge internal CL: 70966702 R=rtenneti@chromium.org BUG=none Review URL: https://codereview.chromium.org/397793004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283482 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rw-r--r--net/tools/quic/quic_client.cc10
-rw-r--r--net/tools/quic/quic_server.cc26
-rw-r--r--net/tools/quic/quic_socket_utils.cc10
3 files changed, 15 insertions, 31 deletions
diff --git a/net/tools/quic/quic_client.cc b/net/tools/quic/quic_client.cc
index 19e9801..c443434 100644
--- a/net/tools/quic/quic_client.cc
+++ b/net/tools/quic/quic_client.cc
@@ -124,15 +124,7 @@ bool QuicClient::CreateUDPSocket() {
return false;
}
- int get_local_ip = 1;
- if (address_family == AF_INET) {
- rc = setsockopt(fd_, IPPROTO_IP, IP_PKTINFO,
- &get_local_ip, sizeof(get_local_ip));
- } else {
- rc = setsockopt(fd_, IPPROTO_IPV6, IPV6_RECVPKTINFO,
- &get_local_ip, sizeof(get_local_ip));
- }
-
+ rc = QuicSocketUtils::SetGetAddressInfo(fd_, address_family);
if (rc < 0) {
LOG(ERROR) << "IP detection not supported" << strerror(errno);
return false;
diff --git a/net/tools/quic/quic_server.cc b/net/tools/quic/quic_server.cc
index 40e389c..e496cd6 100644
--- a/net/tools/quic/quic_server.cc
+++ b/net/tools/quic/quic_server.cc
@@ -28,12 +28,16 @@
#define SO_RXQ_OVFL 40
#endif
+namespace net {
+namespace tools {
+
+namespace {
+
const int kEpollFlags = EPOLLIN | EPOLLOUT | EPOLLET;
-static const char kSourceAddressTokenSecret[] = "secret";
+const char kSourceAddressTokenSecret[] = "secret";
const uint32 kServerInitialFlowControlWindow = 100 * net::kMaxPacketSize;
-namespace net {
-namespace tools {
+} // namespace
QuicServer::QuicServer()
: port_(0),
@@ -92,6 +96,8 @@ bool QuicServer::Listen(const IPEndPoint& address) {
return false;
}
+ // Enable the socket option that allows the local address to be
+ // returned if the socket is bound to more than one address.
int rc = QuicSocketUtils::SetGetAddressInfo(fd_, address_family);
if (rc < 0) {
@@ -122,20 +128,6 @@ bool QuicServer::Listen(const IPEndPoint& address) {
return false;
}
- // Enable the socket option that allows the local address to be
- // returned if the socket is bound to more than on address.
- int get_local_ip = 1;
- rc = setsockopt(fd_, IPPROTO_IP, IP_PKTINFO,
- &get_local_ip, sizeof(get_local_ip));
- if (rc == 0 && address_family == AF_INET6) {
- rc = setsockopt(fd_, IPPROTO_IPV6, IPV6_RECVPKTINFO,
- &get_local_ip, sizeof(get_local_ip));
- }
- if (rc != 0) {
- LOG(ERROR) << "Failed to set required socket options";
- return false;
- }
-
sockaddr_storage raw_addr;
socklen_t raw_addr_len = sizeof(raw_addr);
CHECK(address.ToSockAddr(reinterpret_cast<sockaddr*>(&raw_addr),
diff --git a/net/tools/quic/quic_socket_utils.cc b/net/tools/quic/quic_socket_utils.cc
index 3202150..f635515 100644
--- a/net/tools/quic/quic_socket_utils.cc
+++ b/net/tools/quic/quic_socket_utils.cc
@@ -70,13 +70,13 @@ bool QuicSocketUtils::GetOverflowFromMsghdr(struct msghdr *hdr,
// static
int QuicSocketUtils::SetGetAddressInfo(int fd, int address_family) {
int get_local_ip = 1;
- if (address_family == AF_INET) {
- return setsockopt(fd, IPPROTO_IP, IP_PKTINFO,
- &get_local_ip, sizeof(get_local_ip));
- } else {
- return setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
+ int rc = setsockopt(fd, IPPROTO_IP, IP_PKTINFO,
&get_local_ip, sizeof(get_local_ip));
+ if (rc == 0 && address_family == AF_INET6) {
+ rc = setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
+ &get_local_ip, sizeof(get_local_ip));
}
+ return rc;
}
// static