Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ the packets in the file.

Examples
--------

```erlang
48> {ok,FD}=pran:open_file("mtp2.pcap", "").
{ok,<0.152.0>}
49> pran:read(FD).
Expand All @@ -37,7 +37,7 @@ Examples
1,17,19,...>>}]
51> pran:close(FD).
ok

```
Protocols
---------

Expand Down
153 changes: 0 additions & 153 deletions src/elibpcap.erl

This file was deleted.

11 changes: 11 additions & 0 deletions src/pran.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{application, pran,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{env, []}
]}.
14 changes: 11 additions & 3 deletions src/pran.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
%%%-------------------------------------------------------------------
-module(pran).

-compile(export_all).

%% API
-export([open_file/2,
open_file_from_ram/2,
read/1,
close/1,
grep_file/2]).
Expand All @@ -31,7 +30,16 @@ open_file(File, Pat) when is_binary(Pat) ->
open_file(File, {filters,[{pcap,{contain,CP}}]});
open_file(File, Filter) when is_tuple(Filter) ->
Opts = pran_utils:load_config(),
{ok,_FD}=pran_pcap_file:open(File, [Filter|Opts]).
{ok,_FD}=pran_pcap_file:open(File, disk, [Filter|Opts]).

open_file_from_ram(File, Pat) when is_list(Pat) ->
open_file_from_ram(File, list_to_binary(Pat));
open_file_from_ram(File, Pat) when is_binary(Pat) ->
CP = pran_utils:mk_pattern(Pat),
open_file_from_ram(File, {filters,[{pcap,{contain,CP}}]});
open_file_from_ram(File, Filter) when is_tuple(Filter) ->
Opts = pran_utils:load_config(),
{ok,_FD}=pran_pcap_file:open(File, memory, [Filter|Opts]).

read(FD) ->
pran_pcap_file:read(FD).
Expand Down
26 changes: 17 additions & 9 deletions src/pran_pcap_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-behaviour(gen_server).

%% API
-export([open/2,
-export([open/3,
read/1,
close/1]).

Expand Down Expand Up @@ -44,8 +44,8 @@
%% Function: open() -> {ok,Pid} | ignore | {error,Error}
%% Description: Starts the server
%%--------------------------------------------------------------------
open(File, Opts) ->
gen_server:start_link(?MODULE, [File,Opts], []).
open(File, Type, Opts) ->
gen_server:start_link(?MODULE, [File, Type, Opts], []).

read(Fd) ->
gen_server:call(Fd,read).
Expand All @@ -64,11 +64,19 @@ close(Fd) ->
%% {stop, Reason}
%% Description: Initiates the server
%%--------------------------------------------------------------------
init([File,Opts]) ->
init([File, Type, Opts]) ->
Decoders = proplists:get_value(decoders, Opts),
Filters = proplists:get_value(filters, Opts, []),
{ok, Fd} = file:open(File, [read, raw, binary]),
{ok, Bin} = file:pread(Fd, 0, ?BLOCKSIZE),
{Fd, Bin} = case Type of
disk ->
{ok, F} = file:open(File, [read, raw, binary]),
{ok, B} = file:pread(F, 0, ?BLOCKSIZE),
{F, B};
memory ->
{ok, F} = file:open(File, [ram, read, binary]),
{ok, B} = file:pread(F, 0, ?BLOCKSIZE),
{F, B}
end,
case pran_pcap:file_header(Bin) of
{#file_hdr{order = Endian,
major = _Major, minor = _Minor,
Expand Down Expand Up @@ -188,13 +196,13 @@ read_block(#state{fd=Fd, offset=Offset}=State) ->
%%--------------------------------------------------------------------
test_read_file(File) ->
et:trace_me(80, test_read_frames,pcap_file,open,[]),
{ok,Pid} = open(File,[]),
{ok,Pid} = open(File, disk, []),
F=read(Pid),
test_read_frames(F,Pid).

test_read_frames(eof,Pid) ->
test_read_frames(eof,_Pid) ->
ok;
test_read_frames(F,Pid) ->
test_read_frames(_F,Pid) ->
et:trace_me(80, test_read_frames,pcap_file,read,[]),
F1=read(Pid),
test_read_frames(F1,Pid).
109 changes: 0 additions & 109 deletions src/pran_tcap.erl

This file was deleted.