Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 487 #557

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: Bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps of Code to reproduce the behavior:

**Expected behavior**
A clear and concise description of what you expected to happen.

**Error Snippet**
If applicable, add screenshots or snippets to help explain your problem.

**Environment (please complete the following information):**
- OS: [e.g. Windows, Mac, Linux]
- Version [e.g. 10, 12.3.1, Buster]

**Rust Environment (please complete the following information):**
- Version: [e.g. 1.60.0]
- Toolchain: [e.g. stable-x86_64-unknown-linux-gnu, nightly-x86_64-apple-darwin]
- Version of Libpnet [e.g. 0.27.1, 0.29.0]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for adding these!

name: Feature request
about: Suggest an idea for this project
title: "[Feature]"
labels: Feature Request
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Rust

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this,libpnet still uses master.

I'm happy to change this, but it should be separate from this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change this

branches: [ main ]

env:
CARGO_TERM_COLOR: always
Expand Down
12 changes: 12 additions & 0 deletions pnet_base/src/macaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ pub struct MacAddr(pub u8, pub u8, pub u8, pub u8, pub u8, pub u8);

impl MacAddr {
/// Construct a new `MacAddr` instance.
#[inline]
pub fn new(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8) -> MacAddr {
MacAddr(a, b, c, d, e, f)
}

/// Construct an all-zero `MacAddr` instance.
#[inline]
pub fn zero() -> MacAddr {
Default::default()
}
Expand Down Expand Up @@ -78,21 +80,25 @@ impl MacAddr {
pub fn octets(&self) -> [u8; 6] {
[self.0, self.1, self.2, self.3, self.4, self.5]
}

}

impl From<EtherAddr> for MacAddr {
#[inline]
fn from(addr: EtherAddr) -> MacAddr {
MacAddr(addr[0], addr[1], addr[2], addr[3], addr[4], addr[5])
}
}

impl From<MacAddr> for EtherAddr {
#[inline]
fn from(addr: MacAddr) -> Self {
[addr.0, addr.1, addr.2, addr.3, addr.4, addr.5]
}
}

impl PartialEq<EtherAddr> for MacAddr {
#[inline]
fn eq(&self, other: &EtherAddr) -> bool {
*self == MacAddr::from(*other)
}
Expand All @@ -114,6 +120,7 @@ impl Serialize for MacAddr {
///
/// It serializes either to a string or its binary representation, depending on what the format
/// prefers.
#[inline]
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
if serializer.is_human_readable() {
serializer.collect_str(self)
Expand All @@ -130,15 +137,18 @@ impl<'de> Deserialize<'de> for MacAddr {
/// It deserializes it from either a byte array (of size 6) or a string. If the format is
/// self-descriptive (like JSON or MessagePack), it auto-detects it. If not, it obeys the
/// human-readable property of the deserializer.
#[inline]
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct MacAddrVisitor;
impl<'de> de::Visitor<'de> for MacAddrVisitor {
type Value = MacAddr;

#[inline]
fn visit_str<E: de::Error>(self, value: &str) -> Result<MacAddr, E> {
value.parse().map_err(|err| E::custom(err))
}

#[inline]
fn visit_bytes<E: de::Error>(self, v: &[u8]) -> Result<MacAddr, E> {
if v.len() == 6 {
Ok(MacAddr::new(v[0], v[1], v[2], v[3], v[4], v[5]))
Expand All @@ -147,6 +157,7 @@ impl<'de> Deserialize<'de> for MacAddr {
}
}

#[inline]
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(
formatter,
Expand Down Expand Up @@ -202,6 +213,7 @@ impl fmt::Display for ParseMacAddrErr {

impl FromStr for MacAddr {
type Err = ParseMacAddrErr;
#[inline]
fn from_str(s: &str) -> Result<MacAddr, ParseMacAddrErr> {
let mut parts = [0u8; 6];
let splits = s.split(':');
Expand Down