From 9d2fb169bfc461d247338137458cbecc924d9208 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Mon, 9 Dec 2002 14:57:51 +0000 Subject: [PATCH] - added explode_sockaddr, inverse function of build_sockaddr - uncurried build_sockaddr arguments - added peername_of_{in,out}_channel which retrieve peer socket address from an i/o channel --- helm/DEVEL/ocaml-http/http_misc.ml | 11 ++++++++++- helm/DEVEL/ocaml-http/http_misc.mli | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/helm/DEVEL/ocaml-http/http_misc.ml b/helm/DEVEL/ocaml-http/http_misc.ml index 8117c540b..0e11e1048 100644 --- a/helm/DEVEL/ocaml-http/http_misc.ml +++ b/helm/DEVEL/ocaml-http/http_misc.ml @@ -97,6 +97,15 @@ let reason_phrase_of_code = function | 505 -> "HTTP version not supported" | invalid_code -> raise (Invalid_code invalid_code) -let build_sockaddr ~addr ~port = +let build_sockaddr (addr, port) = Unix.ADDR_INET (Unix.inet_addr_of_string addr, port) +let explode_sockaddr = function + | Unix.ADDR_INET (addr, port) -> (Unix.string_of_inet_addr addr, port) + | _ -> assert false (* can explode only inet address *) + +let peername_of_out_channel outchan = + Unix.getpeername (Unix.descr_of_out_channel outchan) +let peername_of_in_channel inchan = + Unix.getpeername (Unix.descr_of_in_channel inchan) + diff --git a/helm/DEVEL/ocaml-http/http_misc.mli b/helm/DEVEL/ocaml-http/http_misc.mli index 3aea8b52d..6e5fdfcf6 100644 --- a/helm/DEVEL/ocaml-http/http_misc.mli +++ b/helm/DEVEL/ocaml-http/http_misc.mli @@ -42,10 +42,24 @@ val strip_heading_slash: string -> string (** given a dir handle @return a list of entries contained *) val ls: Unix.dir_handle -> string list + (** explode a string in a char list *) val string_explode: string -> char list + (** implode a char list in a string *) val string_implode: char list -> string + (** given an HTTP response code return the corresponding reason phrase *) val reason_phrase_of_code: int -> string -val build_sockaddr: addr:string -> port:int -> Unix.sockaddr + (** build a Unix.sockaddr inet address from a string representation of an IP + address and a port number *) +val build_sockaddr: string * int -> Unix.sockaddr + (** explode an _inet_ Unix.sockaddr address in a string representation of an + IP address and a port number *) +val explode_sockaddr: Unix.sockaddr -> string * int + + (** given an out_channel build on top of a socket, return peername related to + that socket *) +val peername_of_out_channel: out_channel -> Unix.sockaddr + (** as above but works on in_channels *) +val peername_of_in_channel: in_channel -> Unix.sockaddr -- 2.39.2