English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] The Makefile
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-03-02 (09:59)
From: Olivier_Pérès <olivier.peres@l...>
Subject: Re: [Caml-list] use of abstract type "inet_addr"
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 =
	(* if the user gave an IP address, use it *)
	inet_addr_of_string s
     with Failure _ ->
	    (* 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
	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