当前位置: 首页>>代码示例>>Java>>正文


Java Packet.Builder方法代码示例

本文整理汇总了Java中org.pcap4j.packet.Packet.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Packet.Builder方法的具体用法?Java Packet.Builder怎么用?Java Packet.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.pcap4j.packet.Packet的用法示例。


在下文中一共展示了Packet.Builder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateSrcAddress

import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
/**
 * Update source IP address
 */
private Packet updateSrcAddress(Packet packet) {
    try {
        if (importedProperties.isSourceEnabled()) {
            Inet4Address modifiedAddress = (Inet4Address) Inet4Address.getByAddress(convertIPToByte(importedProperties.getSrcAddress()));
            Packet.Builder builder = packet.getBuilder();
            if (packet.get(IpV4Packet.class).getHeader().getSrcAddr().getHostAddress().equals(defaultSrcAddress)) {
                builder.get(IpV4Packet.Builder.class).srcAddr(modifiedAddress);
            } else {
                builder.get(IpV4Packet.Builder.class).dstAddr(modifiedAddress);
            }
            packet = builder.build();
        }

    } catch (Exception ex) {
        LOG.error("Error updating source IP", ex);
    }
    return packet;
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:22,代码来源:PacketUpdater.java

示例2: updateDstAddress

import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
/**
 * Update destination IP address
 */
private Packet updateDstAddress(Packet packet) {
    try {
        if (importedProperties.isDestinationEnabled()) {
            Inet4Address modifiedAddress = (Inet4Address) Inet4Address.getByAddress(convertIPToByte(importedProperties.getDstAddress()));
            Packet.Builder builder = packet.getBuilder();
            if (packet.get(IpV4Packet.class).getHeader().getDstAddr().getHostAddress().equals(defaultDstAddress)) {
                builder.get(IpV4Packet.Builder.class).dstAddr(modifiedAddress);
            } else {
                builder.get(IpV4Packet.Builder.class).srcAddr(modifiedAddress);
            }
            packet = builder.build();
        }
    } catch (Exception ex) {
        LOG.error("Error updating destination IP", ex);
    }
    return packet;
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:21,代码来源:PacketUpdater.java

示例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();
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:41,代码来源:IcmpV6Helper.java

示例4: tag

import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static Packet tag(Packet packet, int vid) {
  EthernetPacket ep = packet.get(EthernetPacket.class);
  if (ep == null) {
    return packet;
  }

  Dot1qVlanTagPacket.Builder vb = new Dot1qVlanTagPacket.Builder();
  vb.vid((short)vid)
    .type(ep.getHeader().getType())
    .payloadBuilder(new SimpleBuilder(ep.getPayload()));

  Packet.Builder pb = packet.getBuilder();
  pb.get(EthernetPacket.Builder.class)
    .type(EtherType.DOT1Q_VLAN_TAGGED_FRAMES)
    .payloadBuilder(vb);

  return pb.build();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:19,代码来源:Dot1qVlanTagHelper.java

示例5: untag

import org.pcap4j.packet.Packet; //导入方法依赖的package包/类
public static Packet untag(Packet packet) {
  Dot1qVlanTagPacket vp = packet.get(Dot1qVlanTagPacket.class);
  if (vp == null) {
    return packet;
  }

  Packet.Builder pb = packet.getBuilder();
  pb.get(EthernetPacket.Builder.class)
    .type(vp.getHeader().getType())
    .payloadBuilder(new SimpleBuilder(vp.getPayload()));
  return pb.build();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:13,代码来源:Dot1qVlanTagHelper.java

示例6: 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();
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:36,代码来源:IcmpV4Helper.java

示例7: 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();
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:66,代码来源:IcmpV6Helper.java

示例8: 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();
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:52,代码来源:IcmpV4Helper.java


注:本文中的org.pcap4j.packet.Packet.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。