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
0d4c2ce9
Commit
0d4c2ce9
authored
Jun 22, 2024
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add mac address struct
parent
f4cf0ec0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
4 deletions
+53
-4
mod.rs
src/etherparser/mod.rs
+3
-4
mac_address.rs
src/etherparser/net/mac_address.rs
+47
-0
mod.rs
src/etherparser/net/mod.rs
+3
-0
No files found.
src/etherparser/mod.rs
View file @
0d4c2ce9
pub
mod
ether_type
;
pub
mod
ether_type
;
pub
mod
ethernet
;
pub
mod
ethernet
;
pub
mod
packet
;
pub
mod
packet
;
pub
mod
tools
;
pub
mod
tools
;
pub
mod
net
;
pub
use
net
::
MacAddr
;
src/etherparser/net/mac_address.rs
0 → 100644
View file @
0d4c2ce9
pub
struct
MacAddr
{
mac
:
[
u8
;
6
],
}
impl
MacAddr
{
pub
fn
new
(
mac
:
[
u8
;
6
])
->
Self
{
Self
{
mac
}
}
}
impl
From
<
MacAddr
>
for
u64
{
fn
from
(
value
:
MacAddr
)
->
Self
{
let
mut
byte
:
u64
=
0
;
for
i
in
0
..
6
{
byte
=
byte
<<
8
;
byte
+=
value
.mac
[
i
]
as
u64
;
}
byte
}
}
impl
From
<
u64
>
for
MacAddr
{
fn
from
(
value
:
u64
)
->
Self
{
let
mut
mac
=
[
0u8
;
6
];
for
i
in
0
..
6
{
mac
[
i
]
=
(
value
>>
(
i
*
8
))
as
u8
;
}
Self
{
mac
}
}
}
impl
From
<&
str
>
for
MacAddr
{
fn
from
(
value
:
&
str
)
->
Self
{
let
mac_vec
=
value
.split
(
":"
)
.map
(|
x
|
match
u8
::
from_str_radix
(
x
,
16
)
{
Ok
(
v
)
=>
v
,
Err
(
_
)
=>
0
,
})
.collect
::
<
Vec
<
u8
>>
();
let
mut
mac
=
[
0u8
;
6
];
for
i
in
0
..
6
{
mac
[
i
]
=
mac_vec
[
i
];
}
Self
{
mac
}
}
}
src/etherparser/net/mod.rs
0 → 100644
View file @
0d4c2ce9
pub
mod
mac_address
;
pub
use
mac_address
::
MacAddr
;
\ No newline at end of file
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