| 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 <winsock2.h> | 5 #include <winsock2.h> |
| 6 #include <ws2tcpip.h> | 6 #include <ws2tcpip.h> |
| 7 #include <mswsock.h> | 7 #include <mswsock.h> |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/eventhandler.h" | 10 #include "bin/eventhandler.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 if (getsockname(socket_handle->socket(), | 47 if (getsockname(socket_handle->socket(), |
| 48 reinterpret_cast<struct sockaddr *>(&socket_address), | 48 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 49 &size)) { | 49 &size)) { |
| 50 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); | 50 fprintf(stderr, "Error getsockname: %s\n", strerror(errno)); |
| 51 return 0; | 51 return 0; |
| 52 } | 52 } |
| 53 return ntohs(socket_address.sin_port); | 53 return ntohs(socket_address.sin_port); |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 intptr_t Socket::GetRemotePort(intptr_t fd) { | 57 bool Socket::GetRemotePeer(intptr_t fd, char *host, intptr_t *port) { |
| 58 ASSERT(DART_INET_ADDRSTRLEN >= INET_ADDRSTRLEN); |
| 58 ASSERT(reinterpret_cast<Handle*>(fd)->is_socket()); | 59 ASSERT(reinterpret_cast<Handle*>(fd)->is_socket()); |
| 59 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); | 60 SocketHandle* socket_handle = reinterpret_cast<SocketHandle*>(fd); |
| 60 struct sockaddr_in socket_address; | 61 struct sockaddr_in socket_address; |
| 61 socklen_t size = sizeof(socket_address); | 62 socklen_t size = sizeof(socket_address); |
| 62 if (getpeername(socket_handle->socket(), | 63 if (getpeername(socket_handle->socket(), |
| 63 reinterpret_cast<struct sockaddr *>(&socket_address), | 64 reinterpret_cast<struct sockaddr *>(&socket_address), |
| 64 &size)) { | 65 &size)) { |
| 65 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); | 66 fprintf(stderr, "Error getpeername: %s\n", strerror(errno)); |
| 66 return 0; | 67 return false; |
| 67 } | 68 } |
| 68 return ntohs(socket_address.sin_port); | 69 if (inet_ntop(socket_address.sin_family, |
| 69 } | 70 reinterpret_cast<const void *>(&socket_address.sin_addr), |
| 71 host, |
| 72 INET_ADDRSTRLEN) == NULL) { |
| 73 fprintf(stderr, "Error inet_ntop: %s\n", strerror(errno)); |
| 74 return false; |
| 75 } |
| 76 *port = ntohs(socket_address.sin_port); |
| 77 return true; |
| 70 | 78 |
| 71 | 79 |
| 72 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { | 80 intptr_t Socket::CreateConnect(const char* host, const intptr_t port) { |
| 73 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); | 81 SOCKET s = socket(AF_INET, SOCK_STREAM, 0); |
| 74 if (s == INVALID_SOCKET) { | 82 if (s == INVALID_SOCKET) { |
| 75 return -1; | 83 return -1; |
| 76 } | 84 } |
| 77 | 85 |
| 78 linger l; | 86 linger l; |
| 79 l.l_onoff = 1; | 87 l.l_onoff = 1; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (status == SOCKET_ERROR) { | 243 if (status == SOCKET_ERROR) { |
| 236 DWORD rc = WSAGetLastError(); | 244 DWORD rc = WSAGetLastError(); |
| 237 closesocket(s); | 245 closesocket(s); |
| 238 SetLastError(rc); | 246 SetLastError(rc); |
| 239 return -1; | 247 return -1; |
| 240 } | 248 } |
| 241 | 249 |
| 242 ListenSocket* listen_socket = new ListenSocket(s); | 250 ListenSocket* listen_socket = new ListenSocket(s); |
| 243 return reinterpret_cast<intptr_t>(listen_socket); | 251 return reinterpret_cast<intptr_t>(listen_socket); |
| 244 } | 252 } |
| OLD | NEW |