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_interface_description_block). |
16 |
|
-export([parse/2]). |
17 |
|
-export([if_filter/1]). |
18 |
|
|
19 |
|
-spec parse(binary(), fun((binary()) -> integer())) -> map(). |
20 |
|
parse(Body, I) -> |
21 |
13 |
<< |
22 |
|
LinkType:16/bits, |
23 |
|
_:16/bits, |
24 |
|
SnapLen:32/bits, |
25 |
|
Options/binary |
26 |
|
>> = Body, |
27 |
|
|
28 |
13 |
#{type => interface_description, |
29 |
|
link_type => maps:get(I(LinkType), link_types(), I(LinkType)), |
30 |
|
snap_len => I(SnapLen), |
31 |
|
options => pcapng_options:parse(Options, I, options()) |
32 |
|
}. |
33 |
|
|
34 |
|
if_filter(<<0:8, Filter/binary>>) -> |
35 |
4 |
Filter. |
36 |
|
|
37 |
|
|
38 |
|
options() -> |
39 |
13 |
#{2 => if_name, |
40 |
|
3 => {if_description, #{module => pcapng_options, |
41 |
|
function => null_terminated}}, |
42 |
|
4 => if_ip_v4_addr, |
43 |
|
5 => if_ip_v6_addr, |
44 |
|
6 => if_mac_addr, |
45 |
|
7 => if_eui_addr, |
46 |
|
8 => if_speed, |
47 |
|
9 => if_tsresol, |
48 |
|
10 => if_tzone, |
49 |
|
11 => {if_filter, #{module => pcapng_interface_description_block, |
50 |
|
function => if_filter}}, |
51 |
|
12 => if_os, |
52 |
|
13 => if_fcslen, |
53 |
|
14 => if_tsoffset |
54 |
|
}. |
55 |
|
|
56 |
|
link_types() -> |
57 |
13 |
#{0 => null, |
58 |
|
1 => ethernet, |
59 |
|
2 => exp_ethernet, |
60 |
|
3 => ax25, |
61 |
|
4 => pronet, |
62 |
|
5 => chaos, |
63 |
|
6 => token_ring, |
64 |
|
7 => arcnet, |
65 |
|
8 => slip, |
66 |
|
9 => ppp, |
67 |
|
10 => fddi, |
68 |
|
50 => ppp_hdlc, |
69 |
|
51 => ppp_ether, |
70 |
|
99 => symantec_firewall, |
71 |
|
100 => atm_rfc1483, |
72 |
|
101 => raw, |
73 |
|
102 => slip_bsdos, |
74 |
|
103 => ppp_bsdos, |
75 |
|
104 => c_hdlc, |
76 |
|
105 => ieee802_11, |
77 |
|
106 => atm_clip, |
78 |
|
107 => frelay, |
79 |
|
108 => loop, |
80 |
|
109 => enc, |
81 |
|
110 => lane8023, |
82 |
|
111 => hippi, |
83 |
|
112 => hdlc, |
84 |
|
113 => linux_sll, |
85 |
|
114 => ltalk, |
86 |
|
115 => econet, |
87 |
|
116 => ipfilter, |
88 |
|
117 => pflog, |
89 |
|
118 => cisco_ios, |
90 |
|
119 => prism_header, |
91 |
|
120 => aironet_header, |
92 |
|
121 => hhdlc, |
93 |
|
122 => ip_over_fc, |
94 |
|
123 => sunatm, |
95 |
|
124 => rio, |
96 |
|
125 => pci_exp, |
97 |
|
126 => aurora, |
98 |
|
127 => ieee802_11_radio, |
99 |
|
128 => tzsp, |
100 |
|
129 => arcnet_linux, |
101 |
|
130 => juniper_mlppp, |
102 |
|
131 => juniper_mlfr, |
103 |
|
132 => juniper_es, |
104 |
|
133 => juniper_ggsn, |
105 |
|
134 => juniper_mfr, |
106 |
|
135 => juniper_atm2, |
107 |
|
136 => juniper_services, |
108 |
|
137 => juniper_atm1, |
109 |
|
138 => apple_ip_over_ieee1394, |
110 |
|
139 => mtp2_with_phdr, |
111 |
|
140 => mtp2, |
112 |
|
141 => mtp3, |
113 |
|
142 => sccp, |
114 |
|
143 => docsis, |
115 |
|
144 => linux_irda, |
116 |
|
145 => ibm_sp, |
117 |
|
146 => ibm_sn}. |