From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA03258; Tue, 2 Mar 2004 10:59:21 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA03023 for ; Tue, 2 Mar 2004 10:59:20 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from partridge.numericable.net (partridge.numericable.net [80.236.0.152]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i229xJae023425 for ; Tue, 2 Mar 2004 10:59:20 +0100 Received: (qmail 25195 invoked from network); 2 Mar 2004 09:59:19 -0000 Received: from unknown (HELO laposte.net) ([81.220.100.229]) (envelope-sender ) by partridge.numericable.net (qmail-ldap-1.03) with SMTP for ; 2 Mar 2004 09:59:19 -0000 Message-ID: <40445B4C.9040708@laposte.net> Date: Tue, 02 Mar 2004 11:00:44 +0100 From: =?ISO-8859-1?Q?Olivier_P=E9r=E8s?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040206 X-Accept-Language: br, fr-fr, fr, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] use of abstract type "inet_addr" References: <20040302010059.48823.qmail@web41208.mail.yahoo.com> In-Reply-To: <20040302010059.48823.qmail@web41208.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 suitably:01 high-level:01 low-level:01 sockaddr:01 waits:01 dotted:99 failwith:01 fetches:01 failwith:01 sockets:01 olivier:02 olivier:02 exception:02 address:96 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 18 Vasili Galchin wrote: > I want to use type "inet_addr" Here is some code I wrote for my fourth year project (due in June this year, it is still far from complete). Its purpose is to allow simple definition and parallel execution of processes, and it has to be suitably easy for teaching high-level parallel programming without losing time on low-level concerns. Those two functions -- translated to English -- are among those used to connect processes using sockets (the actual process is hidden from the user). The first one shows how to build an inet_address and the second one shows how to turn it into a sockaddr. They're a bit rough but work for now (not released yet). By the way, if someone could tell me why I don't get the Not_found exception when a host is not found (the program waits forever), I would appreciate it. (* this functions takes either an IPv4 dotted decimal address or a host name, and returns an inet_addr. *) let ia_of_string s = try (* if the user gave an IP address, use it *) inet_addr_of_string s with Failure _ -> try (* assume it is a host name and resolve it *) (gethostbyname (s)).h_addr_list.(0) with Not_found -> failwith ("Unknown host : "^s) (* this fetches a "network" (type provided by my library) that was set up on the given machine and the given port. *) let get_network machine port = (* build address machine:port *) (* Net_remote is a constructor for type network *) let net = Net_remote (ADDR_INET (ia_of_string machine, port)) in (* ping the network to check it is actually here *) (* net_ping is also provided by my library *) if net_ping net then net else failwith "Remote network unreachable" Olivier Pérès. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners