mldonkey-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Mldonkey-commits] Changes to mldonkey/src/utils/net/ip.ml


From: mldonkey-commits
Subject: [Mldonkey-commits] Changes to mldonkey/src/utils/net/ip.ml
Date: Wed, 06 Jul 2005 20:25:55 -0400

Index: mldonkey/src/utils/net/ip.ml
diff -u mldonkey/src/utils/net/ip.ml:1.8 mldonkey/src/utils/net/ip.ml:1.9
--- mldonkey/src/utils/net/ip.ml:1.8    Mon Nov  1 11:23:02 2004
+++ mldonkey/src/utils/net/ip.ml        Thu Jul  7 00:25:46 2005
@@ -23,12 +23,12 @@
 external of_string : string -> t  = "ml_ints_of_string"
 
 let allow_local_network = ref false
-  
-let of_inet_addr t = 
+
+let of_inet_addr t =
   of_string (Unix.string_of_inet_addr t)
-  
+
 let any = of_inet_addr Unix.inet_addr_any
-  
+
 let null = (0,0,0,0)
 
 let of_ints t = t
@@ -45,7 +45,7 @@
 let to_fixed_string ((a4, a3, a2, a1) as t)=
   try
     Hashtbl.find hostname_table t
-  with _ -> 
+  with _ ->
       Printf.sprintf "%03d.%03d.%03d.%03d" a4 a3 a2 a1
 
 let to_int64  ((a4, a3, a2, a1) as t) =
@@ -53,7 +53,7 @@
   Int64.add (Int64.of_int small) (Int64.shift_left (Int64.of_int a4) 24)
 
 let const_int32_255 = Int64.of_int 255
-  
+
 let of_int64 i =
   let a4 = Int64.to_int (Int64.logand (Int64.shift_right i 24) const_int32_255)
   in
@@ -64,7 +64,7 @@
   let a1 = Int64.to_int (Int64.logand i const_int32_255)
   in
   (a4, a3, a2, a1)
-  
+
 let resolve_one t =
   try
     Hashtbl.find hostname_table t
@@ -80,21 +80,21 @@
       end;
       to_fixed_string t
 
-let valid (j,k,l,i) = 
-  j > 0 && j < 224 && 
-  k >= 0 && k <= 255 && 
+let valid (j,k,l,i) =
+  j > 0 && j < 224 &&
+  k >= 0 && k <= 255 &&
   l >= 0 && l <= 255 &&
   i >= 0 && i <= 255
-  
-let reachable ip = 
+
+let reachable ip =
   !allow_local_network ||
   match ip with
     192, 168,_,_ -> false
   | 10, _, _, _ | 127, _,_,_ -> false
   | 172, v, _, _ when v > 15 && v < 32 -> false
   | _ -> true
-  
-  
+
+
 let rec matches ((a4,a3,a2,a1) as a) ips =
   match ips with
     [] -> false
@@ -104,7 +104,7 @@
         (a2 = b2 || b2 = 255) &&
         (a1 = b1 || b1 = 255))
       || (matches a tail)
-      
+
 let compare ((a4,a3,a2,a1) as a) ((b4,b3,b2,b1) as b) =
   let c4 = compare a4 b4 in
   if c4 <> 0 then c4 else
@@ -115,7 +115,7 @@
   compare a1 b1
 
 let localhost = of_string "127.0.0.1"
-  
+
 let to_sockaddr ip port =
   Unix.ADDR_INET (to_inet_addr ip, port)
 
@@ -130,12 +130,15 @@
         else ip
   in
   try iter list
-  with _ -> match list with [] -> raise Not_found  | ip :: _ -> of_inet_addr ip
-    
+  with _ ->
+      match list with
+        [] -> raise Not_found
+      | ip :: _ -> of_inet_addr ip
+
 let gethostbyname name = 
   let h = Unix.gethostbyname name in
   let list = Array.to_list h.Unix.h_addr_list in
-  get_non_local_ip list        
+  get_non_local_ip list
 
 let ip_cache = Hashtbl.create 13
 let resolve_name name =
@@ -151,17 +154,17 @@
       with _ -> ip
     else ip
   with _ ->
-      lprintf "Resolving [%s] ..." name;
+      lprintf "[NS]: Resolving [%s] ..." name;
       let ip = gethostbyname name in
-      lprintf "done\n";
+      lprintf "[NS]: done\n";
       Hashtbl.add ip_cache name (ip, current_time +. 3600.);
       ip
-      
+
 
 let from_name name =
   try
-    if String.length name > 0 && name.[0] >= '0' && name.[0] <= '9' then 
-      of_string name 
+    if String.length name > 0 && name.[0] >= '0' && name.[0] <= '9' then
+      of_string name
     else
       raise Not_found
   with _ ->
@@ -170,9 +173,9 @@
         let ip = resolve_name name in
 (*        lprintf "..name resolved\n";  *)
         ip
-      with _ -> 
+      with _ ->
           raise Not_found
-          
+
 let my () =
   try
     let name = Unix.gethostname () in
@@ -184,16 +187,16 @@
         else
           localhost
   with _ -> localhost
-      
+
 
 open Options
-        
+
     let value_to_ip v = of_string (value_to_string v)
       
     let ip_to_value ip = string_to_value (to_string ip)
-      
-let option = define_option_class "Ip" value_to_ip ip_to_value      
-  
+
+let option = define_option_class "Ip" value_to_ip ip_to_value
+
 let rev (a1,a2,a3,a4) = (a4,a3,a2,a1)
 
 let equal a b = 
@@ -208,13 +211,13 @@
     handler : (t -> unit);
   }
 
-  
+
 external job_done : job -> bool = "ml_ip_job_done"
 external job_start : job -> unit = "ml_ip_job_start"
-  
+
 let current_job = ref None
 let ip_fifo = Fifo.create ()
-  
+
 let async_ip name f =
   try
 (*    lprintf "async_ip [%s]\n" name; *)
@@ -227,14 +230,14 @@
       (try f ip with _ -> ())
     with _ ->
         Fifo.put ip_fifo (name, f)
-        
+
 (* We check for names every 1/10 second. Too long ? *)
-let _ = 
+let _ =
   BasicSocket.add_infinite_timer 0.1 (fun _ ->
       let current_time = Unix.gettimeofday () in
       while true do
         match !current_job with
-          None -> 
+          None ->
             let (name, f) = Fifo.take ip_fifo in
             (try
                 let (ip, time) = Hashtbl.find ip_cache name in
@@ -246,20 +249,20 @@
               with _ ->
 (*                  lprintf "resolving name...\n"; *)
                   if !BasicSocket.use_threads && 
-                    BasicSocket.has_threads () then    
+                    BasicSocket.has_threads () then
                     let job = {
                         handler = f;
                         name = name;
                         entries = [||];
                         error = false;
                       }
-                    in 
+                    in
                     current_job := Some job;
                     job_start job
                   else begin
 (*                      lprintf "from_name ...\n"; *)
                       f (from_name name)
-                      
+
                     end
             )
         | Some job ->
@@ -292,7 +295,7 @@
 
 let addr_of_string s =
   try AddrIp (of_string s) with _ -> AddrName s
-      
+
 let addr_of_ip ip = AddrIp ip
 let ip_of_addr addr =
   match addr with
@@ -303,10 +306,10 @@
   match addr with
     AddrIp ip -> f ip
   | AddrName name -> async_ip name f
-      
-              
+
+
 let value_to_addr v = addr_of_string (value_to_string v)
-  
+
 let addr_to_value ip = string_to_value (string_of_addr ip)
-      
-let addr_option = define_option_class "Addr" value_to_addr addr_to_value      
+
+let addr_option = define_option_class "Addr" value_to_addr addr_to_value




reply via email to

[Prev in Thread] Current Thread [Next in Thread]