-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Writing to a dump file #291
Comments
Were you ever able to figure this out? |
I seem to have accomplished this with the following:
Obviously exception handling is weak ... just a prototype. |
I'm back on this, so I'll let you know how I fare. |
@rjo I gave that a shot with 1.8.2 and this was logged
|
That looks like its coming from someplace deeper in your code that the dump part |
@rjo does the |
I dont think it does as that would not accomodate variable length packets. The snap length is about capturing anyway. I don't think it would have an impact on what you're doing and I would just set it to 65535. |
Ok, I'll set that back to 65535; I read through some of the unit tests and came up with for my write section; the issue is that the pcap doesn't show the proper sizes for the packets when I view them in wireshark; this is my write section: UnknownPacket.Builder rtpPktBuilder = new UnknownPacket.Builder();
rtpPktBuilder.rawData(p.data);
UdpPacket.Builder uPktBuilder = new UdpPacket.Builder();
uPktBuilder.srcAddr(srcAddr).srcPort(srcPort).dstAddr(dstAddr).dstPort(dstPort)
.payloadBuilder(rtpPktBuilder).correctChecksumAtBuild(true).correctLengthAtBuild(true);
IpV6Packet.Builder IpV6PktBuilder = new IpV6Packet.Builder();
IpV6PktBuilder.version(IpVersion.IPV6).trafficClass(IpV6SimpleTrafficClass.newInstance((byte) 0x12))
.flowLabel(IpV6SimpleFlowLabel.newInstance(0x12345)).nextHeader(IpNumber.UDP).hopLimit((byte) 100)
.srcAddr(srcAddr).dstAddr(dstAddr).payloadBuilder(uPktBuilder).correctLengthAtBuild(true);
EthernetPacket.Builder ethPktBuilder = new EthernetPacket.Builder();
ethPktBuilder.dstAddr(MacAddress.getByName("fe:00:00:00:00:02"))
.srcAddr(MacAddress.getByName("fe:00:00:00:00:01")).type(EtherType.IPV6)
.payloadBuilder(IpV6PktBuilder).paddingAtBuild(true);
EthernetPacket ethPkt = ethPktBuilder.build();
pcapWriter.dump(ethPkt, Instant.now()); It'd be awesome if there was an |
I've now got data that wireshark seems to mostly understand, but my data can't be decoded as RTP, so I'm stuck. Anyone know what might wrong by looking at this image? //init section
try {
handle = Pcaps.openDead(DataLinkType.EN10MB, 65535);
pcapWriter = handle.dumpOpen(String.format("%s/%s.pcap", currentPath.toAbsolutePath().toString(), name));
srcAddr = (Inet4Address) InetAddress.getByName("192.168.0.1");
dstAddr = (Inet4Address) InetAddress.getByName("192.168.0.2");
srcPort = UdpPort.getInstance((short) 49152);
dstPort = UdpPort.getInstance((short) 49153);
} catch (Exception e) {
log.error("PcapException", e);
}
//write section
try {
UnknownPacket rtpPkt = UnknownPacket.newPacket(p.data, 0, p.data.length);
log.debug("Writing {} rtp bytes pt: {} {}", p.length, p.payloadType, rtpPkt);
UdpPacket.Builder uPktBuilder = new UdpPacket.Builder();
uPktBuilder.srcAddr(srcAddr).srcPort(srcPort).dstAddr(dstAddr).dstPort(dstPort)
.payloadBuilder(rtpPkt.getBuilder()).correctChecksumAtBuild(true).correctLengthAtBuild(true);
IpV4Packet.Builder IpPktBuilder = new IpV4Packet.Builder();
IpPktBuilder.version(IpVersion.IPV4).dontFragmentFlag(true).ihl((byte) 9).protocol(IpNumber.UDP)
.tos(IpV4Rfc1349Tos.newInstance((byte) 0)).ttl((byte) 16).srcAddr(srcAddr).dstAddr(dstAddr)
.payloadBuilder(uPktBuilder).correctChecksumAtBuild(true).correctLengthAtBuild(true)
.paddingAtBuild(true);
EthernetPacket.Builder ethPktBuilder = new EthernetPacket.Builder();
ethPktBuilder.dstAddr(MacAddress.getByName("fe:00:00:00:00:02"))
.srcAddr(MacAddress.getByName("fe:00:00:00:00:01")).type(EtherType.IPV4)
.payloadBuilder(IpPktBuilder).paddingAtBuild(true);
EthernetPacket ethPkt = ethPktBuilder.build();
pcapWriter.dump(ethPkt, Instant.now());
} catch (Exception e) {
log.error("PcapException", e);
} |
Is there a way to specify one pcap format vs the other? There appear to be different types covered here: https://wiki.wireshark.org/Development/LibpcapFileFormat |
Regarding your wireshark problem ... perhaps you need to do a manual decode. link |
@rjo that helped a lot, but my "menu" options are different. It certainly sees the proper values now, thanks!
|
glad i could help! |
I want to write some UDP packets to a file, I do not want to hook into any network interfaces or stdin. I've tried a number of different variations of the below logic and I'm stopped at every turn; is this even possible?
Error for above:
I also tried with
Pcaps.openOffline(pcapPathStr)
but since its a new empty file, it fails...The text was updated successfully, but these errors were encountered: