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 "net/tools/quic/quic_socket_utils.h" | 5 #include "net/tools/quic/quic_socket_utils.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <linux/net_tstamp.h> | 8 #include <linux/net_tstamp.h> |
9 #include <netinet/in.h> | 9 #include <netinet/in.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 if (cmsg->cmsg_type == SO_RXQ_OVFL) { | 66 if (cmsg->cmsg_type == SO_RXQ_OVFL) { |
67 *dropped_packets = *(reinterpret_cast<uint32_t*> CMSG_DATA(cmsg)); | 67 *dropped_packets = *(reinterpret_cast<uint32_t*> CMSG_DATA(cmsg)); |
68 return true; | 68 return true; |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 // static | 75 // static |
| 76 bool QuicSocketUtils::GetTtlFromMsghdr(struct msghdr* hdr, int* ttl) { |
| 77 if (hdr->msg_controllen > 0) { |
| 78 struct cmsghdr* cmsg; |
| 79 for (cmsg = CMSG_FIRSTHDR(hdr); cmsg != nullptr; |
| 80 cmsg = CMSG_NXTHDR(hdr, cmsg)) { |
| 81 if ((cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_TTL) || |
| 82 (cmsg->cmsg_level == IPPROTO_IPV6 && |
| 83 cmsg->cmsg_type == IPV6_HOPLIMIT)) { |
| 84 *ttl = *(reinterpret_cast<int*>(CMSG_DATA(cmsg))); |
| 85 return true; |
| 86 } |
| 87 } |
| 88 } |
| 89 return false; |
| 90 } |
| 91 |
| 92 // static |
76 int QuicSocketUtils::SetGetAddressInfo(int fd, int address_family) { | 93 int QuicSocketUtils::SetGetAddressInfo(int fd, int address_family) { |
77 int get_local_ip = 1; | 94 int get_local_ip = 1; |
78 int rc = setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &get_local_ip, | 95 int rc = setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &get_local_ip, |
79 sizeof(get_local_ip)); | 96 sizeof(get_local_ip)); |
80 if (rc == 0 && address_family == AF_INET6) { | 97 if (rc == 0 && address_family == AF_INET6) { |
81 rc = setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &get_local_ip, | 98 rc = setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &get_local_ip, |
82 sizeof(get_local_ip)); | 99 sizeof(get_local_ip)); |
83 } | 100 } |
84 return rc; | 101 return rc; |
85 } | 102 } |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 rc = SetGetSoftwareReceiveTimestamp(fd); | 311 rc = SetGetSoftwareReceiveTimestamp(fd); |
295 if (rc < 0) { | 312 if (rc < 0) { |
296 LOG(WARNING) << "SO_TIMESTAMPING not supported; using fallback: " | 313 LOG(WARNING) << "SO_TIMESTAMPING not supported; using fallback: " |
297 << strerror(errno); | 314 << strerror(errno); |
298 } | 315 } |
299 | 316 |
300 return fd; | 317 return fd; |
301 } | 318 } |
302 | 319 |
303 } // namespace net | 320 } // namespace net |
OLD | NEW |