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


Java IpNumber.UDP属性代码示例

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


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

示例1: processIpv6Packet

public static void processIpv6Packet(Packet packet, PcapFileSummary pcapFileSummary, PacketInfo packetInfo, Mode mode) {
    if (packet == null) {
        return; // skip empty packets
    }
    try {
        log.trace("Converting to IPv6 packet");
        IpV6Packet ipV6Packet = IpV6Packet.newPacket(packet.getRawData(), 0, packet.length());
        IpV6Packet.IpV6Header ipV6Header = ipV6Packet.getHeader();
        Inet6Address sourceAddress = ipV6Header.getSrcAddr();
        Inet6Address destAddress = ipV6Header.getDstAddr();
        if (mode == Mode.POSSIBLE_ATTACKS_ANALYSIS) {
            //pcapFileSummary.ipMacTracker.query(sourceAddress.getHostAddress(), sourceMac.toString());
        }
        packetInfo.put(PacketInfo.SOURCE_ADDRESS, sourceAddress.getHostAddress());
        packetInfo.put(PacketInfo.DESTINATION_ADDRESS, destAddress.getHostAddress());
        log.trace("Adding IPv6 addresses to set:  source: " + sourceAddress.getHostAddress() + ", dest: " + destAddress.getHostAddress());
        pcapFileSummary.uniqueIpAddresses.add(sourceAddress.getHostAddress());
        pcapFileSummary.uniqueIpAddresses.add(destAddress.getHostAddress());
        IpNumber ipNumber = ipV6Header.getProtocol();
        packetInfo.put(PacketInfo.IP_PROTOCOL, ipNumber.toString());
        pcapFileSummary.ipProtocolCounter.increment(ipNumber);
        Packet payload = ipV6Packet.getPayload();
        if (ipNumber == IpNumber.ICMPV4) {
            IcmpPacketProcessor.processIcmpv4Packet(payload, pcapFileSummary, packetInfo, mode);
        } else if (ipNumber == IpNumber.ICMPV6) {
            IcmpPacketProcessor.processIcmpv6Packet(payload, pcapFileSummary, packetInfo, mode);
        } else if (ipNumber == IpNumber.TCP) {
            TcpPacketProcessor.processTcpPacket(payload, pcapFileSummary, packetInfo, mode);
        } else if (ipNumber == IpNumber.UDP) {
            UdpPacketProcessor.processUdpPacket(payload, pcapFileSummary, packetInfo, mode);
        } else {
            log.trace("Skipping packet: " + payload);
        }
    } catch (IllegalRawDataException e) {
        log.error("Exception occurred while processing a packet. Exception was: " + e);
    }
}
 
开发者ID:rmcnew,项目名称:LiquidFortressPacketAnalyzer,代码行数:37,代码来源:IpPacketProcessor.java

示例2: buildPacket

/**
 *
 * @param builder
 * @param protocol
 */
public void buildPacket(AbstractPacket.AbstractBuilder builder, IpNumber protocol) {

    byte[] pad = new byte[1];
    String payloadPattern = payload.getPayloadPattern();
    String payloadString = payload.getPayloadType().getPadPayloadString(payloadPattern, (totalLength - 20) * 2);

    if (packetLength > DEFAULT_PACKET_LENGTH) {
        payloadString = payload.getPayloadType().getPadPayloadString(payloadPattern, payloadString.length() + ((packetLength - DEFAULT_PACKET_LENGTH) * 2));
        this.totalLength = (short) ((int) totalLength + (packetLength - DEFAULT_PACKET_LENGTH));
    }
    pad = payload.getPayloadPad(payloadString, totalLength - 20);

    ipV4Builder = new IpV4Packet.Builder();
    ipV4Builder.version(version)
            .ihl(ihl)
            .tos(tos)
            .totalLength(totalLength)
            .identification(identification)
            .reservedFlag(reservedFlag)
            .ttl(ttl)
            .fragmentOffset((short) 0)
            .protocol(protocol)
            .headerChecksum(headerChecksum)
            .srcAddr(srcAddr)
            .dstAddr(dstAddr)
            .protocol(protocol)
            .correctChecksumAtBuild(true)
            //  .correctLengthAtBuild(true)
            .payloadBuilder(builder);

    if (protocol != IpNumber.TCP && protocol != IpNumber.UDP) {
        ipV4Builder.paddingAtBuild(false)
                .padding(pad);
    } else {
        ipV4Builder.paddingAtBuild(true).correctLengthAtBuild(true);
    }

    this.packet1 = ipV4Builder.build();
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:44,代码来源:TrexIpV4Packet.java

示例3: pack

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

示例4: pack

public static IpV4Packet pack(
  final Packet payload, Inet4Address src, Inet4Address dst, int ttl, short id
) {
  IpNumber ipNum;
  if (payload instanceof UdpPacket) {
    ipNum = IpNumber.UDP;
  }
  else if (payload instanceof IcmpV4CommonPacket) {
    ipNum = IpNumber.ICMPV4;
  }
  else if (payload instanceof TcpPacket) {
    ipNum = IpNumber.TCP;
  }
  else {
    throw new AssertionError();
  }

  IpV4Packet.Builder builder = new IpV4Packet.Builder();
  return
    builder.version(IpVersion.IPV4)
           .tos(IpV4Rfc791Tos.newInstance((byte)0))
           .identification(id)
           .ttl((byte)ttl)
           .protocol(ipNum)
           .srcAddr(src)
           .dstAddr(dst)
           .payloadBuilder(new SimpleBuilder(payload))
           .correctChecksumAtBuild(true)
           .correctLengthAtBuild(true)
           .build();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:31,代码来源:IpV4Helper.java


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