Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: runtime/bin/socket_patch.dart

Issue 17640008: Add reverse dns lookup as a method on InternetAddress. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 patch class RawServerSocket { 5 patch class RawServerSocket {
6 /* patch */ static Future<RawServerSocket> bind(address, 6 /* patch */ static Future<RawServerSocket> bind(address,
7 int port, 7 int port,
8 {int backlog: 0, 8 {int backlog: 0,
9 bool v6Only: false}) { 9 bool v6Only: false}) {
10 return _RawServerSocket.bind(address, port, backlog, v6Only); 10 return _RawServerSocket.bind(address, port, backlog, v6Only);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return _sockaddr_storage[_IPV4_ADDR_OFFSET] == 169 && 97 return _sockaddr_storage[_IPV4_ADDR_OFFSET] == 169 &&
98 _sockaddr_storage[_IPV4_ADDR_OFFSET + 1] == 254; 98 _sockaddr_storage[_IPV4_ADDR_OFFSET + 1] == 254;
99 99
100 case InternetAddressType.IP_V6: 100 case InternetAddressType.IP_V6:
101 // Checking for fe80::/10. 101 // Checking for fe80::/10.
102 return _sockaddr_storage[_IPV6_ADDR_OFFSET] == 0xFE && 102 return _sockaddr_storage[_IPV6_ADDR_OFFSET] == 0xFE &&
103 (_sockaddr_storage[_IPV6_ADDR_OFFSET + 1] & 0xB0) == 0x80; 103 (_sockaddr_storage[_IPV6_ADDR_OFFSET + 1] & 0xB0) == 0x80;
104 } 104 }
105 } 105 }
106 106
107 Future<InternetAddress> reverse() => _NativeSocket.reverseLookup(this);
108
107 _InternetAddress(InternetAddressType this.type, 109 _InternetAddress(InternetAddressType this.type,
108 String this.address, 110 String this.address,
109 String this.host, 111 String this.host,
110 List<int> this._sockaddr_storage); 112 List<int> this._sockaddr_storage);
111 113
112 factory _InternetAddress.fixed(int id) { 114 factory _InternetAddress.fixed(int id) {
113 var sockaddr = _fixed(id); 115 var sockaddr = _fixed(id);
114 switch (id) { 116 switch (id) {
115 case _ADDRESS_LOOPBACK_IP_V4: 117 case _ADDRESS_LOOPBACK_IP_V4:
116 return new _InternetAddress( 118 return new _InternetAddress(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // information on the type of the file descriptor. 186 // information on the type of the file descriptor.
185 static const int LISTENING_SOCKET = 16; 187 static const int LISTENING_SOCKET = 16;
186 static const int PIPE_SOCKET = 17; 188 static const int PIPE_SOCKET = 17;
187 static const int TYPE_NORMAL_SOCKET = 0; 189 static const int TYPE_NORMAL_SOCKET = 0;
188 static const int TYPE_LISTENING_SOCKET = 1 << LISTENING_SOCKET; 190 static const int TYPE_LISTENING_SOCKET = 1 << LISTENING_SOCKET;
189 static const int TYPE_PIPE = 1 << PIPE_SOCKET; 191 static const int TYPE_PIPE = 1 << PIPE_SOCKET;
190 192
191 // Native port messages. 193 // Native port messages.
192 static const HOST_NAME_LOOKUP = 0; 194 static const HOST_NAME_LOOKUP = 0;
193 static const LIST_INTERFACES = 1; 195 static const LIST_INTERFACES = 1;
196 static const REVERSE_LOOKUP = 2;
194 197
195 // Socket close state 198 // Socket close state
196 bool isClosed = false; 199 bool isClosed = false;
197 bool isClosedRead = false; 200 bool isClosedRead = false;
198 bool isClosedWrite = false; 201 bool isClosedWrite = false;
199 Completer closeCompleter = new Completer(); 202 Completer closeCompleter = new Completer();
200 203
201 // Handlers and receive port for socket events from the event handler. 204 // Handlers and receive port for socket events from the event handler.
202 int eventMask = 0; 205 int eventMask = 0;
203 List eventHandlers; 206 List eventHandlers;
(...skipping 23 matching lines...) Expand all
227 throw createError(response, "Failed host name lookup"); 230 throw createError(response, "Failed host name lookup");
228 } else { 231 } else {
229 return response.skip(1).map((result) { 232 return response.skip(1).map((result) {
230 var type = new InternetAddressType._from(result[0]); 233 var type = new InternetAddressType._from(result[0]);
231 return new _InternetAddress(type, result[1], host, result[2]); 234 return new _InternetAddress(type, result[1], host, result[2]);
232 }).toList(); 235 }).toList();
233 } 236 }
234 }); 237 });
235 } 238 }
236 239
240 static Future<InternetAddress> reverseLookup(InternetAddress addr) {
241 ensureSocketService();
242 return socketService.call([REVERSE_LOOKUP, addr._sockaddr_storage])
243 .then((response) {
244 if (isErrorResponse(response)) {
245 throw createError(response, "Failed host name lookup");
246 } else {
247 return addr._cloneWithNewHost(response);
248 }
249 });
250 }
251
237 static Future<List<NetworkInterface>> listInterfaces({ 252 static Future<List<NetworkInterface>> listInterfaces({
238 bool includeLoopback: false, 253 bool includeLoopback: false,
239 bool includeLinkLocal: false, 254 bool includeLinkLocal: false,
240 InternetAddressType type: InternetAddressType.ANY}) { 255 InternetAddressType type: InternetAddressType.ANY}) {
241 ensureSocketService(); 256 ensureSocketService();
242 return socketService.call([LIST_INTERFACES, type._value]) 257 return socketService.call([LIST_INTERFACES, type._value])
243 .then((response) { 258 .then((response) {
244 if (isErrorResponse(response)) { 259 if (isErrorResponse(response)) {
245 throw createError(response, "Failed listing interfaces"); 260 throw createError(response, "Failed listing interfaces");
246 } else { 261 } else {
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 if (_detachReady != null) { 1171 if (_detachReady != null) {
1157 _detachReady.complete(null); 1172 _detachReady.complete(null);
1158 } else { 1173 } else {
1159 if (_raw != null) { 1174 if (_raw != null) {
1160 _raw.shutdown(SocketDirection.SEND); 1175 _raw.shutdown(SocketDirection.SEND);
1161 _disableWriteEvent(); 1176 _disableWriteEvent();
1162 } 1177 }
1163 } 1178 }
1164 } 1179 }
1165 } 1180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698