Permalink
Browse files

add ping test

  • Loading branch information...
avsm committed Sep 21, 2011
1 parent 10b1ce9 commit 468cc29f06e88d4dae496f0d68eb047e85df9b12
Showing with 40 additions and 0 deletions.
  1. +7 −0 examples/net/ping/Makefile
  2. +33 −0 examples/net/ping/ping.ml
@@ -0,0 +1,7 @@
+run:
+ mir-build unix-direct/ping.bin
+ sudo ./_build/unix-direct/ping.bin
+
+clean:
+ mir-build -clean
+ rm -f myocamlbuild.ml
View
@@ -0,0 +1,33 @@
+(*
+ * Copyright (c) 2011 Richard Mortier <mort@cantab.net>
+ *
+ * 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.
+ *)
+
+open Lwt
+open Printf
+
+let main () =
+ Log.info "Ping" "starting server";
+ Net.Manager.create (fun mgr interface id ->
+ let ip = Net.Nettypes.(
+ (ipv4_addr_of_tuple (10l,0l,0l,2l),
+ ipv4_addr_of_tuple (255l,255l,255l,0l),
+ [ ipv4_addr_of_tuple (10l,0l,0l,1l) ]
+ ))
+ in
+ lwt () = Net.Manager.configure interface (`IPv4 ip) in
+ let icmp_t, th = Net.Icmp.create (Net.Manager.ipv4_of_interface interface) in
+ Log.info "Ping" "Bring the pings!\n%!";
+ th
+ )

0 comments on commit 468cc29

Please sign in to comment.