package core_unix

  1. Overview
  2. Docs
Unix-specific portions of Core

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.1.tar.gz
md5=9370dca36f518fcea046d2752e3de22b
sha512=c4e8ce9d5885ac8fa8d554a97e1857f3a1c933e0eb5dfd4fe874412b9d09e6d0a2973b644733855553f33f5c859719228f0e6aaf3a2b7eb5befb46fc513750de

doc/src/core_unix.process_env/process_env.ml.html

Source file process_env.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
open! Core
open! Import
module Unix = Core_unix

let ssh_client_var = "SSH_CLIENT"

let parse_ssh_client_var = function
  | None -> Ok `Nowhere
  | Some s ->
    (match String.split ~on:' ' s with
     | [] -> failwith "This should never happen, empty string splits as [\"\"]"
     (* Allow any SSH_CLIENT var containing an IP address as the first element.
        Normally, it should have three parts, but relaxing this constraint helps
        debugging/troubleshooting easier. *)
     | address :: _ ->
       Or_error.try_with (fun () -> `From (Unix.Inet_addr.of_string address))
       |> fun e ->
       Or_error.tag_arg e "Could not parse IP address in SSH_CLIENT" s [%sexp_of: string])
;;

let parse_ssh_client () = parse_ssh_client_var (Sys.getenv ssh_client_var)

module Private = struct
  let parse_ssh_client_var = parse_ssh_client_var
end
OCaml

Innovation. Community. Security.