123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(*
* Copyright (c) 2011-2015 Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2013-2015 Thomas Gazagnaire <thomas@gazagnaire.org>
* Copyright (c) 2013 Citrix Systems Inc
* Copyright (c) 2018 Hannes Mehnert <hannes@mehnert.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)moduleNet=structtypeerror=[`Invalid_length|`Disconnected]letpp_errorppf=function|`Invalid_length->Fmt.stringppf"invalid length (exceeds size)"|`Disconnected->Fmt.stringppf"network device is disconnected"endtypestats={mutablerx_bytes:int64;mutablerx_pkts:int32;mutabletx_bytes:int64;mutabletx_pkts:int32;}moduleStats=structletcreate()={rx_pkts=0l;rx_bytes=0L;tx_pkts=0l;tx_bytes=0L}letrxtsize=t.rx_pkts<-Int32.succt.rx_pkts;t.rx_bytes<-Int64.addt.rx_bytessizelettxtsize=t.tx_pkts<-Int32.succt.tx_pkts;t.tx_bytes<-Int64.addt.tx_bytessizeletresett=t.rx_bytes<-0L;t.rx_pkts<-0l;t.tx_bytes<-0L;t.tx_pkts<-0lendmoduletypeS=sigtypeerror=private[>Net.error]valpp_error:errorFmt.ttypetvaldisconnect:t->unitLwt.tvalwrite:t->size:int->(Cstruct.t->int)->(unit,error)resultLwt.tvallisten:t->header_size:int->(Cstruct.t->unitLwt.t)->(unit,error)resultLwt.tvalmac:t->Macaddr.tvalmtu:t->intvalget_stats_counters:t->statsvalreset_stats_counters:t->unitend