Переглянути джерело

[cpp]Some initial work on ipv6

Hugh 8 роки тому
батько
коміт
27f68af6a8
2 змінених файлів з 16 додано та 3 видалено
  1. 9 0
      std/cpp/NativeSocket.hx
  2. 7 3
      std/cpp/_std/sys/net/Host.hx

+ 9 - 0
std/cpp/NativeSocket.hx

@@ -44,6 +44,9 @@ extern class NativeSocket
    @:extern @:native("_hx_std_socket_read")
    public static function socket_read(o:Dynamic) : haxe.io.BytesData return null;
 
+   @:extern @:native("_hx_std_host_resolve_ipv6")
+   public static function host_resolve_ipv6(host:String,onlyIfNoIpv4:Bool) : haxe.io.BytesData return null;
+
 
    @:extern @:native("_hx_std_host_resolve")
    public static function host_resolve(host:String) : Int return 0;
@@ -52,10 +55,16 @@ extern class NativeSocket
    @:extern @:native("_hx_std_host_to_string")
    public static function host_to_string(ip:Int) : String return null;
 
+   @:extern @:native("_hx_std_host_to_string_ipv6")
+   public static function host_to_string_ipv6(ipv6:haxe.io.BytesData) : String return null;
+
 
    @:extern @:native("_hx_std_host_reverse")
    public static function host_reverse(host:Int) : String return null;
 
+   @:extern @:native("_hx_std_host_reverse_ipv6")
+   public static function host_reverse_ipv6(ipv6:haxe.io.BytesData) : String return null;
+
 
    @:extern @:native("_hx_std_host_local")
    public static function host_local() : String return null;

+ 7 - 3
std/cpp/_std/sys/net/Host.hx

@@ -30,17 +30,21 @@ class Host {
 
 	public var ip(default,null) : Int;
 
+   private var ipv6(default,null) : haxe.io.BytesData;
+
 	public function new( name : String ) : Void {
 		host = name;
-		ip = NativeSocket.host_resolve(name);
+		ipv6 = NativeSocket.host_resolve_ipv6(name,true);
+		if (ipv6==null)
+			ip = NativeSocket.host_resolve(name);
 	}
 
 	public function toString() : String {
-		return NativeSocket.host_to_string(ip);
+		return ipv6==null ? NativeSocket.host_to_string(ip) : NativeSocket.host_to_string_ipv6(ipv6);
 	}
 
 	public function reverse() : String {
-		return NativeSocket.host_reverse(ip);
+		return ipv6==null ? NativeSocket.host_reverse(ip) : NativeSocket.host_reverse_ipv6(ipv6);
 	}
 
 	public static function localhost() : String {