本文整理汇总了Java中org.pcap4j.packet.namednumber.EtherType.IPV4属性的典型用法代码示例。如果您正苦于以下问题:Java EtherType.IPV4属性的具体用法?Java EtherType.IPV4怎么用?Java EtherType.IPV4使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.pcap4j.packet.namednumber.EtherType
的用法示例。
在下文中一共展示了EtherType.IPV4属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildPacket
/**
*
* @param builder
*/
public void buildPacket(AbstractPacket.AbstractBuilder builder) {
if (!this.type.equals(EtherType.getInstance((short) 0x0000))) {
// do nothing if type not 0x0000
} else if (builder == null) {
this.type = EtherType.getInstance((short) 0xFFFF);
} else {
this.type = EtherType.IPV4;
}
db = new Dot1qVlanTagPacket.Builder();
db.priority(priority)
.cfi(cfi)
.vid(vid)
.type(type)
.payloadBuilder(builder);
this.packet = db.build();
}
示例2: processEthernetPacket
public static void processEthernetPacket(Packet packet, PcapFileSummary pcapFileSummary, PacketInfo packetInfo, Mode mode) {
if (packet == null) {
return; // skip empty packets
}
try {
log.trace("Converting to ethernet packet");
EthernetPacket ethernetPacket = EthernetPacket.newPacket(packet.getRawData(), 0, packet.length());
EthernetPacket.EthernetHeader ethernetHeader = ethernetPacket.getHeader();
MacAddress sourceMac = ethernetHeader.getSrcAddr();
log.trace("Source MAC: " + sourceMac);
packetInfo.put(PacketInfo.SOURCE_MAC, sourceMac.toString());
MacAddress destMac = ethernetHeader.getDstAddr();
log.trace("Destination MAC: " + destMac);
packetInfo.put(PacketInfo.DESTINATION_MAC, destMac.toString());
EtherType etherType = ethernetHeader.getType();
log.trace("EtherType: " + etherType.toString());
packetInfo.put(PacketInfo.ETHERTYPE, etherType.toString());
Packet payload = ethernetPacket.getPayload();
if (etherType == EtherType.IPV4) {
IpPacketProcessor.processIpv4Packet(payload, pcapFileSummary, packetInfo, mode);
} else if (etherType == EtherType.IPV6) {
IpPacketProcessor.processIpv6Packet(payload, pcapFileSummary, packetInfo, mode);
} else if ((mode == Mode.POSSIBLE_ATTACKS_ANALYSIS) && (etherType == EtherType.ARP)) {
pcapFileSummary.nonIpPacketCount++;
ArpPacketProcessor.processArpPacket(payload, pcapFileSummary);
} else {
pcapFileSummary.nonIpPacketCount++;
log.trace("Skipping packet with EtherType: " + etherType);
}
} catch (IllegalRawDataException e) {
log.error("Exception occurred while processing a packet. Exception was: " + e);
}
}
示例3: TrexEthernetPacket
/**
*
*/
public TrexEthernetPacket() {
this.srcAddr = MacAddress.getByName("00:00:00:00:00:00");
this.dstAddr = MacAddress.getByName("00:00:00:00:00:00");
this.type = EtherType.IPV4;
this.addPad = false;
}
示例4: pack
public static EthernetPacket pack(
final Packet payload, MacAddress src, MacAddress dst
) {
EtherType type;
if (payload instanceof IpV4Packet) {
type = EtherType.IPV4;
}
else if (payload instanceof IpV6Packet) {
type = EtherType.IPV6;
}
else if (payload instanceof ArpPacket) {
type = EtherType.ARP;
}
else if (payload instanceof Dot1qVlanTagPacket) {
type = EtherType.DOT1Q_VLAN_TAGGED_FRAMES;
}
else {
throw new AssertionError(payload.getClass().getName());
}
EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
return etherBuilder.dstAddr(dst)
.srcAddr(src)
.type(type)
.payloadBuilder(
new AbstractBuilder() {
@Override
public Packet build() {
return payload;
}
}
)
.paddingAtBuild(true)
.build();
}
示例5: buildIpV4
public static Packet buildIpV4(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
IpV4Packet.Builder builder_ipv4){
org.pcap4j.packet.Packet.Builder builder=null;
EtherType etherType=null;
Packet p=null;
if(ppp){
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;
}
示例6: buildIpV4
public static Packet buildIpV4(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
IpV4Packet.Builder builder_ipv4){
org.pcap4j.packet.Packet.Builder builder=null;
EtherType etherType=null;
Packet p=null;
if(ppp){
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;
}
示例7: buildIpV4
public static Packet buildIpV4(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
IpV4Packet.Builder builder_ipv4) {
org.pcap4j.packet.Packet.Builder builder;
EtherType etherType;
Packet p;
if (ppp) {
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;
}