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

Can not convert a LLDP packet to bytes #8

Closed
UlyssesWu opened this issue Apr 19, 2016 · 3 comments
Closed

Can not convert a LLDP packet to bytes #8

UlyssesWu opened this issue Apr 19, 2016 · 3 comments

Comments

@UlyssesWu
Copy link

As description in HERE, when constructing a LLDP packet and getting bytes by calling Packet.Bytes, we will get a NullReferenceException (see the stackoverflow page for details).

And there is a workaround in that page:

var packet = LLDPPacket.RandomPacket();
var lldpBytes = packet.Bytes;
var lldpPacket = new LLDPPacket(new ByteArraySegment(lldpBytes));

After "reparsing" we can get the bytes. I think this may be a bug. also see

@chmorgan
Copy link
Collaborator

Hello. If you had a .pcap file with the least number of packets required to reproduce the issue I could use that to create a unit test and fix this issue.

@UlyssesWu
Copy link
Author

You may add a test at LldpTest.cs like this:

    [Test]
    public void AsPayloadTest()
    {
        PhysicalAddress NDP_MULTICAST =
       new PhysicalAddress(new byte[] { 0x01, 0x23, 0x20, 0x00, 0x00, 0x01 });
        LLDPPacket lldpPacket = new LLDPPacket();
        lldpPacket.TlvCollection.Add(new ChassisID(NDP_MULTICAST));
        lldpPacket.TlvCollection.Add(new PortID(PortSubTypes.PortComponent, BitConverter.GetBytes(6633)));
        lldpPacket.TlvCollection.Add(new TimeToLive(120));
        lldpPacket.TlvCollection.Add(new EndOfLLDPDU());
        // reparse these bytes back into a lldp packet
        //lldpPacket = new LLDPPacket(new ByteArraySegment(lldpPacket.Bytes));

        EthernetPacket ethernet = new EthernetPacket(NDP_MULTICAST, NDP_MULTICAST, EthernetPacketType.LLDP);
        ethernet.PayloadPacket = lldpPacket;
        var bytes = ethernet.Bytes;
        Assert.NotNull(bytes);
    }

It throws NullReferenceException. After uncomment that "reparse" line, the test would succeed. I don't know if I shouldn't call methods in that way...

@chmorgan
Copy link
Collaborator

chmorgan commented Mar 7, 2019

Hi @UlyssesWu. I'm closing this out as it has been open for a while now but we appreciate you reporting it. We would love to have a PR to help resolve this issue and add a test for this case, we just haven't had the time to resolve it here.

@chmorgan chmorgan closed this as completed Mar 7, 2019
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

No branches or pull requests

2 participants