Permalink
Browse files

Add start/stop functions

As a convenience (for typing), add start/0 and start/1. Add a stop/0
function as well. Update the docs.
  • Loading branch information...
1 parent 5b5be30 commit be109e20a63c3153e02114699f3a6deadd00b6df @msantos committed Sep 17, 2010
Showing with 18 additions and 10 deletions.
  1. +5 −10 README
  2. +13 −0 src/perv.erl
View
15 README
@@ -22,8 +22,8 @@ make
HOW TO USE IT
-perv:start_link() -> ok
-perv:start_link(Options) -> ok
+perv:start() -> ok
+perv:start(Options) -> ok
Types Options = list()
@@ -59,19 +59,19 @@ EXAMPLES
* To start sniffing, specify the interface to use:
-> perv:start_link([{interface, "eth0"}]).
+> perv:start([{interface, "eth0"}]).
* By default, all traffic on port 80 is captured. If you want to exclude
your IP address, modify the pcap filter. For example, if you are using
the device "en1" with an IP address of "192.168.10.11":
-> perv:start_link([{interface, "en1"}, {filter, "tcp and port 80 and not 192.168.10.11"}]).
+> perv:start([{interface, "en1"}, {filter, "tcp and port 80 and not 192.168.10.11"}]).
* To replay data from a pcap file (for example, captured using tcpdump):
-> perv:start_link([{file, "/path/to/file.pcap"}]).
+> perv:start([{file, "/path/to/file.pcap"}]).
* perv includes a very basic web interface:
@@ -99,11 +99,6 @@ TODO
* pervon:content/3 should return a list of tuples containing the name,
file type and file contents, rather than writing them directly to disk
-* file chunks are still occassionally dropped (Content-Length
- header does not match the body size), for example, when playing
- Flash video. Figure out where this is happening and see if it can be
- fixed. Might be a regression, since it was working reliably previously.
-
* since the interface being snooped is known, grab the device's IP
address using inet:ifget/2. Provide an option for including/excluding
the user's address.
View
@@ -36,6 +36,7 @@
-define(SERVER, ?MODULE).
+-export([start/0, start/1, stop/0]).
-export([start_link/0, start_link/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
@@ -50,6 +51,14 @@
{chroot, "priv/tmp"}]).
+start() ->
+ start_link().
+start(EpcapArg) ->
+ start_link(EpcapArg).
+
+stop() ->
+ gen_server:call(?SERVER, [stop]).
+
start_link() ->
start_link([]).
@@ -61,6 +70,10 @@ init([EpcapArg]) ->
{ok, #state{c = dict:new()}}.
+handle_call(stop, _From, #state{c = C} = State) ->
+ epcap:stop(),
+ [ pervon:stop(V) || {_,V} <- dict:to_list(C) ],
+ {stop, shutdown, ok, State};
handle_call(_Request, _From, State) ->
{reply, ok, State}.

0 comments on commit be109e2

Please sign in to comment.