private UnknownIpV6NeighborDiscoveryOption(byte[] rawData, int offset, int length)
      throws IllegalRawDataException {
    if (length < 2) {
      StringBuilder sb = new StringBuilder(100);
      sb.append("The raw data length must be more than 1. rawData: ")
          .append(ByteArrays.toHexString(rawData, " "))
          .append(", offset: ")
          .append(offset)
          .append(", length: ")
          .append(length);
      throw new IllegalRawDataException(sb.toString());
    }

    this.type = IpV6NeighborDiscoveryOptionType.getInstance(rawData[offset]);
    this.length = rawData[1 + offset];
    if (length < this.length * 8) {
      StringBuilder sb = new StringBuilder(100);
      sb.append("The raw data is too short to build this option(")
          .append(this.length * 8)
          .append("). data: ")
          .append(ByteArrays.toHexString(rawData, " "))
          .append(", offset: ")
          .append(offset)
          .append(", length: ")
          .append(length);
      throw new IllegalRawDataException(sb.toString());
    }

    this.data = ByteArrays.getSubArray(rawData, 2 + offset, this.length * 8 - 2);
  }
예제 #2
0
  private IcmpV6EchoReplyPacket(byte[] rawData) {
    this.header = new IcmpV6EchoReplyHeader(rawData);

    byte[] rawPayload =
        ByteArrays.getSubArray(rawData, header.length(), rawData.length - header.length());

    this.payload = UnknownPacket.newPacket(rawPayload);
  }
예제 #3
0
  private PcapNetworkInterface(pcap_if pif, boolean local) {
    this.name = pif.name;
    this.description = pif.description;

    for (pcap_addr pcapAddr = pif.addresses; pcapAddr != null; pcapAddr = pcapAddr.next) {
      if (pcapAddr.addr == null
          && pcapAddr.netmask == null
          && pcapAddr.broadaddr == null
          && pcapAddr.dstaddr == null) {
        logger.warn("Empty pcap_addr on {} ({}). Ignore it.", name, description);
        continue;
      }

      short sa_family =
          pcapAddr.addr != null
              ? pcapAddr.addr.getSaFamily()
              : pcapAddr.netmask != null
                  ? pcapAddr.netmask.getSaFamily()
                  : pcapAddr.broadaddr != null
                      ? pcapAddr.broadaddr.getSaFamily()
                      : pcapAddr.dstaddr != null
                          ? pcapAddr.dstaddr.getSaFamily()
                          /* default */ : Inets.AF_UNSPEC; // Never get here.
      if (sa_family == Inets.AF_INET) {
        addresses.add(PcapIpV4Address.newInstance(pcapAddr, sa_family, name));
      } else if (sa_family == Inets.AF_INET6) {
        addresses.add(PcapIpV6Address.newInstance(pcapAddr, sa_family, name));
      } else {
        if (Platform.isLinux() && sa_family == Inets.AF_PACKET) {
          sockaddr_ll sll = new sockaddr_ll(pcapAddr.addr.getPointer());
          byte[] addr = sll.sll_addr;
          int addrLength = sll.sll_halen & 0xFF;
          if (addrLength == 6) {
            linkLayerAddresses.add(ByteArrays.getMacAddress(addr, 0));
          } else if (addr.length == 0) {
            continue;
          } else {
            linkLayerAddresses.add(
                LinkLayerAddress.getByAddress(ByteArrays.getSubArray(addr, 0, addrLength)));
          }
        } else if ((Platform.isMac() || Platform.isFreeBSD() || Platform.isOpenBSD())
            || Platform.iskFreeBSD() && sa_family == Inets.AF_LINK) {
          sockaddr_dl sdl = new sockaddr_dl(pcapAddr.addr.getPointer());
          byte[] addr = sdl.getAddress();
          if (addr.length == 6) {
            linkLayerAddresses.add(MacAddress.getByAddress(addr));
          } else if (addr.length == 0) {
            continue;
          } else {
            linkLayerAddresses.add(LinkLayerAddress.getByAddress(addr));
          }
        } else {
          logger.warn("{} is not supported address family. Ignore it.", sa_family);
        }
      }
    }

    if (pif.flags == PCAP_IF_LOOPBACK) {
      this.loopBack = true;
    } else {
      this.loopBack = false;
    }

    this.local = local;
  }