Software Defined Networking
1827948 Members
3464 Online
109973 Solutions
New Discussion

Re: Creating a packet

 
HansChristian
Occasional Contributor

Creating a packet

Hello,

I'm able to create a packet like this:

Ethernet etherh = new Ethernet.Builder().srcAddr(smac).dstAddr(dmac).type(EthernetType.IPv4).build();
Ip iph = new Ip.Builder().srcAddr(sip).dstAddr(dip).type(IpType.TCP).build();
Tcp tcph = new Tcp.Builder().dstPort(dport).srcPort(sport).build();
Packet pkt = new Packet(etherh, iph, tcph);

But how can I add tcp data?

Could anybody please help

1 REPLY 1
ShaunWackerly
HPE Pro

Re: Creating a packet

To add TCP data, you'd likely need to specify the data as an inner "Protocol".

To specify the data as an inner protocol, you'd build a com.hp.util.pkt.UnknownProtocol, using UnknownProtocol.Builder and specifying the raw bytes you want to add in the bytes() method. Then you'd pass that UnknownProtocol to the Packet constructor just after the 'tcph' parameter.

I am an HPE Employee