-
Notifications
You must be signed in to change notification settings - Fork 93
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
How to create a Packet without parent? #92
Comments
Hey, I'm on the bus right now but may find some time later but check out the unit tests, there should be complete examples of how to create a full Packet, all the way from layer 7 and down. |
@aboutsip thanks |
I found. The unit test code is in folder pkts-core/src/test/java/io/pkts/packet/impl/, seems like there's a TransportPacketFactory to use. |
@aboutsip I try to invoke the PacketFactory.getInstance().getTransportFactory().create(...), but the packet will be UDP whatever the protocol you pass into the arguments, I see the method detail, like this: public TransportPacket create(Protocol protocol, byte[] srcAddress, int srcPort, byte[] destAddress, int destPort, Buffer payload) throws IllegalArgumentException, IllegalProtocolException {
TransportPacket pkt = this.createUdpInternal(payload);
IPv4Packet ipPkt = (IPv4Packet)pkt.getParentPacket();
ipPkt.setSourceIP(srcAddress[0], srcAddress[1], srcAddress[2], srcAddress[3]);
ipPkt.setDestinationIP(destAddress[0], destAddress[1], destAddress[2], destAddress[3]);
pkt.setDestinationPort(destPort);
pkt.setSourcePort(srcPort);
ipPkt.reCalculateChecksum();
return pkt;
} seems like the Protocol protocol argument won't be used in this method, and all packet will be create by private method createUdpInternal method, Is there something not right? I may need to create a packet base IP and not base UDP. |
I used to changed the Buffer payload value of the create method which is a argument. the protocol which display in wireshark of the pcap file seems like will be judge by the buffer format, not judged by Protocol arguments. |
Hi, I'm working. Sorry to distrub again.
I wanna create a PcapOutputStream instance and invoke it's write method to write a packet into which is a Ipv4 packet.
When I try to init a packet, the Packet constructor request me to pass a parent packet instance as Argument, but I don't know where is the parent packet can init and the parent packet don't need pass a parent packet argument.
Because I want to create a new pcap file by PcapOutputStream, but I don't know if there's a factory or defaultImpl way to init a parent packet or a create packet correct way, Could you offer a example like unit test code? Thanks!
The text was updated successfully, but these errors were encountered: