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

Unified Diff: runtime/bin/socket_patch.dart

Issue 76383002: Update InternetAddress (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review commetns Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_patch.dart
diff --git a/runtime/bin/socket_patch.dart b/runtime/bin/socket_patch.dart
index a4b9c83d35f4bcede943aab52551d58e6ad447b7..49fca7986e6744b6ae40c12f1a0c81357d327760 100644
--- a/runtime/bin/socket_patch.dart
+++ b/runtime/bin/socket_patch.dart
@@ -106,6 +106,19 @@ class _InternetAddress implements InternetAddress {
}
}
+ bool get isMulticast {
+ switch (type) {
+ case InternetAddressType.IP_V4:
+ // Checking for 224.0.0.0 through 239.255.255.255.
+ return _sockaddr_storage[_IPV4_ADDR_OFFSET] >= 224 &&
+ _sockaddr_storage[_IPV4_ADDR_OFFSET] < 240;
+
+ case InternetAddressType.IP_V6:
+ // Checking for ff00::/8.
+ return _sockaddr_storage[_IPV6_ADDR_OFFSET] == 0xFF;
+ }
+ }
+
Future<InternetAddress> reverse() => _NativeSocket.reverseLookup(this);
_InternetAddress(InternetAddressType this.type,
@@ -113,6 +126,17 @@ class _InternetAddress implements InternetAddress {
String this._host,
List<int> this._sockaddr_storage);
+ factory _InternetAddress.parse(String address) {
+ var type = address.indexOf(':') == -1
+ ? InternetAddressType.IP_V4
+ : InternetAddressType.IP_V6;
+ var raw = _parse(type._value, address);
+ if (raw == null) {
+ throw new ArgumentError("Invalid internet address $address");
+ }
+ return new _InternetAddress(type, address, null, raw);
+ }
+
factory _InternetAddress.fixed(int id) {
var sockaddr = _fixed(id);
switch (id) {
@@ -140,11 +164,31 @@ class _InternetAddress implements InternetAddress {
type, address, host, new Uint8List.fromList(_sockaddr_storage));
}
+ bool operator ==(other) {
+ if (!(other is _InternetAddress)) return false;
+ if (other.type != type) return false;
+ bool equals = true;
+ for (int i = 0; i < _sockaddr_storage.length && equals; i++) {
+ equals = other._sockaddr_storage[i] == _sockaddr_storage[i];
+ }
+ return equals;
+ }
+
+ int get hashCode {
+ int result = 1;
+ for (int i = 0; i < _sockaddr_storage.length; i++) {
+ result = (result * 31 + _sockaddr_storage[i]) & 0x3FFFFFFF;
+ }
+ return result;
+ }
+
String toString() {
return "InternetAddress('$address', ${type.name})";
}
static Uint8List _fixed(int id) native "InternetAddress_Fixed";
+ static Uint8List _parse(int type, String address)
+ native "InternetAddress_Parse";
}
class _NetworkInterface implements NetworkInterface {
« no previous file with comments | « runtime/bin/socket_macos.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698