caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Q] About Unix Library of Ocaml
@ 2000-02-22  7:29 Bomshik Kim
  2000-02-22 12:34 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: Bomshik Kim @ 2000-02-22  7:29 UTC (permalink / raw)
  To: caml-list


 Hello~ 
 I Have Some Questions About Unix Library

1) Why do these exceptions occur ?

---------------------------------------------------------- 
        Objective Caml version 2.04

# open Unix ;;
# let theSocket = socket PF_INET SOCK_STREAM 0 ;;
val theSocket : Unix.file_descr = <abstr>
# let theSocket = socket PF_INET SOCK_DGRAM 0 ;;
val theSocket : Unix.file_descr = <abstr>
# let theSocket = socket PF_INET SOCK_RAW 0 ;;
Uncaught exception: Unix.Unix_error(1, "socket", "")
# let theSocket = socket PF_INET SOCK_SEQPACKET 0 ;;
Uncaught exception: Unix.Unix_error(45, "socket", "")
# 
----------------------------------------------------------

2) What is the differences of 4 socket_type ?
 Stream socket, Datagram socket, Raw socket, Sequenced packets socket

3) Error with using connection function  

 Could you let me know the error code(63)
 and why does this error occur? 

-----------------------------------------------------------
        Objective Caml version 2.04

# open Unix ;;
# let addr = inet_addr_of_string "***.***.***.***" ;;
val addr : Unix.inet_addr = <abstr>
# let socketAddr = ADDR_INET( addr , 21 ) ;;
val socketAddr : Unix.sockaddr = ADDR_INET (<abstr>, 21)
# let theSocket = socket PF_INET SOCK_STREAM 0 ;;
val theSocket : Unix.file_descr = <abstr>
# connect theSocket socketAddr ;;
Uncaught exception: Unix.Unix_error(63, "connect", "")
-----------------------------------------------------------


4) Where can I get more specific information(examples, docs, papers) 
  about ocaml library especially unix library 
  (in order to design & implement bigger network library of ocaml 
   for building web-server, web-browser etc... )

@ thank you 
-bskim@ropas.kaist.ac.kr




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Q] About Unix Library of Ocaml
  2000-02-22  7:29 [Q] About Unix Library of Ocaml Bomshik Kim
@ 2000-02-22 12:34 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2000-02-22 12:34 UTC (permalink / raw)
  To: Bomshik Kim, caml-list

> 1) Why do these exceptions occur ?
> # let theSocket = socket PF_INET SOCK_RAW 0 ;;
> Uncaught exception: Unix.Unix_error(1, "socket", "")
> # let theSocket = socket PF_INET SOCK_SEQPACKET 0 ;;
> Uncaught exception: Unix.Unix_error(45, "socket", "")

The best way to interpret those mysterious error codes is to use the
Unix.error_message function to get a readable error message.  Let's do
that as a generic error reporting function:

# let show_unix_error fn =
    try
      fn ()
    with Unix_error(err, ctx1, ctx2) as exn -> 
      Printf.printf "Unix error: %s, %s, %s" (error_message err) ctx1 ctx2;
      print_newline();
      raise exn;;

Now, the errors you get are nearly self-explanatory:

# show_unix_error (fun () ->  socket PF_INET SOCK_RAW 0);;
Unix error: Operation not permitted, socket, 
Uncaught exception: Unix.Unix_error(30, "socket", "")
# show_unix_error (fun () ->  socket PF_INET SOCK_SEQPACKET 0);;
Unix error: Socket type not supported, socket, 
Uncaught exception: Unix.Unix_error(46, "socket", "")

In other terms, the SEQPACKET socket type is not supported by your
Unix kernel, and you need to be superuser to create a socket in RAW
mode.

> 2) What is the differences of 4 socket_type ?
>  Stream socket, Datagram socket, Raw socket, Sequenced packets socket

This question, as well as your other questions, is a question about
Unix network programming, not about Caml.  The "Unix" library in Caml
is a direct translation of the basic Unix systems programming concepts.
Please refer to any good book on Unix systems programming, such as
the books by W. Richard Stevens ("Advanced Programming in the Unix
Environment", "Unix Network Programming", etc).

> 3) Error with using connection function  
> 
> # let addr = inet_addr_of_string "***.***.***.***" ;;
> val addr : Unix.inet_addr = <abstr>
> # let socketAddr = ADDR_INET( addr , 21 ) ;;
> val socketAddr : Unix.sockaddr = ADDR_INET (<abstr>, 21)
> # let theSocket = socket PF_INET SOCK_STREAM 0 ;;
> val theSocket : Unix.file_descr = <abstr>
> # connect theSocket socketAddr ;;
> Uncaught exception: Unix.Unix_error(63, "connect", "")
>  Could you let me know the error code(63)
>  and why does this error occur? 

Again, using the show_unix_error above, you'd see that the error is
"No route to host", and it means that the machine with the specified
IP address is not accessible from your machine.

> 4) Where can I get more specific information(examples, docs, papers) 
>   about ocaml library especially unix library 
>   (in order to design & implement bigger network library of ocaml 
>    for building web-server, web-browser etc... )

The books I mentioned above are an excellent starting point.  Once
you're familiar with Unix systems programming in general, you should
have no problems using the "Unix" library.

Best regards,

- Xavier Leroy



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-02-22 14:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-22  7:29 [Q] About Unix Library of Ocaml Bomshik Kim
2000-02-22 12:34 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).