File: pcap_loop.ml

package info (click to toggle)
mlpcap 0.9-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,324 kB
  • sloc: sh: 1,302; ansic: 143; ml: 94; makefile: 48
file content (36 lines) | stat: -rw-r--r-- 802 bytes parent folder | download | duplicates (9)
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
34
35
36
open Pcap

(* looking up suitable device *)
let (a) = pcap_lookupdev ();;

(* open it in promiscous mode *)
let openlive = pcap_open_live a 1500 1 0;;

Printf.printf "[+] opening interface %s ...\n" a ; flush_all ();;
	
(* callback ... *)
let callbkfun (s:string) (h:pcap_pkthdr) (t:string) =
	print_endline "[-] Entered callbkfun.\n";
	Printf.printf "timestamp: %u\n" (h.ts.tv_sec);
		let proto = (int_of_char (String.unsafe_get t 23)) in
	match proto with
	| 6 -> Printf.printf "-> TCP\n"
	| 1 -> Printf.printf "-> ICMP\n"
	| 17 -> Printf.printf "-> UDP\n"
	| _ -> Printf.printf "-> Unknown\n";;



let pcap_loop_test () =
	for i = 0 to 20 do
        begin
		let x = pcap_loop openlive 1 callbkfun "" in flush_all ()
        end
	done;;


let () = pcap_loop_test ();;

let () = pcap_close openlive