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 "tools/android/forwarder2/socket.h" | 5 #include "tools/android/forwarder2/socket.h" |
6 | 6 |
7 #include <arpa/inet.h> | 7 #include <arpa/inet.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <netdb.h> | 10 #include <netdb.h> |
11 #include <netinet/in.h> | 11 #include <netinet/in.h> |
| 12 #include <stdint.h> |
12 #include <stdio.h> | 13 #include <stdio.h> |
13 #include <string.h> | 14 #include <string.h> |
14 #include <sys/socket.h> | 15 #include <sys/socket.h> |
15 #include <sys/types.h> | 16 #include <sys/types.h> |
16 #include <unistd.h> | 17 #include <unistd.h> |
17 | 18 |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/posix/eintr_wrapper.h" | 20 #include "base/posix/eintr_wrapper.h" |
20 #include "base/posix/safe_strerror.h" | 21 #include "base/posix/safe_strerror.h" |
21 #include "tools/android/common/net.h" | 22 #include "tools/android/common/net.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 HANDLE_EINTR(listen(socket_, SOMAXCONN)) < 0) { | 177 HANDLE_EINTR(listen(socket_, SOMAXCONN)) < 0) { |
177 PLOG(ERROR) << "bind/listen"; | 178 PLOG(ERROR) << "bind/listen"; |
178 SetSocketError(); | 179 SetSocketError(); |
179 return false; | 180 return false; |
180 } | 181 } |
181 if (port_ == 0 && FamilyIsTCP(family_)) { | 182 if (port_ == 0 && FamilyIsTCP(family_)) { |
182 SockAddr addr; | 183 SockAddr addr; |
183 memset(&addr, 0, sizeof(addr)); | 184 memset(&addr, 0, sizeof(addr)); |
184 socklen_t addrlen = 0; | 185 socklen_t addrlen = 0; |
185 sockaddr* addr_ptr = NULL; | 186 sockaddr* addr_ptr = NULL; |
186 uint16* port_ptr = NULL; | 187 uint16_t* port_ptr = NULL; |
187 if (family_ == AF_INET) { | 188 if (family_ == AF_INET) { |
188 addr_ptr = reinterpret_cast<sockaddr*>(&addr.addr4); | 189 addr_ptr = reinterpret_cast<sockaddr*>(&addr.addr4); |
189 port_ptr = &addr.addr4.sin_port; | 190 port_ptr = &addr.addr4.sin_port; |
190 addrlen = sizeof(addr.addr4); | 191 addrlen = sizeof(addr.addr4); |
191 } else if (family_ == AF_INET6) { | 192 } else if (family_ == AF_INET6) { |
192 addr_ptr = reinterpret_cast<sockaddr*>(&addr.addr6); | 193 addr_ptr = reinterpret_cast<sockaddr*>(&addr.addr6); |
193 port_ptr = &addr.addr6.sin6_port; | 194 port_ptr = &addr.addr6.sin6_port; |
194 addrlen = sizeof(addr.addr6); | 195 addrlen = sizeof(addr.addr6); |
195 } | 196 } |
196 errno = 0; | 197 errno = 0; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 ucred ucred; | 442 ucred ucred; |
442 socklen_t len = sizeof(ucred); | 443 socklen_t len = sizeof(ucred); |
443 if (getsockopt(socket.socket_, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1) { | 444 if (getsockopt(socket.socket_, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1) { |
444 CHECK_NE(ENOPROTOOPT, errno); | 445 CHECK_NE(ENOPROTOOPT, errno); |
445 return -1; | 446 return -1; |
446 } | 447 } |
447 return ucred.pid; | 448 return ucred.pid; |
448 } | 449 } |
449 | 450 |
450 } // namespace forwarder2 | 451 } // namespace forwarder2 |
OLD | NEW |