Hi all,

I worked through the network example (page 629) of the the Ocaml book, and don't know what's going wrong with the last statement. I am using Ocaml under cygwin / WinXP.

I know, EINVAL means invalid argument, but as far as I read s_descr is used as an abstract file descriptor. Is this wrong?

 -----------------------------------------------------------------------------------------------------------------------------
let my_name = Unix.gethostname ();;
let my_entry_byname = Unix.gethostbyname my_name;;
let my_addr = my_entry_byname.Unix.h_addr_list.(0);;
let my_entry_byaddr = Unix.gethostbyaddr my_addr;;
let my_full_name = my_entry_byaddr.Unix.h_name;;
let s_descr = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0;;
let (addr_in, p_num) =
  match Unix.getsockname s_descr with
      Unix.ADDR_INET (a,n) -> (a,n)
    | _ -> failwith "not INET";;

# val my_entry_byname : Unix.host_entry =
  {Unix.h_name = "CNCHZUR2497"; Unix.h_aliases = [||];
   Unix.h_addrtype = Unix.PF_INET; Unix.h_addr_list = [|<abstr>; <abstr>|]}
# val my_addr : Unix.inet_addr = <abstr>
# val my_entry_byaddr : Unix.host_entry =
  {Unix.h_name = "CNCHZUR2497"; Unix.h_aliases = [||];
   Unix.h_addrtype = Unix.PF_INET; Unix.h_addr_list = [|<abstr>|]}
# val my_full_name : string = "CNCHZUR2497"
# val s_descr : Unix.file_descr = <abstr>
#       Exception: Unix.Unix_error (Unix.EINVAL, "getsockname", "").
# 
 -----------------------------------------------------------------------------------------------------------------------------

By the way: where can I find the domain_of function of page 630. Here is the code I used from the book:

Harald