| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #ifndef BIN_SOCKET_H_ | 5 #ifndef BIN_SOCKET_H_ |
| 6 #define BIN_SOCKET_H_ | 6 #define BIN_SOCKET_H_ |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 static int16_t FromType(int type) { | 49 static int16_t FromType(int type) { |
| 50 if (type == TYPE_ANY) return AF_UNSPEC; | 50 if (type == TYPE_ANY) return AF_UNSPEC; |
| 51 if (type == TYPE_IPV4) return AF_INET; | 51 if (type == TYPE_IPV4) return AF_INET; |
| 52 ASSERT(type == TYPE_IPV6 && "Invalid type"); | 52 ASSERT(type == TYPE_IPV6 && "Invalid type"); |
| 53 return AF_INET6; | 53 return AF_INET6; |
| 54 } | 54 } |
| 55 | 55 |
| 56 static void SetAddrPort(struct sockaddr_storage* addr, intptr_t port) { | 56 static void SetAddrPort(struct sockaddr_storage* addr, intptr_t port) { |
| 57 sock_addr_ *sock_addr = reinterpret_cast<sock_addr_*>(addr); |
| 57 if (addr->ss_family == AF_INET) { | 58 if (addr->ss_family == AF_INET) { |
| 58 GetAsSockAddrIn(GetAsSockAddr(addr))->sin_port = htons(port); | 59 sock_addr->in.sin_port = htons(port); |
| 59 } else { | 60 } else { |
| 60 GetAsSockAddrIn6(GetAsSockAddr(addr))->sin6_port = htons(port); | 61 sock_addr->in6.sin6_port = htons(port); |
| 61 } | 62 } |
| 62 } | 63 } |
| 63 | 64 |
| 64 static intptr_t GetAddrPort(struct sockaddr_storage* addr) { | 65 static intptr_t GetAddrPort(struct sockaddr_storage* addr) { |
| 66 sock_addr_ *sock_addr = reinterpret_cast<sock_addr_*>(addr); |
| 65 if (addr->ss_family == AF_INET) { | 67 if (addr->ss_family == AF_INET) { |
| 66 return ntohs(GetAsSockAddrIn(GetAsSockAddr(addr))->sin_port); | 68 return ntohs(sock_addr->in.sin_port); |
| 67 } else { | 69 } else { |
| 68 return ntohs(GetAsSockAddrIn6(GetAsSockAddr(addr))->sin6_port); | 70 return ntohs(sock_addr->in6.sin6_port); |
| 69 } | 71 } |
| 70 } | 72 } |
| 71 | 73 |
| 72 static struct sockaddr* GetAsSockAddr(struct sockaddr_storage* addr) { | 74 static struct sockaddr* GetAsSockAddr(struct sockaddr_storage* addr) { |
| 73 uint8_t* data = reinterpret_cast<uint8_t*>(addr); | 75 sock_addr_ *sock_addr = reinterpret_cast<sock_addr_*>(addr); |
| 74 return reinterpret_cast<struct sockaddr*>(data); | 76 return reinterpret_cast<sockaddr*>(sock_addr); |
| 75 } | 77 } |
| 76 | 78 |
| 77 static struct sockaddr_in* GetAsSockAddrIn(struct sockaddr* addr) { | 79 static struct sockaddr_in* GetAsSockAddrIn(struct sockaddr* addr) { |
| 78 uint8_t* data = reinterpret_cast<uint8_t*>(addr); | 80 sock_addr_ *sock_addr = reinterpret_cast<sock_addr_*>(addr); |
| 79 return reinterpret_cast<struct sockaddr_in*>(data); | 81 return reinterpret_cast<sockaddr_in*>(sock_addr); |
| 80 } | 82 } |
| 81 | 83 |
| 82 static struct sockaddr_in6* GetAsSockAddrIn6(struct sockaddr* addr) { | 84 static struct sockaddr_in6* GetAsSockAddrIn6(struct sockaddr* addr) { |
| 83 uint8_t* data = reinterpret_cast<uint8_t*>(addr); | 85 sock_addr_ *sock_addr = reinterpret_cast<sock_addr_*>(addr); |
| 84 return reinterpret_cast<struct sockaddr_in6*>(data); | 86 return reinterpret_cast<sockaddr_in6*>(sock_addr); |
| 85 } | 87 } |
| 86 | 88 |
| 87 private: | 89 private: |
| 88 union sock_addr_ { | 90 union sock_addr_ { |
| 89 struct sockaddr_storage* storage; | 91 struct sockaddr_storage storage; |
| 90 struct sockaddr_in* in; | 92 struct sockaddr_in in; |
| 91 struct sockaddr_in6* in6; | 93 struct sockaddr_in6 in6; |
| 92 struct sockaddr* addr; | 94 struct sockaddr addr; |
| 95 char raw[sizeof(sockaddr_storage)]; |
| 93 }; | 96 }; |
| 94 | 97 |
| 95 char as_string_[INET6_ADDRSTRLEN]; | 98 char as_string_[INET6_ADDRSTRLEN]; |
| 96 sockaddr_storage addr_; | 99 sockaddr_storage addr_; |
| 97 | 100 |
| 98 DISALLOW_COPY_AND_ASSIGN(SocketAddress); | 101 DISALLOW_COPY_AND_ASSIGN(SocketAddress); |
| 99 }; | 102 }; |
| 100 | 103 |
| 101 class SocketAddresses { | 104 class SocketAddresses { |
| 102 public: | 105 public: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // -5: invalid bindAddress | 181 // -5: invalid bindAddress |
| 179 static intptr_t CreateBindListen(sockaddr_storage addr, | 182 static intptr_t CreateBindListen(sockaddr_storage addr, |
| 180 intptr_t port, | 183 intptr_t port, |
| 181 intptr_t backlog); | 184 intptr_t backlog); |
| 182 | 185 |
| 183 DISALLOW_ALLOCATION(); | 186 DISALLOW_ALLOCATION(); |
| 184 DISALLOW_IMPLICIT_CONSTRUCTORS(ServerSocket); | 187 DISALLOW_IMPLICIT_CONSTRUCTORS(ServerSocket); |
| 185 }; | 188 }; |
| 186 | 189 |
| 187 #endif // BIN_SOCKET_H_ | 190 #endif // BIN_SOCKET_H_ |
| OLD | NEW |