Skip to content

Instantly share code, notes, and snippets.

@yomimono
Created February 23, 2015 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yomimono/e2a8e2988284a0362179 to your computer and use it in GitHub Desktop.
Save yomimono/e2a8e2988284a0362179 to your computer and use it in GitHub Desktop.
stackv4.create_connection fails with statically configured interface
open Lwt
open V1_LWT
module Main (C: V1_LWT.CONSOLE) (CLIENT_STACK: V1_LWT.STACKV4) = struct
let local_webserver="8.8.8.8"
let port = 5162
let start c client_stack =
let construct_request () =
let buf = Io_page.(to_cstruct (get 1)) in
let output = (Printf.sprintf "land of adventure !!") in
Cstruct.blit_from_string output 0 buf 0 (String.length output);
Cstruct.set_len buf (String.length output)
in
let rec make_connection c s =
let my_tcpv4 = (CLIENT_STACK.tcpv4 s) in
let webserver = local_webserver in
CLIENT_STACK.TCPV4.create_connection my_tcpv4 ((Ipaddr.V4.of_string_exn webserver),
port) >>=
fun conn -> (
match conn with
| `Ok (outbound : CLIENT_STACK.TCPV4.flow) ->
let request = construct_request () in
CLIENT_STACK.TCPV4.write outbound request >>
CLIENT_STACK.TCPV4.read outbound >>= fun read_data -> (
match read_data with
| `Ok buffer -> (Cstruct.hexdump buffer); return ()
| _ -> return ()
) >>= fun () ->
CLIENT_STACK.TCPV4.close outbound
| p ->
C.log c (Printf.sprintf "Couldn't initiate connection to %s:%d ;
giving up\n" webserver port);
Lwt.return_unit
)
in
make_connection c client_stack
end
open Mirage
let main = foreign "Client.Main" (console @-> stackv4 @-> job)
let ip = {
address = Ipaddr.V4.of_string_exn "192.168.3.234";
netmask = Ipaddr.V4.of_string_exn "255.255.255.0";
gateways = [ Ipaddr.V4.of_string_exn "192.168.3.1"]
}
let stack console = direct_stackv4_with_static_ipv4 console tap0 ip
(* direct_stackv4_with_dhcp console tap0 *)
let () =
register "client" (* ~tracing *) [
main $ default_console $ stack default_console
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment