coq-ssh/coq_ssh.ml

38 lines
1 KiB
OCaml
Raw Normal View History

2021-06-11 05:07:55 +00:00
open Unix
open Printf
open CoqSSH
let () =
let addr_str = "10.7.0.4" in
let socket_fd = socket PF_INET SOCK_STREAM 0 in
let inet_addr = inet_addr_of_string addr_str in
let sock_addr = ADDR_INET (inet_addr, 22) in
connect socket_fd sock_addr;
printf "Connected to %s.\n" addr_str;
(* protocol negotiation *)
let hello = "2.0 Hellosu\r\n" |> Bytes.of_string in
let bytes_written = write socket_fd hello 0 (Bytes.length hello) in
printf "Sent greeting (%d bytes).\n" bytes_written;
let buf = Bytes.create 1024 in
let bytes_read = read socket_fd buf 0 1024 in
let actual = Bytes.sub buf 0 bytes_read |> Bytes.to_string in
printf "Read '%s' (%d bytes).\n" actual bytes_read;
let version = "SSH-2.0-CoqSSH0.1 Coggers\r\n" |> Bytes.of_string in
let bytes_written = write socket_fd version 0 (Bytes.length version) in
printf "Sent protocol version (%d bytes).\n" bytes_written;
(* key exchange *)
let n : SSH.nat = SSH.O in
match n with
| SSH.O -> print_endline "o"
| _ -> ();
close socket_fd;