| 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 <netinet/in.h> | 8 #include <netinet/in.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| 11 #include <sys/uio.h> | 11 #include <sys/uio.h> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/logging.h" | 14 #include "base/logging.h" |
| 16 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
| 17 | 16 |
| 18 #ifndef SO_RXQ_OVFL | 17 #ifndef SO_RXQ_OVFL |
| 19 #define SO_RXQ_OVFL 40 | 18 #define SO_RXQ_OVFL 40 |
| 20 #endif | 19 #endif |
| 21 | 20 |
| 22 namespace net { | 21 namespace net { |
| 23 namespace tools { | 22 namespace tools { |
| 24 | 23 |
| 25 // static | 24 // static |
| 26 IPAddressNumber QuicSocketUtils::GetAddressFromMsghdr(struct msghdr* hdr) { | 25 IPAddressNumber QuicSocketUtils::GetAddressFromMsghdr(struct msghdr* hdr) { |
| 27 if (hdr->msg_controllen > 0) { | 26 if (hdr->msg_controllen > 0) { |
| 28 for (cmsghdr* cmsg = CMSG_FIRSTHDR(hdr); cmsg != nullptr; | 27 for (cmsghdr* cmsg = CMSG_FIRSTHDR(hdr); cmsg != nullptr; |
| 29 cmsg = CMSG_NXTHDR(hdr, cmsg)) { | 28 cmsg = CMSG_NXTHDR(hdr, cmsg)) { |
| 30 const uint8* addr_data = nullptr; | 29 const uint8_t* addr_data = nullptr; |
| 31 int len = 0; | 30 int len = 0; |
| 32 if (cmsg->cmsg_type == IPV6_PKTINFO) { | 31 if (cmsg->cmsg_type == IPV6_PKTINFO) { |
| 33 in6_pktinfo* info = reinterpret_cast<in6_pktinfo*> CMSG_DATA(cmsg); | 32 in6_pktinfo* info = reinterpret_cast<in6_pktinfo*> CMSG_DATA(cmsg); |
| 34 addr_data = reinterpret_cast<const uint8*>(&info->ipi6_addr); | 33 addr_data = reinterpret_cast<const uint8_t*>(&info->ipi6_addr); |
| 35 len = sizeof(in6_addr); | 34 len = sizeof(in6_addr); |
| 36 } else if (cmsg->cmsg_type == IP_PKTINFO) { | 35 } else if (cmsg->cmsg_type == IP_PKTINFO) { |
| 37 in_pktinfo* info = reinterpret_cast<in_pktinfo*> CMSG_DATA(cmsg); | 36 in_pktinfo* info = reinterpret_cast<in_pktinfo*> CMSG_DATA(cmsg); |
| 38 addr_data = reinterpret_cast<const uint8*>(&info->ipi_addr); | 37 addr_data = reinterpret_cast<const uint8_t*>(&info->ipi_addr); |
| 39 len = sizeof(in_addr); | 38 len = sizeof(in_addr); |
| 40 } else { | 39 } else { |
| 41 continue; | 40 continue; |
| 42 } | 41 } |
| 43 return IPAddressNumber(addr_data, addr_data + len); | 42 return IPAddressNumber(addr_data, addr_data + len); |
| 44 } | 43 } |
| 45 } | 44 } |
| 46 DCHECK(false) << "Unable to get address from msghdr"; | 45 DCHECK(false) << "Unable to get address from msghdr"; |
| 47 return IPAddressNumber(); | 46 return IPAddressNumber(); |
| 48 } | 47 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 return WriteResult(WRITE_STATUS_OK, rc); | 214 return WriteResult(WRITE_STATUS_OK, rc); |
| 216 } | 215 } |
| 217 return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) | 216 return WriteResult((errno == EAGAIN || errno == EWOULDBLOCK) |
| 218 ? WRITE_STATUS_BLOCKED | 217 ? WRITE_STATUS_BLOCKED |
| 219 : WRITE_STATUS_ERROR, | 218 : WRITE_STATUS_ERROR, |
| 220 errno); | 219 errno); |
| 221 } | 220 } |
| 222 | 221 |
| 223 } // namespace tools | 222 } // namespace tools |
| 224 } // namespace net | 223 } // namespace net |
| OLD | NEW |