本文整理汇总了Java中org.pcap4j.packet.IpV6SimpleTrafficClass类的典型用法代码示例。如果您正苦于以下问题:Java IpV6SimpleTrafficClass类的具体用法?Java IpV6SimpleTrafficClass怎么用?Java IpV6SimpleTrafficClass使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IpV6SimpleTrafficClass类属于org.pcap4j.packet包,在下文中一共展示了IpV6SimpleTrafficClass类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pack
import org.pcap4j.packet.IpV6SimpleTrafficClass; //导入依赖的package包/类
public static IpV6Packet pack(
final Packet payload, Inet6Address src, Inet6Address dst, int hopLimit, short id
) {
IpNumber nextHeader;
if (payload instanceof UdpPacket) {
nextHeader = IpNumber.UDP;
}
else if (payload instanceof IcmpV6CommonPacket) {
nextHeader = IpNumber.ICMPV6;
}
else if (payload instanceof TcpPacket) {
nextHeader = IpNumber.TCP;
}
else {
throw new AssertionError();
}
IpV6Packet.Builder builder = new IpV6Packet.Builder();
return builder.version(IpVersion.IPV6)
.trafficClass(IpV6SimpleTrafficClass.newInstance((byte)0))
.flowLabel(IpV6SimpleFlowLabel.newInstance(0))
.nextHeader(nextHeader)
.hopLimit((byte)hopLimit)
.srcAddr(src)
.dstAddr(dst)
.payloadBuilder(new SimpleBuilder(payload))
.correctLengthAtBuild(true)
.build();
}
示例2: _getPacketBuilder4IPv6
import org.pcap4j.packet.IpV6SimpleTrafficClass; //导入依赖的package包/类
private EthernetPacket.Builder _getPacketBuilder4IPv6(Inet6Address remoteAddress, MacAddress localMacAddress, Inet6Address
localIpAdress) throws UnknownHostException {
MacAddress broadcastMacAddress = _getBroadcastMacAddress4IPv6(remoteAddress);
Inet6Address broadcasetIPAddress = _getBroadcastIPAddress4IPv6(remoteAddress);
IcmpV6NeighborSolicitationPacket.Builder v6Builder = new IcmpV6NeighborSolicitationPacket.Builder();
v6Builder.targetAddress(remoteAddress);
v6Builder.reserved(0);
IpV6NeighborDiscoverySourceLinkLayerAddressOption.Builder optionBuilder = new IpV6NeighborDiscoverySourceLinkLayerAddressOption
.Builder();
IpV6NeighborDiscoverySourceLinkLayerAddressOption option = optionBuilder
.linkLayerAddress(localMacAddress.getAddress())
.correctLengthAtBuild(true)
.build();
List<IcmpV6CommonPacket.IpV6NeighborDiscoveryOption> options = new ArrayList<>();
options.add(option);
v6Builder.options(options);
IcmpV6CommonPacket.Builder icmpV6b = new IcmpV6CommonPacket.Builder();
icmpV6b.type(IcmpV6Type.NEIGHBOR_SOLICITATION)
.code(IcmpV6Code.NO_CODE)
.srcAddr(localIpAdress)
.dstAddr(broadcasetIPAddress)
.payloadBuilder(v6Builder)
.correctChecksumAtBuild(true);
IpV6Packet.Builder ipv6b = new IpV6Packet.Builder();
ipv6b.version(IpVersion.IPV6)
.trafficClass(IpV6SimpleTrafficClass.newInstance((byte) 0x12))
.flowLabel(IpV6SimpleFlowLabel.newInstance(0))
.nextHeader(IpNumber.ICMPV6)
.hopLimit((byte) 255)
.srcAddr(localIpAdress)
.dstAddr(broadcasetIPAddress) // "fe80:0:0:0:250:56ff:febc:2688" -> "FF02::1:FFbc:2688"
.correctLengthAtBuild(true)
.payloadBuilder(icmpV6b);
EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
etherBuilder.dstAddr(broadcastMacAddress)
.srcAddr(localMacAddress)
.type(EtherType.IPV6)
.payloadBuilder(ipv6b)
.paddingAtBuild(true);
return etherBuilder;
}
示例3: testBlockedInet6DnsQuery
import org.pcap4j.packet.IpV6SimpleTrafficClass; //导入依赖的package包/类
@Test
public void testBlockedInet6DnsQuery() throws Exception {
Message message = Message.newQuery(new ARecord(new Name("blocked.example.com."),
0x01,
3600,
Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
));
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr((Inet6Address) Inet6Address.getByName("::0"))
.dstAddr((Inet6Address) Inet6Address.getByName("::1"))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(message.toWire())
);
IpPacket ipOutPacket = new IpV6Packet.Builder()
.version(IpVersion.IPV6)
.trafficClass(IpV6SimpleTrafficClass.newInstance((byte) 0))
.flowLabel(IpV6SimpleFlowLabel.newInstance(0))
.nextHeader(IpNumber.UDP)
.srcAddr((Inet6Address) Inet6Address.getByName("::0"))
.dstAddr((Inet6Address) Inet6Address.getByName("::1"))
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNotNull(mockEventLoop.lastResponse);
assertNull(mockEventLoop.lastOutgoing);
assertTrue(mockEventLoop.lastResponse instanceof IpPacket);
assertTrue(mockEventLoop.lastResponse.getPayload() instanceof UdpPacket);
Message responseMsg = new Message(mockEventLoop.lastResponse.getPayload().getPayload().getRawData());
assertEquals(NOERROR, responseMsg.getHeader().getRcode());
assertArrayEquals(new Record[] {}, responseMsg.getSectionArray(Section.ANSWER));
assertNotEquals(0, responseMsg.getSectionArray(Section.AUTHORITY).length);
assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0] instanceof SOARecord);
assertTrue(responseMsg.getSectionArray(Section.AUTHORITY)[0].getTTL() > 0);
}