package netsnmp

  1. Overview
  2. Docs
An interface to the Net-SNMP client library

Install

Dune Dependency

Authors

Maintainers

Sources

netsnmp-v0.14.0.tar.gz
sha256=91a33e407dd1f5dc42ce5aaa5a65e0d65e19b454a129603a89c31d1461abe68f
md5=ae0c0a55bf466f9eca96543f4f2578e4

doc/src/netsnmp.raw/ASN1_Bitstring.ml.html

Source file ASN1_Bitstring.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
type t = string

let to_int_list bs =
  let len = String.length bs in
  let rec f i res =
    if i >= len then List.rev res
    else f (i + 1) ((Char.code bs.[i])::res)
  in 
    f 0 []

let to_hex_string ?(sep=" ") bs =
  to_int_list bs
  |> List.map (fun v -> Printf.sprintf "%02X" v)
  |> String.concat sep

let to_bit_list bs = 
  let masks = [ 0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01 ] in
  let octet_bits off octet =
    List.mapi (fun i m -> if (octet land m) > 0 then off + i else -1) masks
    |> List.filter (fun v -> v >= 0)
  in
    to_int_list bs
    |> List.mapi (fun i v -> octet_bits (i*8) v)
    |> List.concat

let to_string bs =
  let hex = to_hex_string bs in
  let bits = to_bit_list bs
    |> List.map (Printf.sprintf "%d")
    |> String.concat " "
  in
    if String.length bits > 0 then hex ^ " BITS(" ^ bits ^ ")"
    else hex
OCaml

Innovation. Community. Security.