_site/cover/pcapng_ethernet.COVER.html

1 %% Copyright (c) 2015 Peter Morgan <peter.james.morgan@gmail.com>
2 %%
3 %% Licensed under the Apache License, Version 2.0 (the "License");
4 %% you may not use this file except in compliance with the License.
5 %% You may obtain a copy of the License at
6 %%
7 %% http://www.apache.org/licenses/LICENSE-2.0
8 %%
9 %% Unless required by applicable law or agreed to in writing, software
10 %% distributed under the License is distributed on an "AS IS" BASIS,
11 %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 %% See the License for the specific language governing permissions and
13 %% limitations under the License.
14
15 -module(pcapng_ethernet).
16 -export([decode/1]).
17
18 -define(IPV4, 16#0800).
19 -define(IPV6, 16#86DD).
20 -define(ARP, 16#0806).
21
22 decode(<<_:48, _:48, ?IPV4:16, _/binary>> = Frame) ->
23 1506 decode(Frame, ip, pcapng_ip);
24
25 decode(<<_:48, _:48, ?IPV6:16, _/binary>> = Frame) ->
26 11 decode(Frame, ip, pcapng_ip);
27
28 decode(<<_:48, _:48, ?ARP:16, _/binary>> = Frame) ->
29 6 decode(Frame, arp, pcapng_arp);
30 decode(Frame) ->
31 1 #{unknown => Frame}.
32
33
34
35 decode(<<Destination:48, Source:48, _:16, IP/binary>>, Protocol, Decoder) ->
36 1523 #{Protocol => Decoder:decode(IP),
37 destination => integer_to_binary(Destination, 16),
38 source => integer_to_binary(Source, 16)}.
Line Hits Source