Module Host

module Host: sig .. end
Simple hosts with a single Eth network interface with a full IP stack.

Hosts are merely simple IP stacks with a eth device at the bottom and a name. These makes the link between the network and programs such as browsers or http servers (see Browser and Opache).

Hosts also comes with a logger (see Log).

See also Localhost for a special kind of host that's running on top of guest system real IP stack.


type addr = 
| IPv4 of Ip.Addr.t
| Name of string
type host_trx = {
   name : string;
   logger : Log.logger;
   tcp_connect : addr ->
?src_port:Tcp.Port.t ->
Tcp.Port.t -> (Tcp.TRX.tcp_trx option -> unit) -> unit
;
   udp_connect : addr ->
?src_port:Udp.Port.t ->
Udp.Port.t ->
(Udp.TRX.udp_trx -> Bitstring.bitstring -> unit) ->
(Udp.TRX.udp_trx option -> unit) -> unit
;
   udp_send : addr ->
?src_port:Udp.Port.t -> Udp.Port.t -> Bitstring.bitstring -> unit
;
   ping : ?id:int -> ?seq:int -> addr -> unit;
   gethostbyname : string -> (Ip.Addr.t list option -> unit) -> unit;
   tcp_server : Tcp.Port.t -> (Tcp.TRX.tcp_trx -> unit) -> unit;
   udp_server : Udp.Port.t -> (Udp.TRX.udp_trx -> unit) -> unit;
   signal_err : string -> unit;
   dev : Tools.dev;
   get_mac : unit -> Eth.Addr.t;
   get_ip : unit -> Ip.Addr.t option;
   arp_set : Ip.Addr.t -> Eth.Addr.t option -> unit;
}
type tcp_socks = {
   ip_4_tcp : Tools.trx;
   tcps : (Tcp.Port.t * Tcp.Port.t, Tcp.TRX.tcp_trx) Batteries.Hashtbl.t;
}
type udp_socks = {
   ip_4_udp : Tools.trx;
   udps : (Udp.Port.t * Udp.Port.t, Udp.TRX.udp_trx) Batteries.Hashtbl.t;
}
val make_tcp_socks : Tools.trx -> tcp_socks
val make_udp_socks : Tools.trx -> udp_socks
type t = {
   mutable host_trx : host_trx;
   mutable my_ip : Ip.Addr.t;
   eth : Eth.TRX.eth_trx;
   tcp_socks : (Ip.Addr.t, tcp_socks) Batteries.Hashtbl.t;
   udp_socks : (Ip.Addr.t, udp_socks) Batteries.Hashtbl.t;
   icmp_socks : (Ip.Addr.t, Tools.trx) Batteries.Hashtbl.t;
   tcp_servers : (Tcp.Port.t, Tcp.TRX.tcp_trx -> unit) Batteries.Hashtbl.t;
   udp_servers : (Udp.Port.t, Udp.TRX.udp_trx -> unit) Batteries.Hashtbl.t;
   search_sfx : string option;
   nameserver : Ip.Addr.t option;
   mutable resolv_trx : Tools.trx option;
   dns_queries : (string, (Ip.Addr.t list option -> unit) * Clock.Time.t option)
Batteries.Hashtbl.t
;
   dns_cache : (string, Ip.Addr.t list) Batteries.Hashtbl.t;
}
exception No_socket
val signal_err : t -> string -> unit
val tcp_sock_rx : t -> tcp_socks -> Bitstring.bitstring -> unit
val udp_sock_rx : t -> udp_socks -> Bitstring.bitstring -> unit
val icmp_rx : 'a -> Tools.trx -> string * int * int -> unit
val find_alive_tcp : ('a, Tcp.TRX.tcp_trx) Batteries.Hashtbl.t -> 'a -> Tcp.TRX.tcp_trx option
exception AlreadyConnected
exception NoIp
exception CannotResolveName
exception DnsTimeout
val string_of_addr : addr -> string
val tcp_cnxs_ok : Metric.Atomic.t
val tcp_cnxs_err : Metric.Atomic.t
val udp_cnxs_ok : Metric.Atomic.t
val udp_cnxs_err : Metric.Atomic.t
val resolution_timeouts : Metric.Atomic.t
val resolution_cachehits : Metric.Atomic.t
val resolutions : Metric.Timed.t
val ip_is_set : t -> bool
val with_resolver_trx : t -> (Tools.trx option -> unit) -> unit
val gethostbyname : t -> string -> (Ip.Addr.t list option -> unit) -> unit
val do_gethostbyname : t -> string -> (Ip.Addr.t list option -> unit) -> unit
val tcp_connect : t ->
addr ->
?src_port:Tcp.Port.t ->
Tcp.Port.t -> (Tcp.TRX.tcp_trx option -> unit) -> unit
val udp_connect : t ->
addr ->
?src_port:Udp.Port.t ->
Udp.Port.t ->
(Udp.TRX.udp_trx -> Bitstring.bitstring -> unit) ->
(Udp.TRX.udp_trx option -> unit) -> unit
val udp_send : t ->
addr ->
?src_port:Udp.Port.t -> Udp.Port.t -> Tools.Payload.outer_t -> unit
val ping : t -> ?id:int -> ?seq:int -> addr -> unit
val tcp_server : t -> Tcp.Port.t -> (Tcp.TRX.tcp_trx -> unit) -> unit
val udp_server : t -> Udp.Port.t -> (Udp.TRX.udp_trx -> unit) -> unit
val ip_recv : t -> Bitstring.bitstring -> unit
val make : string ->
?gw:Eth.gw_addr ->
?search_sfx:string -> ?nameserver:Ip.Addr.t -> Eth.Addr.t -> t
val set_ip : t -> Ip.Addr.t -> unit
val make_static : string ->
?gw:Eth.gw_addr ->
?search_sfx:string ->
?nameserver:Ip.Addr.t -> Eth.Addr.t -> Ip.Addr.t -> host_trx
val make_dhcp : string ->
?gw:Eth.gw_addr ->
?search_sfx:string -> ?nameserver:Ip.Addr.t -> Eth.Addr.t -> host_trx
val random_name : unit -> string