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

get MacAddr octets as fixed-size array #478

Merged
merged 1 commit into from
May 9, 2021
Merged

get MacAddr octets as fixed-size array #478

merged 1 commit into from
May 9, 2021

Conversation

jonlil
Copy link
Contributor

@jonlil jonlil commented Mar 26, 2021

Hello,

This is my first pull request in the Rust community. A common thing when working with network protocol e.g. UdpSocket is to compose byte slices. This new helper method provides a better interface for accessing the internal data of the mac address.

For example

Before

let mac_addr = MacAddr(0x00, 0x00, 0x00, 0x01, 0x01, 0x01);
let mut buffer = Vec::with_capacity(6);

buffer.extend_from_slice(&[mac_addr.0, mac_addr.1, mac_addr.2, mac_addr.3, mac_addr.4, mac_addr.5]);

After

let mac_addr = MacAddr(0x00, 0x00, 0x00, 0x01, 0x01, 0x01);
let mut buffer = Vec::with_capacity(6);

buffer.extend_from_slice(&mac_addr.octets());

@mrmonday
Copy link
Contributor

mrmonday commented May 9, 2021

I like it!

Thanks.

@mrmonday mrmonday merged commit 14763b0 into libpnet:master May 9, 2021
@mrmonday
Copy link
Contributor

mrmonday commented May 9, 2021

I'm sorry it took so long to get around to.

@stappersg
Copy link
Contributor

stappersg commented May 9, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants