Support IPv6

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@6193 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 2004-04-09 13:25:23 +00:00
parent b9ba49e310
commit 641657c87b
17 changed files with 978 additions and 390 deletions

6
configure vendored
View File

@ -783,6 +783,12 @@ if sh ./hasgot inet_aton; then
echo "#define HAS_INET_ATON" >> s.h
fi
if sh ./hasgot -i sys/socket.h -i netinet/in.h -t 'struct sockaddr_in6' \
&& sh ./hasgot getaddrinfo getnameinfo inet_pton inet_ntop; then
echo "IPv6 is supported."
echo "#define HAS_IPV6" >> s.h
fi
if sh ./hasgot -i unistd.h; then
echo "unistd.h found."
echo "#define HAS_UNISTD" >> s.h

View File

@ -484,7 +484,7 @@ external getgrnam : string -> group_entry = "unix_getgrnam"
external getpwuid : int -> passwd_entry = "unix_getpwuid"
external getgrgid : int -> group_entry = "unix_getgrgid"
type inet_addr
type inet_addr = string
external inet_addr_of_string : string -> inet_addr
= "unix_inet_addr_of_string"
@ -492,10 +492,18 @@ external string_of_inet_addr : inet_addr -> string
= "unix_string_of_inet_addr"
let inet_addr_any = inet_addr_of_string "0.0.0.0"
let inet_addr_loopback = inet_addr_of_string "127.0.0.1"
let inet6_addr_any =
try inet_addr_of_string "::" with Failure _ -> inet_addr_any
let inet6_addr_loopback =
try inet_addr_of_string "::1" with Failure _ -> inet_addr_loopback
let is_inet6_addr s = String.length s = 16
type socket_domain =
PF_UNIX
| PF_INET
| PF_INET6
type socket_type =
SOCK_STREAM
@ -507,6 +515,10 @@ type sockaddr =
ADDR_UNIX of string
| ADDR_INET of inet_addr * int
let domain_of_sockaddr = function
ADDR_UNIX _ -> PF_UNIX
| ADDR_INET(a, _) -> if is_inet6_addr a then PF_INET6 else PF_INET
type shutdown_command =
SHUTDOWN_RECEIVE
| SHUTDOWN_SEND
@ -675,6 +687,135 @@ external getservbyname : string -> string -> service_entry
= "unix_getservbyname"
external getservbyport : int -> string -> service_entry
= "unix_getservbyport"
type addr_info =
{ ai_family : socket_domain;
ai_socktype : socket_type;
ai_protocol : int;
ai_addr : sockaddr;
ai_canonname : string }
type getaddrinfo_option =
AI_FAMILY of socket_domain
| AI_SOCKTYPE of socket_type
| AI_PROTOCOL of int
| AI_NUMERICHOST
| AI_CANONNAME
| AI_PASSIVE
external getaddrinfo_system
: string -> string -> getaddrinfo_option list -> addr_info list
= "unix_getaddrinfo"
let getaddrinfo_emulation node service opts =
(* Parse options *)
let opt_socktype = ref None
and opt_protocol = ref 0
and opt_passive = ref false in
List.iter
(function AI_SOCKTYPE s -> opt_socktype := Some s
| AI_PROTOCOL p -> opt_protocol := p
| AI_PASSIVE -> opt_passive := true
| _ -> ())
opts;
(* Determine socket types and port numbers *)
let get_port ty kind =
if service = "" then [ty, 0] else
try
[ty, int_of_string service]
with Failure _ ->
try
[ty, (getservbyname service kind).s_port]
with Not_found -> []
in
let ports =
match !opt_socktype with
| None ->
get_port SOCK_STREAM "tcp" @ get_port SOCK_DGRAM "udp"
| Some SOCK_STREAM ->
get_port SOCK_STREAM "tcp"
| Some SOCK_DGRAM ->
get_port SOCK_DGRAM "udp"
| Some ty ->
if service = "" then [ty, 0] else [] in
(* Determine IP addresses *)
let addresses =
if node = "" then
if List.mem AI_PASSIVE opts
then [inet_addr_any, "0.0.0.0"]
else [inet_addr_loopback, "127.0.0.1"]
else
try
[inet_addr_of_string node, node]
with Failure _ ->
try
let he = gethostbyname node in
List.map
(fun a -> (a, he.h_name))
(Array.to_list he.h_addr_list)
with Not_found ->
[] in
(* Cross-product of addresses and ports *)
List.flatten
(List.map
(fun (ty, port) ->
List.map
(fun (addr, name) ->
{ ai_family = PF_INET;
ai_socktype = ty;
ai_protocol = !opt_protocol;
ai_addr = ADDR_INET(addr, port);
ai_canonname = name })
addresses)
ports)
let getaddrinfo node service opts =
try
List.rev(getaddrinfo_system node service opts)
with Invalid_argument _ ->
getaddrinfo_emulation node service opts
type name_info =
{ ni_hostname : string;
ni_service : string }
type getnameinfo_option =
NI_NOFQDN
| NI_NUMERICHOST
| NI_NAMEREQD
| NI_NUMERICSERV
| NI_DGRAM
external getnameinfo_system
: sockaddr -> getnameinfo_option list -> name_info
= "unix_getnameinfo"
let getnameinfo_emulation addr opts =
match addr with
| ADDR_UNIX f ->
{ ni_hostname = ""; ni_service = f } (* why not? *)
| ADDR_INET(a, p) ->
let hostname =
try
if List.mem NI_NUMERICHOST opts then raise Not_found;
(gethostbyaddr a).h_name
with Not_found ->
if List.mem NI_NAMEREQD opts then raise Not_found;
string_of_inet_addr a in
let service =
try
if List.mem NI_NUMERICSERV opts then raise Not_found;
let kind = if List.mem NI_DGRAM opts then "udp" else "tcp" in
(getservbyport p kind).s_name
with Not_found ->
string_of_int p in
{ ni_hostname = hostname; ni_service = service }
let getnameinfo addr opts =
try
getnameinfo_system addr opts
with Invalid_argument _ ->
getnameinfo_emulation addr opts
type terminal_io = {
mutable c_ignbrk: bool;
mutable c_brkint: bool;
@ -894,10 +1035,8 @@ let close_process_full (inchan, outchan, errchan) =
(* High-level network functions *)
let open_connection sockaddr =
let domain =
match sockaddr with ADDR_UNIX _ -> PF_UNIX | ADDR_INET(_,_) -> PF_INET in
let sock =
socket domain SOCK_STREAM 0 in
socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in
try
connect sock sockaddr;
(in_channel_of_descr sock, out_channel_of_descr sock)
@ -908,10 +1047,8 @@ let shutdown_connection inchan =
shutdown (descr_of_in_channel inchan) SHUTDOWN_SEND
let establish_server server_fun sockaddr =
let domain =
match sockaddr with ADDR_UNIX _ -> PF_UNIX | ADDR_INET(_,_) -> PF_INET in
let sock =
socket domain SOCK_STREAM 0 in
socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in
setsockopt sock SO_REUSEADDR true;
bind sock sockaddr;
listen sock 5;

View File

@ -1,346 +1,233 @@
accept.o: accept.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/signals.h unixsupport.h \
socketaddr.h
access.o: access.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h unixsupport.h
addrofstr.o: addrofstr.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/fail.h \
unixsupport.h socketaddr.h
alarm.o: alarm.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
accept.o: accept.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h socketaddr.h
access.o: access.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
addrofstr.o: addrofstr.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h socketaddr.h
alarm.o: alarm.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
bind.o: bind.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
bind.o: bind.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h socketaddr.h
chdir.o: chdir.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
chdir.o: chdir.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
chmod.o: chmod.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
chmod.o: chmod.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
chown.o: chown.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
chown.o: chown.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
chroot.o: chroot.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
close.o: close.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
closedir.o: closedir.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
chroot.o: chroot.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
connect.o: connect.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/signals.h \
unixsupport.h socketaddr.h
cst2constr.o: cst2constr.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/fail.h cst2constr.h
cstringv.o: cstringv.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
dup.o: dup.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
close.o: close.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
dup2.o: dup2.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
envir.o: envir.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h
errmsg.o: errmsg.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h
execv.o: execv.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/memory.h ../../byterun/gc.h \
closedir.o: closedir.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
connect.o: connect.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h socketaddr.h
cst2constr.o: cst2constr.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h cst2constr.h
cstringv.o: cstringv.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
execve.o: execve.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/memory.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
execvp.o: execvp.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/memory.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
exit.o: exit.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
dup2.o: dup2.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
fchmod.o: fchmod.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
dup.o: dup.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
fchown.o: fchown.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
fcntl.o: fcntl.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
fork.o: fork.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
ftruncate.o: ftruncate.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/io.h unixsupport.h
getcwd.o: getcwd.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h unixsupport.h
getegid.o: getegid.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
geteuid.o: geteuid.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getgid.o: getgid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
getgr.o: getgr.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/fail.h ../../byterun/alloc.h \
../../byterun/memory.h ../../byterun/gc.h ../../byterun/major_gc.h \
envir.o: envir.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h
errmsg.o: errmsg.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h
execv.o: execv.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h
getgroups.o: getgroups.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h
gethost.o: gethost.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
../../byterun/memory.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h ../../byterun/fail.h \
../../byterun/signals.h unixsupport.h socketaddr.h
gethostname.o: gethostname.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h
getlogin.o: getlogin.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h
getpeername.o: getpeername.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h socketaddr.h
getpid.o: getpid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
getppid.o: getppid.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getproto.o: getproto.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
../../byterun/memory.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h ../../byterun/fail.h \
unixsupport.h
getpw.o: getpw.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/fail.h unixsupport.h
getserv.o: getserv.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
../../byterun/memory.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h ../../byterun/fail.h \
unixsupport.h
getsockname.o: getsockname.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h socketaddr.h
gettimeofday.o: gettimeofday.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h
getuid.o: getuid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
gmtime.o: gmtime.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
itimer.o: itimer.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
kill.o: kill.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/fail.h unixsupport.h \
../../byterun/signals.h
link.o: link.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
listen.o: listen.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
lockf.o: lockf.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
lseek.o: lseek.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/io.h \
unixsupport.h
mkdir.o: mkdir.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
mkfifo.o: mkfifo.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
nice.o: nice.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
open.o: open.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/signals.h unixsupport.h
opendir.o: opendir.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
pipe.o: pipe.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h unixsupport.h
putenv.o: putenv.c ../../byterun/memory.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/gc.h ../../byterun/mlvalues.h ../../byterun/misc.h \
execve.o: execve.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
read.o: read.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/memory.h ../../byterun/gc.h \
execvp.o: execvp.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/signals.h unixsupport.h
readdir.o: readdir.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/fail.h \
../../byterun/alloc.h unixsupport.h
readlink.o: readlink.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h
rename.o: rename.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/minor_gc.h unixsupport.h
exit.o: exit.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
rewinddir.o: rewinddir.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
fchmod.o: fchmod.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
rmdir.o: rmdir.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
select.o: select.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/signals.h unixsupport.h
sendrecv.o: sendrecv.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
../../byterun/memory.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h \
../../byterun/signals.h unixsupport.h socketaddr.h
setgid.o: setgid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
setsid.o: setsid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
setuid.o: setuid.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
shutdown.o: shutdown.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
fchown.o: fchown.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
signals.o: signals.c ../../byterun/alloc.h ../../byterun/compatibility.h \
../../byterun/misc.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/mlvalues.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/signals.h unixsupport.h
sleep.o: sleep.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/signals.h unixsupport.h
socket.o: socket.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
fcntl.o: fcntl.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
socketaddr.o: socketaddr.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
../../byterun/memory.h ../../byterun/gc.h ../../byterun/major_gc.h \
fork.o: fork.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
ftruncate.o: ftruncate.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getaddrinfo.o: getaddrinfo.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h cst2constr.h socketaddr.h
getcwd.o: getcwd.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getegid.o: getegid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
geteuid.o: geteuid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getgid.o: getgid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getgr.o: getgr.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h
getgroups.o: getgroups.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
gethost.o: gethost.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h socketaddr.h
gethostname.o: gethostname.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getlogin.o: getlogin.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getnameinfo.o: getnameinfo.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h socketaddr.h
getpeername.o: getpeername.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h socketaddr.h
getpid.o: getpid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getppid.o: getppid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getproto.o: getproto.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
getpw.o: getpw.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h
getserv.o: getserv.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
getsockname.o: getsockname.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h socketaddr.h
gettimeofday.o: gettimeofday.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
getuid.o: getuid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
gmtime.o: gmtime.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
itimer.o: itimer.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
kill.o: kill.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
link.o: link.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
listen.o: listen.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
lockf.o: lockf.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
lseek.o: lseek.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
mkdir.o: mkdir.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
mkfifo.o: mkfifo.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
nice.o: nice.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
open.o: open.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h
opendir.o: opendir.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
pipe.o: pipe.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
putenv.o: putenv.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/gc.h ../../byterun/mlvalues.h \
../../byterun/misc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
read.o: read.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h
readdir.o: readdir.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
readlink.o: readlink.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
rename.o: rename.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
rewinddir.o: rewinddir.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
rmdir.o: rmdir.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
select.o: select.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
sendrecv.o: sendrecv.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h socketaddr.h
setgid.o: setgid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
setsid.o: setsid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
setuid.o: setuid.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
shutdown.o: shutdown.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
signals.o: signals.c ../../byterun/misc.h ../../byterun/config.h \
../../config/m.h ../../config/s.h ../../byterun/mlvalues.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
sleep.o: sleep.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
socketaddr.o: socketaddr.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h socketaddr.h
socket.o: socket.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
socketpair.o: socketpair.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
sockopt.o: sockopt.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h socketaddr.h
stat.o: stat.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h \
socketaddr.h
socketpair.o: socketpair.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h
sockopt.o: sockopt.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h socketaddr.h
stat.o: stat.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/memory.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/alloc.h unixsupport.h \
cst2constr.h ../../byterun/io.h
strofaddr.o: strofaddr.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h socketaddr.h
symlink.o: symlink.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
termios.o: termios.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
unixsupport.h
time.o: time.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h unixsupport.h
times.o: times.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h unixsupport.h
truncate.o: truncate.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/io.h unixsupport.h
umask.o: umask.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
unixsupport.o: unixsupport.c ../../byterun/mlvalues.h \
../../byterun/compatibility.h ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/alloc.h \
../../byterun/callback.h ../../byterun/memory.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/fail.h unixsupport.h \
cst2constr.h
unlink.o: unlink.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
strofaddr.o: strofaddr.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h socketaddr.h
symlink.o: symlink.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
termios.o: termios.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
time.o: time.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
utimes.o: utimes.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
times.o: times.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h
truncate.o: truncate.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
umask.o: umask.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h unixsupport.h
wait.o: wait.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/alloc.h ../../byterun/memory.h \
../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/signals.h unixsupport.h
write.o: write.c ../../byterun/mlvalues.h ../../byterun/compatibility.h \
../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/memory.h ../../byterun/gc.h \
unixsupport.o: unixsupport.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h ../../byterun/gc.h \
../../byterun/major_gc.h ../../byterun/freelist.h \
../../byterun/minor_gc.h ../../byterun/signals.h unixsupport.h
../../byterun/minor_gc.h unixsupport.h cst2constr.h
unlink.o: unlink.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
utimes.o: utimes.c ../../byterun/config.h ../../config/m.h \
../../config/s.h ../../byterun/misc.h unixsupport.h
wait.o: wait.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h
write.o: write.c ../../byterun/config.h ../../config/m.h ../../config/s.h \
../../byterun/misc.h ../../byterun/gc.h ../../byterun/major_gc.h \
../../byterun/freelist.h ../../byterun/minor_gc.h unixsupport.h
unixLabels.cmi: unix.cmi
unix.cmo: unix.cmi
unix.cmx: unix.cmi
unixLabels.cmo: unix.cmi unixLabels.cmi
unixLabels.cmx: unix.cmx unixLabels.cmi
unix.cmo: unix.cmi
unix.cmx: unix.cmi

View File

@ -28,9 +28,10 @@ COMPFLAGS=-warn-error A
OBJS=accept.o access.o addrofstr.o alarm.o bind.o chdir.o chmod.o \
chown.o chroot.o close.o closedir.o connect.o cst2constr.o cstringv.o \
dup.o dup2.o envir.o errmsg.o execv.o execve.o execvp.o exit.o \
fchmod.o fchown.o fcntl.o fork.o ftruncate.o getcwd.o getegid.o \
geteuid.o getgid.o getgr.o getgroups.o gethost.o gethostname.o \
getlogin.o getpeername.o getpid.o getppid.o getproto.o getpw.o \
fchmod.o fchown.o fcntl.o fork.o ftruncate.o \
getaddrinfo.o getcwd.o getegid.o geteuid.o getgid.o \
getgr.o getgroups.o gethost.o gethostname.o getlogin.o \
getnameinfo.o getpeername.o getpid.o getppid.o getproto.o getpw.o \
gettimeofday.o getserv.o getsockname.o getuid.o \
gmtime.o itimer.o kill.o link.o listen.o lockf.o lseek.o mkdir.o \
mkfifo.o nice.o open.o opendir.o pipe.o putenv.o read.o \

View File

@ -23,16 +23,25 @@
CAMLprim value unix_inet_addr_of_string(value s)
{
#ifdef HAS_INET_ATON
#if defined(HAS_IPV6)
struct in_addr address;
struct in6_addr address6;
if (inet_pton(AF_INET, String_val(s), &address) > 0)
return alloc_inet_addr(&address);
else if (inet_pton(AF_INET6, String_val(s), &address6) > 0)
return alloc_inet6_addr(&address6);
else
failwith("inet_addr_of_string");
#elif defined(HAS_INET_ATON)
struct in_addr address;
if (inet_aton(String_val(s), &address) == 0)
failwith("inet_addr_of_string");
return alloc_inet_addr(address.s_addr);
return alloc_inet_addr(&address);
#else
unsigned int address;
address = inet_addr(String_val(s));
if (address == (unsigned int) -1) failwith("inet_addr_of_string");
return alloc_inet_addr(address);
struct in_addr address;
address.s_addr = inet_addr(String_val(s));
if (address.s_addr == (uint32) -1) failwith("inet_addr_of_string");
return alloc_inet_addr(&address);
#endif
}

View File

@ -13,8 +13,4 @@
/* $Id$ */
#ifdef __STDC__
value cst_to_constr(int, int *, int, int);
#else
value cst_to_constr();
#endif
extern value cst_to_constr(int n, int * tbl, int size, int deflt);

View File

@ -0,0 +1,133 @@
/***********************************************************************/
/* */
/* Objective Caml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 2004 Institut National de Recherche en Informatique et */
/* en Automatique. All rights reserved. This file is distributed */
/* under the terms of the GNU Library General Public License, with */
/* the special exception on linking described in file ../../LICENSE. */
/* */
/***********************************************************************/
/* $Id$ */
#include <string.h>
#include <mlvalues.h>
#include <alloc.h>
#include <memory.h>
#include <fail.h>
#include <signals.h>
#include "unixsupport.h"
#include "cst2constr.h"
#if defined(HAS_SOCKETS) && defined(HAS_IPV6)
#include "socketaddr.h"
#ifndef _WIN32
#include <sys/types.h>
#include <netdb.h>
#endif
extern int socket_domain_table[]; /* from socket.c */
extern int socket_type_table[]; /* from socket.c */
static value convert_addrinfo(struct addrinfo * a)
{
CAMLparam0();
CAMLlocal3(vres,vaddr,vcanonname);
union sock_addr_union sa;
memcpy(&sa.s_gen, a->ai_addr, sizeof(struct sockaddr));
vaddr = alloc_sockaddr(&sa, sizeof(struct sockaddr));
vcanonname = copy_string(a->ai_canonname == NULL ? "" : a->ai_canonname);
vres = alloc_small(5, 0);
Field(vres, 0) = cst_to_constr(a->ai_family, socket_domain_table, 3, 0);
Field(vres, 1) = cst_to_constr(a->ai_socktype, socket_type_table, 4, 0);
Field(vres, 2) = Val_int(a->ai_protocol);
Field(vres, 3) = vaddr;
Field(vres, 4) = vcanonname;
CAMLreturn(vres);
}
CAMLprim value unix_getaddrinfo(value vnode, value vserv, value vopts)
{
CAMLparam3(vnode, vserv, vopts);
CAMLlocal3(vres, v, e);
mlsize_t len;
char * node, * serv;
struct addrinfo hints;
struct addrinfo * res, * r;
int retcode;
/* Extract "node" parameter */
len = string_length(vnode);
if (len == 0) {
node = NULL;
} else {
node = stat_alloc(len + 1);
strcpy(node, String_val(vnode));
}
/* Extract "service" parameter */
len = string_length(vserv);
if (len == 0) {
serv = NULL;
} else {
serv = stat_alloc(len + 1);
strcpy(serv, String_val(vserv));
}
/* Parse options, set hints */
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
for (/*nothing*/; Is_block(vopts); vopts = Field(vopts, 1)) {
v = Field(vopts, 0);
if (Is_block(v))
switch (Tag_val(v)) {
case 0: /* AI_FAMILY of socket_domain */
hints.ai_family = socket_domain_table[Int_val(Field(v, 0))];
break;
case 1: /* AI_SOCKTYPE of socket_type */
hints.ai_socktype = socket_type_table[Int_val(Field(v, 0))];
break;
case 2: /* AI_PROTOCOL of int */
hints.ai_protocol = Int_val(Field(v, 0));
break;
}
else
switch (Int_val(v)) {
case 0: /* AI_NUMERICHOST */
hints.ai_flags |= AI_NUMERICHOST; break;
case 1: /* AI_CANONNAME */
hints.ai_flags |= AI_CANONNAME; break;
case 2: /* AI_PASSIVE */
hints.ai_flags |= AI_PASSIVE; break;
}
}
/* Do the call */
enter_blocking_section();
retcode = getaddrinfo(node, serv, &hints, &res);
leave_blocking_section();
if (node != NULL) stat_free(node);
if (serv != NULL) stat_free(serv);
/* Convert result */
vres = Val_int(0);
if (retcode == 0) {
for (r = res; r != NULL; r = r->ai_next) {
e = convert_addrinfo(r);
v = alloc_small(2, 0);
Field(v, 0) = e;
Field(v, 1) = vres;
vres = v;
}
freeaddrinfo(res);
}
CAMLreturn(vres);
}
#else
CAMLprim value unix_getaddrinfo(value vnode, value vserv, value vopts)
{ invalid_argument("getaddrinfo not implemented"); }
#endif

View File

@ -43,8 +43,15 @@ extern int socket_domain_table[];
static value alloc_one_addr(char const *a)
{
struct in_addr addr;
memmove (&addr, a, entry_h_length);
return alloc_inet_addr(addr.s_addr);
#ifdef HAS_IPV6
struct in6_addr addr6;
if (entry_h_length == 16) {
memmove(&addr6, a, 16);
return alloc_inet6_addr(&addr6);
}
#endif
memmove (&addr, a, 4);
return alloc_inet_addr(&addr);
}
static value alloc_host_entry(struct hostent *entry)
@ -75,7 +82,7 @@ static value alloc_host_entry(struct hostent *entry)
CAMLprim value unix_gethostbyaddr(value a)
{
uint32 adr = GET_INET_ADDR(a);
struct in_addr adr = GET_INET_ADDR(a);
struct hostent * hp;
#if HAS_GETHOSTBYADDR_R == 7
struct hostent h;

View File

@ -0,0 +1,67 @@
/***********************************************************************/
/* */
/* Objective Caml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 2004 Institut National de Recherche en Informatique et */
/* en Automatique. All rights reserved. This file is distributed */
/* under the terms of the GNU Library General Public License, with */
/* the special exception on linking described in file ../../LICENSE. */
/* */
/***********************************************************************/
/* $Id$ */
#include <string.h>
#include <mlvalues.h>
#include <alloc.h>
#include <memory.h>
#include <fail.h>
#include <signals.h>
#include "unixsupport.h"
#if defined(HAS_SOCKETS) && defined(HAS_IPV6)
#include "socketaddr.h"
#ifndef _WIN32
#include <sys/types.h>
#include <netdb.h>
#endif
static int getnameinfo_flag_table[] = {
NI_NOFQDN, NI_NUMERICHOST, NI_NAMEREQD, NI_NUMERICSERV, NI_DGRAM
};
CAMLprim value unix_getnameinfo(value vaddr, value vopts)
{
CAMLparam0();
CAMLlocal3(vhost, vserv, vres);
union sock_addr_union addr;
socklen_param_type addr_len;
char host[4096];
char serv[1024];
int opts, retcode;
get_sockaddr(vaddr, &addr, &addr_len);
opts = convert_flag_list(vopts, getnameinfo_flag_table);
enter_blocking_section();
retcode =
getnameinfo((const struct sockaddr *) &addr.s_gen, addr_len,
host, sizeof(host), serv, sizeof(serv), opts);
leave_blocking_section();
if (retcode != 0) raise_not_found(); /* TODO: detailed error reporting? */
vhost = copy_string(host);
vserv = copy_string(serv);
vres = alloc_small(2, 0);
Field(vres, 0) = vhost;
Field(vres, 1) = vserv;
CAMLreturn(vres);
}
#else
CAMLprim value unix_getnameinfo(value vaddr, value vopts)
{ invalid_argument("getnameinfo not implemented"); }
#endif

View File

@ -26,7 +26,7 @@ CAMLprim value unix_getpeername(value sock)
union sock_addr_union addr;
socklen_param_type addr_len;
addr_len = sizeof(sock_addr);
addr_len = sizeof(addr);
retcode = getpeername(Int_val(sock), &addr.s_gen, &addr_len);
if (retcode == -1) uerror("getpeername", Nothing);
return alloc_sockaddr(&addr, addr_len);

View File

@ -22,7 +22,14 @@
#include <sys/socket.h>
int socket_domain_table[] = {
PF_UNIX, PF_INET
PF_UNIX, PF_INET,
#if defined(HAS_IPV6)
PF_INET6
#elif defined(PF_UNDEF)
PF_UNDEF
#else
0
#endif
};
int socket_type_table[] = {

View File

@ -28,17 +28,29 @@
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#endif
value alloc_inet_addr(uint32 a)
CAMLprim value alloc_inet_addr(struct in_addr * a)
{
value res;
/* Use a string rather than an abstract block so that it can be
marshaled safely. Remember that a is in network byte order,
hence can be marshaled safely. */
res = alloc_string(sizeof(uint32));
GET_INET_ADDR(res) = a;
hence is marshaled in an endian-independent manner. */
res = alloc_string(4);
memcpy(String_val(res), a, 4);
return res;
}
#ifdef HAS_IPV6
CAMLprim value alloc_inet6_addr(struct in6_addr * a)
{
value res;
res = alloc_string(16);
memcpy(String_val(res), a, 16);
return res;
}
#endif
void get_sockaddr(value mladr,
union sock_addr_union * adr /*out*/,
socklen_param_type * adr_len /*out*/)
@ -62,18 +74,22 @@ void get_sockaddr(value mladr,
}
#endif
case 1: /* ADDR_INET */
{
char * p;
int n;
for (p = (char *) &adr->s_inet, n = sizeof(adr->s_inet);
n > 0; p++, n--)
*p = 0;
adr->s_inet.sin_family = AF_INET;
adr->s_inet.sin_addr.s_addr = GET_INET_ADDR(Field(mladr, 0));
adr->s_inet.sin_port = htons(Int_val(Field(mladr, 1)));
*adr_len = sizeof(struct sockaddr_in);
#ifdef HAS_IPV6
if (string_length(Field(mladr, 0)) == 16) {
memset(&adr->s_inet6, 0, sizeof(struct sockaddr_in6));
adr->s_inet6.sin6_family = AF_INET6;
adr->s_inet6.sin6_addr = GET_INET6_ADDR(Field(mladr, 0));
adr->s_inet6.sin6_port = htons(Int_val(Field(mladr, 1)));
*adr_len = sizeof(struct sockaddr_in6);
break;
}
#endif
memset(&adr->s_inet, 0, sizeof(struct sockaddr_in));
adr->s_inet.sin_family = AF_INET;
adr->s_inet.sin_addr = GET_INET_ADDR(Field(mladr, 0));
adr->s_inet.sin_port = htons(Int_val(Field(mladr, 1)));
*adr_len = sizeof(struct sockaddr_in);
break;
}
}
@ -93,7 +109,7 @@ value alloc_sockaddr(union sock_addr_union * adr /*in*/,
}
#endif
case AF_INET:
{ value a = alloc_inet_addr(adr->s_inet.sin_addr.s_addr);
{ value a = alloc_inet_addr(&adr->s_inet.sin_addr);
Begin_root (a);
res = alloc_small(2, 1);
Field(res,0) = a;
@ -101,6 +117,17 @@ value alloc_sockaddr(union sock_addr_union * adr /*in*/,
End_roots();
break;
}
#ifdef HAS_IPV6
case AF_INET6:
{ value a = alloc_inet6_addr(&adr->s_inet6.sin6_addr);
Begin_root (a);
res = alloc_small(2, 1);
Field(res,0) = a;
Field(res,1) = Val_int(ntohs(adr->s_inet6.sin6_port));
End_roots();
break;
}
#endif
default:
unix_error(EAFNOSUPPORT, "", Nothing);
}

View File

@ -24,21 +24,26 @@ union sock_addr_union {
struct sockaddr s_gen;
struct sockaddr_un s_unix;
struct sockaddr_in s_inet;
#ifdef HAS_IPV6
struct sockaddr_in6 s_inet6;
#endif
};
extern union sock_addr_union sock_addr;
#ifdef HAS_SOCKLEN_T
typedef socklen_t socklen_param_type;
#else
typedef int socklen_param_type;
#endif
void get_sockaddr (value mladdr,
union sock_addr_union * addr /*out*/,
socklen_param_type * addr_len /*out*/);
extern void get_sockaddr (value mladdr,
union sock_addr_union * addr /*out*/,
socklen_param_type * addr_len /*out*/);
CAMLprim value alloc_sockaddr (union sock_addr_union * addr /*in*/,
socklen_param_type addr_len);
CAMLprim value alloc_inet_addr (uint32 inaddr);
CAMLprim value alloc_inet_addr (struct in_addr * inaddr);
#define GET_INET_ADDR(v) (*((struct in_addr *) (v)))
#define GET_INET_ADDR(v) (*((uint32 *) (v)))
#ifdef HAS_IPV6
CAMLprim value alloc_inet6_addr (struct in6_addr * inaddr);
#define GET_INET6_ADDR(v) (*((struct in6_addr *) (v)))
#endif

View File

@ -23,9 +23,22 @@
CAMLprim value unix_string_of_inet_addr(value a)
{
struct in_addr address;
address.s_addr = GET_INET_ADDR(a);
return copy_string(inet_ntoa(address));
char * res;
#ifdef HAS_IPV6
char buffer[64];
if (string_length(a) == 16)
res = (char *)
inet_ntop(AF_INET6, (const void *) &GET_INET6_ADDR(a),
buffer, sizeof(buffer));
else
res = (char *)
inet_ntop(AF_INET, (const void *) &GET_INET_ADDR(a),
buffer, sizeof(buffer));
#else
res = inet_ntoa(GET_INET_ADDR(a));
#endif
if (res == NULL) uerror("string_of_inet_addr", Nothing);
return copy_string(res);
}
#else

View File

@ -374,7 +374,9 @@ external getgrnam : string -> group_entry = "unix_getgrnam"
external getpwuid : int -> passwd_entry = "unix_getpwuid"
external getgrgid : int -> group_entry = "unix_getgrgid"
type inet_addr
type inet_addr = string
let is_inet6_addr s = String.length s = 16
external inet_addr_of_string : string -> inet_addr
= "unix_inet_addr_of_string"
@ -382,10 +384,16 @@ external string_of_inet_addr : inet_addr -> string
= "unix_string_of_inet_addr"
let inet_addr_any = inet_addr_of_string "0.0.0.0"
let inet_addr_loopback = inet_addr_of_string "127.0.0.1"
let inet6_addr_any =
try inet_addr_of_string "::" with Failure _ -> inet_addr_any
let inet6_addr_loopback =
try inet_addr_of_string "::1" with Failure _ -> inet_addr_loopback
type socket_domain =
PF_UNIX
| PF_INET
| PF_INET6
type socket_type =
SOCK_STREAM
@ -397,6 +405,10 @@ type sockaddr =
ADDR_UNIX of string
| ADDR_INET of inet_addr * int
let domain_of_sockaddr = function
ADDR_UNIX _ -> PF_UNIX
| ADDR_INET(a, _) -> if is_inet6_addr a then PF_INET6 else PF_INET
type shutdown_command =
SHUTDOWN_RECEIVE
| SHUTDOWN_SEND
@ -518,6 +530,136 @@ external getservbyname : string -> string -> service_entry
= "unix_getservbyname"
external getservbyport : int -> string -> service_entry
= "unix_getservbyport"
type addr_info =
{ ai_family : socket_domain;
ai_socktype : socket_type;
ai_protocol : int;
ai_addr : sockaddr;
ai_canonname : string }
type getaddrinfo_option =
AI_FAMILY of socket_domain
| AI_SOCKTYPE of socket_type
| AI_PROTOCOL of int
| AI_NUMERICHOST
| AI_CANONNAME
| AI_PASSIVE
external getaddrinfo_system
: string -> string -> getaddrinfo_option list -> addr_info list
= "unix_getaddrinfo"
let getaddrinfo_emulation node service opts =
(* Parse options *)
let opt_socktype = ref None
and opt_protocol = ref 0
and opt_passive = ref false in
List.iter
(function AI_SOCKTYPE s -> opt_socktype := Some s
| AI_PROTOCOL p -> opt_protocol := p
| AI_PASSIVE -> opt_passive := true
| _ -> ())
opts;
(* Determine socket types and port numbers *)
let get_port ty kind =
if service = "" then [ty, 0] else
try
[ty, int_of_string service]
with Failure _ ->
try
[ty, (getservbyname service kind).s_port]
with Not_found -> []
in
let ports =
match !opt_socktype with
| None ->
get_port SOCK_STREAM "tcp" @ get_port SOCK_DGRAM "udp"
| Some SOCK_STREAM ->
get_port SOCK_STREAM "tcp"
| Some SOCK_DGRAM ->
get_port SOCK_DGRAM "udp"
| Some ty ->
if service = "" then [ty, 0] else [] in
(* Determine IP addresses *)
let addresses =
if node = "" then
if List.mem AI_PASSIVE opts
then [inet_addr_any, "0.0.0.0"]
else [inet_addr_loopback, "127.0.0.1"]
else
try
[inet_addr_of_string node, node]
with Failure _ ->
try
let he = gethostbyname node in
List.map
(fun a -> (a, he.h_name))
(Array.to_list he.h_addr_list)
with Not_found ->
[] in
(* Cross-product of addresses and ports *)
List.flatten
(List.map
(fun (ty, port) ->
List.map
(fun (addr, name) ->
{ ai_family = PF_INET;
ai_socktype = ty;
ai_protocol = !opt_protocol;
ai_addr = ADDR_INET(addr, port);
ai_canonname = name })
addresses)
ports)
let getaddrinfo node service opts =
try
List.rev(getaddrinfo_system node service opts)
with Invalid_argument _ ->
getaddrinfo_emulation node service opts
type name_info =
{ ni_hostname : string;
ni_service : string }
type getnameinfo_option =
NI_NOFQDN
| NI_NUMERICHOST
| NI_NAMEREQD
| NI_NUMERICSERV
| NI_DGRAM
external getnameinfo_system
: sockaddr -> getnameinfo_option list -> name_info
= "unix_getnameinfo"
let getnameinfo_emulation addr opts =
match addr with
| ADDR_UNIX f ->
{ ni_hostname = ""; ni_service = f } (* why not? *)
| ADDR_INET(a, p) ->
let hostname =
try
if List.mem NI_NUMERICHOST opts then raise Not_found;
(gethostbyaddr a).h_name
with Not_found ->
if List.mem NI_NAMEREQD opts then raise Not_found;
string_of_inet_addr a in
let service =
try
if List.mem NI_NUMERICSERV opts then raise Not_found;
let kind = if List.mem NI_DGRAM opts then "udp" else "tcp" in
(getservbyport p kind).s_name
with Not_found ->
string_of_int p in
{ ni_hostname = hostname; ni_service = service }
let getnameinfo addr opts =
try
getnameinfo_system addr opts
with Invalid_argument _ ->
getnameinfo_emulation addr opts
type terminal_io = {
mutable c_ignbrk: bool;
mutable c_brkint: bool;
@ -737,10 +879,8 @@ let close_process_full (inchan, outchan, errchan) =
(* High-level network functions *)
let open_connection sockaddr =
let domain =
match sockaddr with ADDR_UNIX _ -> PF_UNIX | ADDR_INET(_,_) -> PF_INET in
let sock =
socket domain SOCK_STREAM 0 in
socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in
try
connect sock sockaddr;
(in_channel_of_descr sock, out_channel_of_descr sock)
@ -751,10 +891,8 @@ let shutdown_connection inchan =
shutdown (descr_of_in_channel inchan) SHUTDOWN_SEND
let establish_server server_fun sockaddr =
let domain =
match sockaddr with ADDR_UNIX _ -> PF_UNIX | ADDR_INET(_,_) -> PF_INET in
let sock =
socket domain SOCK_STREAM 0 in
socket (domain_of_sockaddr sockaddr) SOCK_STREAM 0 in
setsockopt sock SO_REUSEADDR true;
bind sock sockaddr;
listen sock 5;

View File

@ -841,24 +841,40 @@ type inet_addr
(** The abstract type of Internet addresses. *)
val inet_addr_of_string : string -> inet_addr
(** Conversions between string with the format [XXX.YYY.ZZZ.TTT]
and Internet addresses. [inet_addr_of_string] raises [Failure]
when given a string that does not match this format. *)
(** Conversion from the printable representation of an Internet
address to its internal representation. The argument string
consists of 4 numbers separated by periods ([XXX.YYY.ZZZ.TTT])
for IPv4 addresses, and up to 8 numbers separated by colons
for IPv6 addresses. Raise [Failure] when given a string that
does not match these formats. *)
val string_of_inet_addr : inet_addr -> string
(** See {!Unix.inet_addr_of_string}. *)
(** Return the printable representation of the given Internet address.
See {!Unix.inet_addr_of_string} for a description of the
printable representation. *)
val inet_addr_any : inet_addr
(** A special Internet address, for use only with [bind], representing
(** A special IPv4 address, for use only with [bind], representing
all the Internet addresses that the host machine possesses. *)
val inet_addr_loopback : inet_addr
(** A special IPv4 address representing the host machine ([127.0.0.1]). *)
val inet6_addr_any : inet_addr
(** A special IPv6 address, for use only with [bind], representing
all the Internet addresses that the host machine possesses. *)
val inet6_addr_loopback : inet_addr
(** A special IPv6 address representing the host machine ([::1]). *)
(** {6 Sockets} *)
type socket_domain =
PF_UNIX (** Unix domain *)
| PF_INET (** Internet domain *)
| PF_INET (** Internet domain (IPv4) *)
| PF_INET6 (** Internet domain (IPv6) *)
(** The type of socket domains. *)
type socket_type =
@ -881,6 +897,9 @@ val socket : socket_domain -> socket_type -> int -> file_descr
given kind. The third argument is the protocol type; 0 selects
the default protocol for that kind of sockets. *)
val domain_of_sockaddr: sockaddr -> socket_domain
(** Return the socket domain adequate for the given socket address. *)
val socketpair :
socket_domain -> socket_type -> int -> file_descr * file_descr
(** Create a pair of unnamed sockets, connected together. *)
@ -1023,8 +1042,8 @@ external setsockopt_float :
val open_connection : sockaddr -> in_channel * out_channel
(** Connect to a server at the given address.
Return a pair of buffered channels connected to the server.
Remember to call {!Pervasives.flush} on the output channel at the right times
to ensure correct synchronization. *)
Remember to call {!Pervasives.flush} on the output channel at the right
times to ensure correct synchronization. *)
val shutdown_connection : in_channel -> unit
(** ``Shut down'' a connection established with {!Unix.open_connection};
@ -1092,6 +1111,65 @@ val getservbyport : int -> string -> service_entry
(** Find an entry in [services] with the given service number,
or raise [Not_found]. *)
type addr_info =
{ ai_family : socket_domain; (** Socket domain *)
ai_socktype : socket_type; (** Socket type *)
ai_protocol : int; (** Socket protocol number *)
ai_addr : sockaddr; (** Address *)
ai_canonname : string (** Canonical host name *)
}
(** Address information returned by {!Unix.getaddrinfo}. *)
type getaddrinfo_option =
AI_FAMILY of socket_domain (** Impose the given socket domain *)
| AI_SOCKTYPE of socket_type (** Impose the given socket type *)
| AI_PROTOCOL of int (** Impose the given protocol *)
| AI_NUMERICHOST (** Do not call name resolver,
expect numeric IP address *)
| AI_CANONNAME (** Fill the [ai_canonname] field
of the result *)
| AI_PASSIVE (** Set address to ``any'' address
for use with {!Unix.bind} *)
(** Options to {!Unix.getaddrinfo}. *)
val getaddrinfo:
string -> string -> getaddrinfo_option list -> addr_info list
(** [getaddrinfo host service opts] returns a list of {!Unix.addr_info}
records describing socket parameters and addresses suitable for
communicating with the given host and service. The empty list is
returned if the host or service names are unknown, or the constraints
expressed in [opts] cannot be satisfied.
[host] is either a host name or the string representation of an IP
address. [host] can be given as the empty string; in this case,
the ``any'' address or the ``loopback'' address are used,
depending whether [opts] contains [AI_PASSIVE].
[service] is either a service name or the string representation of
a port number. [service] can be given as the empty string;
in this case, the port field of the returned addresses is set to 0.
[opts] is a possibly empty list of options that allows the caller
to force a particular socket domain (e.g. IPv6 only or IPv4 only)
or a particular socket type (e.g. TCP only or UDP only). *)
type name_info =
{ ni_hostname : string; (** Name or IP address of host *)
ni_service : string } (** Name of service or port number *)
(** Host and service information returned by {!Unix.getnameinfo}. *)
type getnameinfo_option =
NI_NOFQDN (** Do not qualify local host names *)
| NI_NUMERICHOST (** Always return host as IP address *)
| NI_NAMEREQD (** Fail if host name cannot be determined *)
| NI_NUMERICSERV (** Always return service as port number *)
| NI_DGRAM (** Consider the service as UDP-based
instead of the default TCP *)
(** Options to {!Unix.getnameinfo}. *)
val getnameinfo : sockaddr -> getnameinfo_option list -> name_info
(** [getnameinfo addr opts] returns the host name and service name
corresponding to the socket address [addr]. [opts] is a possibly
empty list of options that governs how these names are obtained.
Raise [Not_found] if an error occurs. *)
(** {6 Terminal interface} *)

View File

@ -856,17 +856,32 @@ type inet_addr = Unix.inet_addr
(** The abstract type of Internet addresses. *)
val inet_addr_of_string : string -> inet_addr
(** Conversions between string with the format [XXX.YYY.ZZZ.TTT]
and Internet addresses. [inet_addr_of_string] raises [Failure]
when given a string that does not match this format. *)
(** Conversion from the printable representation of an Internet
address to its internal representation. The argument string
consists of 4 numbers separated by periods ([XXX.YYY.ZZZ.TTT])
for IPv4 addresses, and up to 8 numbers separated by colons
for IPv6 addresses. Raise [Failure] when given a string that
does not match these formats. *)
val string_of_inet_addr : inet_addr -> string
(** See {!UnixLabels.inet_addr_of_string}. *)
(** Return the printable representation of the given Internet address.
See {!Unix.inet_addr_of_string} for a description of the
printable representation. *)
val inet_addr_any : inet_addr
(** A special Internet address, for use only with [bind], representing
(** A special IPv4 address, for use only with [bind], representing
all the Internet addresses that the host machine possesses. *)
val inet_addr_loopback : inet_addr
(** A special IPv4 address representing the host machine ([127.0.0.1]). *)
val inet6_addr_any : inet_addr
(** A special IPv6 address, for use only with [bind], representing
all the Internet addresses that the host machine possesses. *)
val inet6_addr_loopback : inet_addr
(** A special IPv6 address representing the host machine ([::1]). *)
(** {6 Sockets} *)
@ -875,6 +890,7 @@ type socket_domain =
Unix.socket_domain =
PF_UNIX (** Unix domain *)
| PF_INET (** Internet domain *)
| PF_INET6 (** Internet domain (IPv6) *)
(** The type of socket domains. *)
type socket_type =
@ -896,6 +912,9 @@ type sockaddr =
domain; [addr] is the Internet address of the machine, and
[port] is the port number. *)
val domain_of_sockaddr: sockaddr -> socket_domain
(** Return the socket domain adequate for the given socket address. *)
val socket :
domain:socket_domain -> kind:socket_type -> protocol:int -> file_descr
(** Create a new socket in the given domain, and with the
@ -1125,7 +1144,65 @@ val getservbyport : int -> protocol:string -> service_entry
(** Find an entry in [services] with the given service number,
or raise [Not_found]. *)
type addr_info =
{ ai_family : socket_domain; (** Socket domain *)
ai_socktype : socket_type; (** Socket type *)
ai_protocol : int; (** Socket protocol number *)
ai_addr : sockaddr; (** Address *)
ai_canonname : string (** Canonical host name *)
}
(** Address information returned by {!Unix.getaddrinfo}. *)
type getaddrinfo_option =
AI_FAMILY of socket_domain (** Impose the given socket domain *)
| AI_SOCKTYPE of socket_type (** Impose the given socket type *)
| AI_PROTOCOL of int (** Impose the given protocol *)
| AI_NUMERICHOST (** Do not call name resolver,
expect numeric IP address *)
| AI_CANONNAME (** Fill the [ai_canonname] field
of the result *)
| AI_PASSIVE (** Set address to ``any'' address
for use with {!Unix.bind} *)
(** Options to {!Unix.getaddrinfo}. *)
val getaddrinfo:
string -> string -> getaddrinfo_option list -> addr_info list
(** [getaddrinfo host service opts] returns a list of {!Unix.addr_info}
records describing socket parameters and addresses suitable for
communicating with the given host and service. The empty list is
returned if the host or service names are unknown, or the constraints
expressed in [opts] cannot be satisfied.
[host] is either a host name or the string representation of an IP
address. [host] can be given as the empty string; in this case,
the ``any'' address or the ``loopback'' address are used,
depending whether [opts] contains [AI_PASSIVE].
[service] is either a service name or the string representation of
a port number. [service] can be given as the empty string;
in this case, the port field of the returned addresses is set to 0.
[opts] is a possibly empty list of options that allows the caller
to force a particular socket domain (e.g. IPv6 only, or IPv4 only)
or a particular socket type (e.g. TCP only or UDP only). *)
type name_info =
{ ni_hostname : string; (** Name or IP address of host *)
ni_service : string } (** Name of service or port number *)
(** Host and service information returned by {!Unix.getnameinfo}. *)
type getnameinfo_option =
NI_NOFQDN (** Do not qualify local host names *)
| NI_NUMERICHOST (** Always return host as IP address *)
| NI_NAMEREQD (** Fail if host name cannot be determined *)
| NI_NUMERICSERV (** Always return service as port number *)
| NI_DGRAM (** Consider the service as UDP-based
instead of the default TCP *)
(** Options to {!Unix.getnameinfo}. *)
val getnameinfo : sockaddr -> getnameinfo_option list -> name_info
(** [getnameinfo addr opts] returns the host name and service name
corresponding to the socket address [addr]. [opts] is a possibly
empty list of options that governs how these names are obtained.
Raise [Not_found] if an error occurs. *)
(** {6 Terminal interface} *)