Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
Tenjin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
Tenjin
Commits
dac40824
Commit
dac40824
authored
Jun 16, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
arp: remove unwrap
parent
228d23b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
16 deletions
+16
-16
ethernet.rs
src/etherparser/ethernet.rs
+2
-2
arp.rs
src/etherparser/packet/arp.rs
+14
-14
No files found.
src/etherparser/ethernet.rs
View file @
dac40824
...
@@ -52,8 +52,8 @@ impl EthernetFrame {
...
@@ -52,8 +52,8 @@ impl EthernetFrame {
tp
if
tp
==
(
EtherType
::
ARP
as
u16
)
=>
{
tp
if
tp
==
(
EtherType
::
ARP
as
u16
)
=>
{
let
arp
=
ARP
::
parse
(
&
mut
bytes
);
let
arp
=
ARP
::
parse
(
&
mut
bytes
);
match
arp
{
match
arp
{
Some
(
arp
)
=>
Network
::
ARP
(
arp
),
Ok
(
arp
)
=>
Network
::
ARP
(
arp
),
None
=>
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
?
.to_vec
()),
Err
(
_
)
=>
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
?
.to_vec
()),
}
}
}
}
_
=>
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
?
.to_vec
()),
_
=>
Network
::
Unparsable
(
typ
,
bytes
.fill_buf
()
?
.to_vec
()),
...
...
src/etherparser/packet/arp.rs
View file @
dac40824
use
std
::
io
::
Cursor
;
use
std
::
io
::
{
Cursor
,
Error
,
ErrorKind
}
;
use
byteorder
::{
BigEndian
,
ReadBytesExt
};
use
byteorder
::{
BigEndian
,
ReadBytesExt
};
...
@@ -26,35 +26,35 @@ impl ARP {
...
@@ -26,35 +26,35 @@ impl ARP {
pub
fn
size_of
()
->
usize
{
pub
fn
size_of
()
->
usize
{
28
28
}
}
pub
fn
parse
(
bytes
:
&
mut
Cursor
<
Vec
<
u8
>>
)
->
Option
<
ARP
>
{
pub
fn
parse
(
bytes
:
&
mut
Cursor
<
Vec
<
u8
>>
)
->
Result
<
ARP
,
Error
>
{
if
bytes
.get_ref
()
.len
()
<
ARP
::
size_of
()
{
if
bytes
.get_ref
()
.len
()
<
ARP
::
size_of
()
{
return
None
;
return
Err
(
Error
::
new
(
ErrorKind
::
Other
,
"arp len wrong"
))
;
}
}
let
hardware_type
=
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
()
;
let
hardware_type
=
bytes
.read_u16
::
<
BigEndian
>
()
?
;
let
protocol_type
=
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
()
;
let
protocol_type
=
bytes
.read_u16
::
<
BigEndian
>
()
?
;
let
hardware_length
=
bytes
.read_u8
()
.unwrap
()
;
let
hardware_length
=
bytes
.read_u8
()
?
;
let
protocol_length
=
bytes
.read_u8
()
.unwrap
()
;
let
protocol_length
=
bytes
.read_u8
()
?
;
let
operation
=
match
bytes
.read_u16
::
<
BigEndian
>
()
.unwrap
()
{
let
operation
=
match
bytes
.read_u16
::
<
BigEndian
>
()
?
{
0x0001
=>
ArpOperation
::
Query
,
0x0001
=>
ArpOperation
::
Query
,
0x0002
=>
ArpOperation
::
Reply
,
0x0002
=>
ArpOperation
::
Reply
,
_
=>
ArpOperation
::
Unparse
,
_
=>
ArpOperation
::
Unparse
,
};
};
if
let
ArpOperation
::
Unparse
=
operation
{
if
let
ArpOperation
::
Unparse
=
operation
{
return
None
;
return
Err
(
Error
::
new
(
ErrorKind
::
Other
,
"arp unparse"
))
;
}
}
let
mut
sender_mac
=
[
0u8
;
6
];
let
mut
sender_mac
=
[
0u8
;
6
];
for
i
in
0
..
6
{
for
i
in
0
..
6
{
sender_mac
[
i
]
=
bytes
.read_u8
()
.unwrap
()
;
sender_mac
[
i
]
=
bytes
.read_u8
()
?
;
}
}
let
sender_address
=
bytes
.read_u32
::
<
BigEndian
>
()
.unwrap
()
;
let
sender_address
=
bytes
.read_u32
::
<
BigEndian
>
()
?
;
let
mut
target_mac
=
[
0u8
;
6
];
let
mut
target_mac
=
[
0u8
;
6
];
for
i
in
0
..
6
{
for
i
in
0
..
6
{
target_mac
[
i
]
=
bytes
.read_u8
()
.unwrap
()
;
target_mac
[
i
]
=
bytes
.read_u8
()
?
;
}
}
let
target_address
=
bytes
.read_u32
::
<
BigEndian
>
()
.unwrap
()
;
let
target_address
=
bytes
.read_u32
::
<
BigEndian
>
()
?
;
Some
(
ARP
{
Ok
(
ARP
{
hardware_type
,
hardware_type
,
protocol_type
,
protocol_type
,
hardware_length
,
hardware_length
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment