public static Packet buildIpV4( MacAddress srcAddress_mac, MacAddress dstAddrress_mac, IpV4Packet.Builder builder_ipv4) { org.pcap4j.packet.Packet.Builder builder = null; EthernetPacketType etherType; //EtherType etherType = null; Packet p = null; if (ppp) { etherType = EthernetPacketType.PointToPointProtocolOverEthernetSessionStage; //etherType = EtherType.PPPOE_SESSION_STAGE; UnknownPacket.Builder pppBuilder = new UnknownPacket.Builder(); byte[] ipData = builder_ipv4.build().getRawData(); byte[] lenb = new byte[2]; ByteShortConvert.toByteArray((short)(ipData.length + 2), lenb, 0); byte[] pppHead = new byte[8]; System.arraycopy(pppHead_static, 0, pppHead, 0, pppHead.length); System.arraycopy(lenb, 0, pppHead, 4, 2); byte[] newData = new byte[pppHead.length + ipData.length]; System.arraycopy(pppHead, 0, newData, 0, pppHead.length); System.arraycopy(ipData, 0, newData, 8, ipData.length); pppBuilder.rawData(newData); builder = pppBuilder; } else { etherType = EtherType.IPV4; builder = builder_ipv4; } EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder(); etherBuilder.dstAddr(dstAddrress_mac) .srcAddr(srcAddress_mac) .type(etherType) .payloadBuilder(builder) .paddingAtBuild(true); p = etherBuilder.build(); return(p); }