libpnet / libpnet/libpnet

rustc(E0515) when trying to use icmp_packet_iter.next()

Open
#588 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.6k
Forks
329
PR merge metrics
No merged PRs in 30d

Description

Apologies if this is a Rust noob question.

I am trying to return the first reply packet from a Layer4(Ipv4(IpNextHeaderProtocols::Icmp)) transport_channel.

The end of my function is:

    let mut rx_iter = icmp_packet_iter(&mut rx);
    rx_iter.next()

And I get the following errors:

error[E0515]: cannot return reference to local variable `rx_iter`
  --> src\main.rs:29:5
   |
29 |     rx_iter.next()
   |     ^^^^^^^^^^^^^^ returns a reference to data owned by the current function

error[E0515]: cannot return value referencing local variable `rx`
  --> src\main.rs:29:5
   |
28 |     let mut rx_iter = icmp_packet_iter(&mut rx);
   |                                        ------- `rx` is borrowed here
29 |     rx_iter.next()
   |     ^^^^^^^^^^^^^^ returns a value referencing data owned by the current function

The official advice is to "consider returning an owned value instead". How should I do it?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/main.rs at the transport_channel setup and the icmp_packet_iter call, then check the iterator's return type and lifetime against Rust's E0515 guidance. Determine an owned return value that does not borrow local rx or rx_iter, and verify that it represents the first received ICMP reply.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.