本文整理汇总了Java中org.pcap4j.packet.Packet.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Packet.toString方法的具体用法?Java Packet.toString怎么用?Java Packet.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.pcap4j.packet.Packet
的用法示例。
在下文中一共展示了Packet.toString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matchesDestination
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static boolean matchesDestination(Packet packet, Inet6Address addr) {
IpV6Packet ipv6Packet = packet.get(IpV6Packet.class);
if (ipv6Packet == null) {
throw new IllegalArgumentException(packet.toString());
}
Inet6Address dstAddr = ipv6Packet.getHeader().getDstAddr();
if (dstAddr.equals(addr)) {
return true;
}
if (dstAddr.equals(LINK_LOCAL_ALL_NODES_ADDRESS)) {
return true;
}
if (dstAddr.equals(LINK_LOCAL_ALL_ROUTERS_ADDRESS)) {
return true;
}
return false;
}
示例2: matchesDestination
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static boolean matchesDestination(
Packet packet, Inet4Address addr, Inet4Address subnetmask
) {
IpV4Packet ipv4Packet = packet.get(IpV4Packet.class);
if (ipv4Packet == null) {
throw new IllegalArgumentException(packet.toString());
}
Inet4Address dstAddr = ipv4Packet.getHeader().getDstAddr();
if (dstAddr.equals(addr)) {
return true;
}
if (!isSameNetwork(addr, dstAddr, subnetmask)) {
return false;
}
return isBroadcastAddr(dstAddr, subnetmask);
}
示例3: sendEchoReply
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static void sendEchoReply(Packet packet, Node node, NetworkInterface nif) {
IcmpV6EchoRequestPacket echo = packet.get(IcmpV6EchoRequestPacket.class);
Packet.Builder outer = packet.getBuilder().getOuterOf(IcmpV6EchoRequestPacket.Builder.class);
IpV6Packet ipv6 = packet.get(IpV6Packet.class);
if (
echo == null
|| ipv6 == null
|| outer == null
|| !(outer instanceof IcmpV6CommonPacket.Builder)
) {
throw new IllegalArgumentException(packet.toString());
}
IcmpV6EchoReplyPacket.Builder repb = new IcmpV6EchoReplyPacket.Builder();
repb.identifier(echo.getHeader().getIdentifier())
.sequenceNumber(echo.getHeader().getSequenceNumber())
.payloadBuilder(new SimpleBuilder(echo.getPayload()));
Inet6Address repSrcAddr = ipv6.getHeader().getDstAddr();
Inet6Address repDstAddr = ipv6.getHeader().getSrcAddr();
((IcmpV6CommonPacket.Builder)outer)
.type(IcmpV6Type.ECHO_REPLY)
.srcAddr(repSrcAddr)
.dstAddr(repDstAddr)
.payloadBuilder(repb)
.correctChecksumAtBuild(true);
try {
node.sendL4Packet(
outer.build(),
repSrcAddr,
repDstAddr,
nif
);
} catch (SendPacketException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
示例4: matchesDestination
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static boolean matchesDestination(Packet packet, MacAddress addr) {
EthernetPacket etherPacket = packet.get(EthernetPacket.class);
if (etherPacket == null) {
throw new IllegalArgumentException(packet.toString());
}
MacAddress dst
= etherPacket.getHeader().getDstAddr();
return dst.equals(addr)
|| dst.equals(MacAddress.ETHER_BROADCAST_ADDRESS);
}
示例5: reply
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static void reply(Packet packet, Node node, NetworkInterface nif) {
IcmpV4EchoPacket echo = packet.get(IcmpV4EchoPacket.class);
Packet.Builder outer = packet.getBuilder().getOuterOf(IcmpV4EchoPacket.Builder.class);
IpV4Packet ipv4 = packet.get(IpV4Packet.class);
if (
echo == null
|| ipv4 == null
|| outer == null
|| !(outer instanceof IcmpV4CommonPacket.Builder)
) {
throw new IllegalArgumentException(packet.toString());
}
IcmpV4EchoReplyPacket.Builder repb = new IcmpV4EchoReplyPacket.Builder();
repb.identifier(echo.getHeader().getIdentifier())
.sequenceNumber(echo.getHeader().getSequenceNumber())
.payloadBuilder(new SimpleBuilder(echo.getPayload()));
((IcmpV4CommonPacket.Builder)outer).type(IcmpV4Type.ECHO_REPLY)
.payloadBuilder(repb)
.correctChecksumAtBuild(true);
try {
node.sendL4Packet(
outer.build(),
ipv4.getHeader().getDstAddr(),
ipv4.getHeader().getSrcAddr(),
nif
);
} catch (SendPacketException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
示例6: matchesDestination
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static boolean matchesDestination(Packet packet, InetAddress addr) {
ArpPacket arpPacket = packet.get(ArpPacket.class);
if (arpPacket == null) {
throw new IllegalArgumentException(packet.toString());
}
return addr.equals(arpPacket.getHeader().getDstProtocolAddr());
}
示例7: cache
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static void cache(Packet packet, ArpCache arpCache) {
ArpPacket arpPacket = packet.get(ArpPacket.class);
if (arpPacket == null) {
throw new IllegalArgumentException(packet.toString());
}
InetAddress ipAddr
= arpPacket.getHeader().getSrcProtocolAddr();
MacAddress macAddr
= arpPacket.getHeader().getSrcHardwareAddr();
NeighborDiscoveryHelper.cache(arpCache, ipAddr, macAddr);
}
示例8: reply
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static void reply(Packet packet, Node node, NetworkInterface nif) {
ArpPacket arpPacket = packet.get(ArpPacket.class);
if (arpPacket == null) {
throw new IllegalArgumentException(packet.toString());
}
InetAddress srcIpAddr
= arpPacket.getHeader().getSrcProtocolAddr();
MacAddress srcMacAddr
= arpPacket.getHeader().getSrcHardwareAddr();
InetAddress dstIpAddr
= arpPacket.getHeader().getDstProtocolAddr();
ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
arpBuilder.hardwareType(ArpHardwareType.ETHERNET)
.protocolType(EtherType.IPV4)
.hardwareAddrLength((byte)MacAddress.SIZE_IN_BYTES)
.protocolAddrLength((byte)ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
.operation(ArpOperation.REPLY)
.srcHardwareAddr(nif.getMacAddress())
.srcProtocolAddr(dstIpAddr)
.dstHardwareAddr(srcMacAddr)
.dstProtocolAddr(srcIpAddr);
try {
node.sendL3Packet(arpBuilder.build(), nif);
} catch (SendPacketException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
示例9: sendSolicitedNeighborAdvertisement
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static void sendSolicitedNeighborAdvertisement(
Packet invokingPacket,Node node, NetworkInterface nif
) {
IpV6Packet ipPacket = invokingPacket.get(IpV6Packet.class);
IcmpV6NeighborSolicitationPacket nsPacket
= invokingPacket.get(IcmpV6NeighborSolicitationPacket.class);
if (nsPacket == null || ipPacket == null) {
throw new IllegalArgumentException(invokingPacket.toString());
}
Inet6Address nsSrcIpAddr
= ipPacket.getHeader().getSrcAddr();
Inet6Address nsTargetAddr
= nsPacket.getHeader().getTargetAddress();
List<IpV6NeighborDiscoveryOption> opts = new ArrayList<IpV6NeighborDiscoveryOption>();
IpV6NeighborDiscoveryTargetLinkLayerAddressOption.Builder optBuilder
= new IpV6NeighborDiscoveryTargetLinkLayerAddressOption.Builder();
optBuilder.linkLayerAddress(nif.getMacAddress().getAddress())
.correctLengthAtBuild(true);
opts.add(optBuilder.build());
IcmpV6NeighborAdvertisementPacket.Builder naBuilder
= new IcmpV6NeighborAdvertisementPacket.Builder();
naBuilder
.routerFlag(true)
.overrideFlag(true)
.targetAddress(nsTargetAddr)
.options(opts);
Inet6Address naDstIpAddr;
if (nsSrcIpAddr.equals(IpV6Helper.UNSPECIFIED_ADDRESS)) {
naBuilder.solicitedFlag(false);
naDstIpAddr = IpV6Helper.LINK_LOCAL_ALL_NODES_ADDRESS;
}
else {
naBuilder.solicitedFlag(true);
naDstIpAddr = nsSrcIpAddr;
}
IcmpV6CommonPacket.Builder icmpV6Common = new IcmpV6CommonPacket.Builder();
icmpV6Common.type(IcmpV6Type.NEIGHBOR_ADVERTISEMENT)
.code(IcmpV6Code.NO_CODE)
.payloadBuilder(naBuilder)
.srcAddr(nsTargetAddr)
.dstAddr(naDstIpAddr)
.correctChecksumAtBuild(true);
try {
node.sendL4Packet(
icmpV6Common.build(),
nsTargetAddr,
naDstIpAddr,
nif,
255
);
} catch (SendPacketException e) {
// TODO handle the exception.
e.printStackTrace();
}
}
示例10: sendErrorMessage
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static void sendErrorMessage(
IcmpV6Type type,
IcmpV6Code code,
Packet packet,
Node node,
NetworkInterface nif
) {
IpV6Packet ipv6Packet = packet.get(IpV6Packet.class);
if (ipv6Packet == null) {
throw new IllegalArgumentException(packet.toString());
}
Packet.Builder icmpV6Inet;
int size = NetworkPropertiesLoader.getMtu() - 40 - 8;
if (type.equals(IcmpV6Type.DESTINATION_UNREACHABLE)) {
icmpV6Inet
= new IcmpV6DestinationUnreachablePacket.Builder()
.payload(
org.pcap4j.util.IcmpV6Helper
.makePacketForInvokingPacketField(ipv6Packet, size)
);
}
else if (type.equals(IcmpV6Type.TIME_EXCEEDED)) {
icmpV6Inet
= new IcmpV6TimeExceededPacket.Builder()
.payload(
org.pcap4j.util.IcmpV6Helper
.makePacketForInvokingPacketField(ipv6Packet, size)
);
}
else {
throw new IllegalArgumentException(packet.toString());
}
Inet6Address errDstAddr = ipv6Packet.getHeader().getSrcAddr();
Inet6Address errSrcAddr = null;
for (NifIpAddress nifIp: nif.getIpAddresses()) {
if (nifIp instanceof NifIpV6Address) {
errSrcAddr = ((NifIpV6Address)nifIp).getIpAddr();
}
}
if (errSrcAddr == null) {
throw new IllegalArgumentException(nif.getName() + " doesn't have IPv6 addresses.");
}
IcmpV6CommonPacket.Builder icmpV6Common = new IcmpV6CommonPacket.Builder();
icmpV6Common.type(type)
.code(code)
.srcAddr(errSrcAddr)
.dstAddr(errDstAddr)
.payloadBuilder(icmpV6Inet)
.correctChecksumAtBuild(true);
try {
node.sendL4Packet(
icmpV6Common.build(),
errSrcAddr,
errDstAddr,
nif
);
} catch (SendPacketException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
示例11: sendErrorMessage
import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static void sendErrorMessage(
IcmpV4Type type,
IcmpV4Code code,
Packet packet,
Node node,
NetworkInterface nif
) {
IpV4Packet ipv4Packet = packet.get(IpV4Packet.class);
if (ipv4Packet == null) {
throw new IllegalArgumentException(packet.toString());
}
Packet.Builder icmpV4Inet;
if (type.equals(IcmpV4Type.DESTINATION_UNREACHABLE)) {
icmpV4Inet
= new IcmpV4DestinationUnreachablePacket.Builder()
.payload(
org.pcap4j.util.IcmpV4Helper
.makePacketForInvokingPacketField(ipv4Packet)
);
}
else if (type.equals(IcmpV4Type.TIME_EXCEEDED)) {
icmpV4Inet
= new IcmpV4TimeExceededPacket.Builder()
.payload(
org.pcap4j.util.IcmpV4Helper
.makePacketForInvokingPacketField(ipv4Packet)
);
}
else {
throw new IllegalArgumentException(packet.toString());
}
IcmpV4CommonPacket.Builder icmpV4Common = new IcmpV4CommonPacket.Builder();
icmpV4Common.type(type)
.code(code)
.payloadBuilder(icmpV4Inet)
.correctChecksumAtBuild(true);
try {
node.sendL4Packet(
icmpV4Common.build(),
nif.getIpAddresses().get(0).getIpAddr(),
ipv4Packet.getHeader().getSrcAddr(),
nif
);
} catch (SendPacketException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}