| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include <arpa/inet.h> | 5 #include <arpa/inet.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <netdb.h> | 7 #include <netdb.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 getsockname(fd, | 95 getsockname(fd, |
| 96 reinterpret_cast<struct sockaddr *>(&socket_address), | 96 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 97 &size))) { | 97 &size))) { |
| 98 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); | 98 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); |
| 99 return 0; | 99 return 0; |
| 100 } | 100 } |
| 101 return ntohs(socket_address.sin_port); | 101 return ntohs(socket_address.sin_port); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 intptr_t Socket::GetRemotePort(intptr_t fd) { | 105 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { |
| 106 ASSERT(DART_INET_ADDRSTRLEN >= INET_ADDRSTRLEN); |
| 106 ASSERT(fd >= 0); | 107 ASSERT(fd >= 0); |
| 107 struct sockaddr_in socket_address; | 108 struct sockaddr_in socket_address; |
| 108 socklen_t size = sizeof(socket_address); | 109 socklen_t size = sizeof(socket_address); |
| 109 if (TEMP_FAILURE_RETRY( | 110 if (TEMP_FAILURE_RETRY( |
| 110 getpeername(fd, | 111 getpeername(fd, |
| 111 reinterpret_cast<struct sockaddr *>(&socket_address), | 112 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 112 &size))) { | 113 &size))) { |
| 113 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); | 114 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); |
| 114 return 0; | 115 return false; |
| 115 } | 116 } |
| 116 return ntohs(socket_address.sin_port); | 117 if (inet_ntop(socket_address.sin_family, |
| 118 reinterpret_cast<const void *>(&socket_address.sin_addr), |
| 119 host, |
| 120 INET_ADDRSTRLEN) == NULL) { |
| 121 fprintf(stderr, "Error inet_ntop: %s\n", strerror(errno)); |
| 122 return false; |
| 123 } |
| 124 *port = ntohs(socket_address.sin_port); |
| 125 return true; |
| 117 } | 126 } |
| 118 | 127 |
| 119 | 128 |
| 120 void Socket::GetError(intptr_t fd, OSError* os_error) { | 129 void Socket::GetError(intptr_t fd, OSError* os_error) { |
| 121 int len = sizeof(errno); | 130 int len = sizeof(errno); |
| 122 getsockopt(fd, | 131 getsockopt(fd, |
| 123 SOL_SOCKET, | 132 SOL_SOCKET, |
| 124 SO_ERROR, | 133 SO_ERROR, |
| 125 &errno, | 134 &errno, |
| 126 reinterpret_cast<socklen_t*>(&len)); | 135 reinterpret_cast<socklen_t*>(&len)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // error. We got woken up from the poll on the listening socket, | 225 // error. We got woken up from the poll on the listening socket, |
| 217 // but there is no connection ready to be accepted. | 226 // but there is no connection ready to be accepted. |
| 218 ASSERT(kTemporaryFailure != -1); | 227 ASSERT(kTemporaryFailure != -1); |
| 219 socket = kTemporaryFailure; | 228 socket = kTemporaryFailure; |
| 220 } | 229 } |
| 221 } else { | 230 } else { |
| 222 FDUtils::SetNonBlocking(socket); | 231 FDUtils::SetNonBlocking(socket); |
| 223 } | 232 } |
| 224 return socket; | 233 return socket; |
| 225 } | 234 } |
| OLD | NEW |