本文整理汇总了Java中org.pcap4j.packet.UdpPacket类的典型用法代码示例。如果您正苦于以下问题:Java UdpPacket类的具体用法?Java UdpPacket怎么用?Java UdpPacket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UdpPacket类属于org.pcap4j.packet包,在下文中一共展示了UdpPacket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: processUdpPacket
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
public static void processUdpPacket(Packet packet, PcapFileSummary pcapFileSummary, PacketInfo packetInfo, Mode mode) {
if (packet == null) {
return; // skip empty packets
}
String sourceAddress = packetInfo.get(PacketInfo.SOURCE_ADDRESS);
String destinationAddress = packetInfo.get(PacketInfo.DESTINATION_ADDRESS);
try {
log.trace("Converting to UDP packet");
UdpPacket udpPacket = UdpPacket.newPacket(packet.getRawData(), 0, packet.length());
UdpPacket.UdpHeader udpHeader = udpPacket.getHeader();
UdpPort sourcePort = udpHeader.getSrcPort();
UdpPort destinationPort = udpHeader.getDstPort();
packetInfo.put(PacketInfo.SOURCE_PORT, sourcePort.valueAsString());
packetInfo.put(PacketInfo.DESTINATION_PORT, destinationPort.valueAsString());
if (mode == Mode.POSSIBLE_ATTACKS_ANALYSIS) {
//pcapFileSummary.portScanDetector.add(packetInfo);
}
String udpSource = sourceAddress + ":" + sourcePort.toString();
String udpDestination = destinationAddress + ":" + destinationPort.toString();
log.trace("Adding UDP source to set: " + udpSource);
pcapFileSummary.udpSources.add(udpSource);
log.trace("UDP{ source: " + udpSource + ", destination: " + udpDestination + " }");
} catch (IllegalRawDataException e) {
log.error("Exception occurred while processing a packet. Exception was: " + e);
}
}
开发者ID:rmcnew,项目名称:LiquidFortressPacketAnalyzer,代码行数:27,代码来源:UdpPacketProcessor.java
示例2: shouldCapture
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
/**
* Checks if the given {@link Packet} should be captured.
*
* @param packet The packet to be checked
* @return Returns true, if the packet should be captured, otherwise false
*/
private boolean shouldCapture(final Packet packet) {
if (packet.contains(ArpPacket.class)) {
ArpPacket arpPacket = packet.get(ArpPacket.class);
if (arpPacket.getHeader().getOperation().equals(ArpOperation.REQUEST)) {
return true;
}
}
if (packet.contains(UdpPacket.class)) {
final UdpPacket udpPacket = packet.get(UdpPacket.class);
if (UdpPort.BOOTPS == udpPacket.getHeader().getDstPort()) {
return true;
}
}
return false;
}
开发者ID:openhab,项目名称:openhab2-addons,代码行数:22,代码来源:PacketCapturingService.java
示例3: pack
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
public static UdpPacket pack(
Packet payload,
UdpPort srcPort,
UdpPort dstPort,
InetAddress srcAddr,
InetAddress dstAddr
) {
UdpPacket.Builder builder = new UdpPacket.Builder();
return builder.srcPort(srcPort)
.dstPort(dstPort)
.payloadBuilder(new SimpleBuilder(payload))
.srcAddr(srcAddr)
.dstAddr(dstAddr)
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.build();
}
开发者ID:kaitoy,项目名称:sneo,代码行数:18,代码来源:UdpHelper.java
示例4: consumeIpV4
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
protected void consumeIpV4(Packet packet, NetworkInterface getter) {
if (packet.contains(UdpPacket.class)) {
consumeUdp(packet, getter);
}
else if (packet.contains(IcmpV4EchoPacket.class)) {
if (!listeningIcmp) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("not listening ICMP. Drop a packet: " + packet);
}
return;
}
IcmpV4Helper.reply(packet, this, getter);
}
else {
LOGGER.warn("I don't care this packet: " + packet);
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:18,代码来源:Node.java
示例5: consumeIpV6
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
protected void consumeIpV6(Packet packet, NetworkInterface getter) {
if (packet.contains(UdpPacket.class)) {
consumeUdp(packet, getter);
}
else if (packet.contains(IcmpV6EchoRequestPacket.class)) {
if (!listeningIcmp) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("not listening ICMP. Drop a packet: " + packet);
}
return;
}
IcmpV6Helper.sendEchoReply(packet, this, getter);
}
else {
LOGGER.warn("I don't care this packet: " + packet);
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:18,代码来源:Node.java
示例6: handleDnsResponse
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
/**
* Handles a responsePayload from an upstream DNS server
*
* @param requestPacket The original request packet
* @param responsePayload The payload of the response
*/
void handleDnsResponse(IpPacket requestPacket, byte[] responsePayload) {
UdpPacket udpOutPacket = (UdpPacket) requestPacket.getPayload();
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder(udpOutPacket)
.srcPort(udpOutPacket.getHeader().getDstPort())
.dstPort(udpOutPacket.getHeader().getSrcPort())
.srcAddr(requestPacket.getHeader().getDstAddr())
.dstAddr(requestPacket.getHeader().getSrcAddr())
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(responsePayload)
);
IpPacket ipOutPacket;
if (requestPacket instanceof IpV4Packet) {
ipOutPacket = new IpV4Packet.Builder((IpV4Packet) requestPacket)
.srcAddr((Inet4Address) requestPacket.getHeader().getDstAddr())
.dstAddr((Inet4Address) requestPacket.getHeader().getSrcAddr())
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
} else {
ipOutPacket = new IpV6Packet.Builder((IpV6Packet) requestPacket)
.srcAddr((Inet6Address) requestPacket.getHeader().getDstAddr())
.dstAddr((Inet6Address) requestPacket.getHeader().getSrcAddr())
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
}
eventLoop.queueDeviceWrite(ipOutPacket);
}
开发者ID:julian-klode,项目名称:dns66,代码行数:43,代码来源:DnsPacketProxy.java
示例7: testHandleDnsRequestNotDnsPacket
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
@Test
public void testHandleDnsRequestNotDnsPacket() throws Exception {
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.HTTP)
.dstPort(UdpPort.HTTP)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(new byte[]{1, 2, 3, 4, 5})
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastOutgoing);
assertNull(mockEventLoop.lastResponse);
}
开发者ID:julian-klode,项目名称:dns66,代码行数:30,代码来源:DnsPacketProxyTest.java
示例8: testDnsQuery
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
@Test
public void testDnsQuery() throws Exception {
Message message = Message.newQuery(new ARecord(new Name("notblocked.example.com."),
0x01,
3600,
Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
));
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(message.toWire())
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastResponse);
assertNotNull(mockEventLoop.lastOutgoing);
assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());
}
开发者ID:julian-klode,项目名称:dns66,代码行数:38,代码来源:DnsPacketProxyTest.java
示例9: testNoQueryDnsQuery
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
@Test
public void testNoQueryDnsQuery() throws Exception {
Message message = new Message();
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(message.toWire())
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastResponse);
assertNull(mockEventLoop.lastOutgoing);
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
}
开发者ID:julian-klode,项目名称:dns66,代码行数:34,代码来源:DnsPacketProxyTest.java
示例10: buildPacket
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
/**
* Build packet
*
* @throws java.net.UnknownHostException
*/
public void buildPacket() throws UnknownHostException {
int calculatedLength = getPacketLength();
String payloadString = payload.getPayloadType().getPadPayloadString(payload.getPayloadPattern(), calculatedLength * 2);
udpBuilder = new UdpPacket.Builder();
UnknownPacket.Builder unknownb = new UnknownPacket.Builder();
unknownb.rawData(payload.getPayloadPad(payloadString, calculatedLength));
Inet4Address srcAddr = (Inet4Address) InetAddress.getByAddress(
new byte[]{(byte) 0, (byte) 0, (byte) 0, (byte) 0}
);
Inet4Address dstAddr = (Inet4Address) InetAddress.getByAddress(
new byte[]{(byte) 0, (byte) 0, (byte) 0, (byte) 0}
);
udpBuilder.srcPort(UdpPort.getInstance((short) srcPort.value()))
.dstPort(UdpPort.getInstance((short) dstPort.value()))
.srcAddr(srcAddr)
.dstAddr(dstAddr)
.length((short) calculatedLength)
.payloadBuilder(unknownb)
.correctChecksumAtBuild(true)
.correctLengthAtBuild(false);
this.packet = udpBuilder.build();
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:32,代码来源:TrexUdpPacket.java
示例11: getSrcPort
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
/**
* Return source port
*
* @param packet
* @return
*/
private String getSrcPort(Packet packet) {
if (protocolType.equals("TCP")) {
return packet.get(TcpPacket.class).getHeader().getSrcPort().toString();
} else if (protocolType.equals("UDP")) {
return packet.get(UdpPacket.class).getHeader().getSrcPort().toString();
}
return "80";
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:17,代码来源:PacketUpdater.java
示例12: getDstPort
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
/**
* Return destination port
*
* @param packet
* @return
*/
private String getDstPort(Packet packet) {
if (protocolType.equals("TCP")) {
return packet.get(TcpPacket.class).getHeader().getDstPort().toString();
} else if (protocolType.equals("UDP")) {
return packet.get(UdpPacket.class).getHeader().getDstPort().toString();
}
return "80";
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:17,代码来源:PacketUpdater.java
示例13: getPacketTypeText
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
/**
*
* @param packet
* @return
*/
public PacketInfo getPacketTypeText(Packet packet) {
PacketInfo packetInfo = new PacketInfo();
String packetType = "";
// Default values for packet info
packetInfo.setType("Unknown");
packetInfo.setLength(packet.length());
if (packet != null) {
// EthernetPacket
if (packet.get(EthernetPacket.class) != null) {
packetType += "Ethernet/";
}
// IPPacket
if (packet.get(IpV4Packet.class) != null) {
packetType += "IPV4/";
}
// TCPPacket
if (packet.get(TcpPacket.class) != null) {
packetType += "TCP/";
}
// UDPPacket
if (packet.get(UdpPacket.class) != null) {
packetType += "UDP";
}
if (packetType.endsWith("/")) {
packetType = packetType.substring(0, packetType.length() - 1);
}
packetInfo.setType(packetType);
}
return packetInfo;
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:37,代码来源:TrafficProfile.java
示例14: pack
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
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,代码行数:30,代码来源:IpV6Helper.java
示例15: pack
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
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,代码行数:32,代码来源:IpV4Helper.java
示例16: consumeUdp
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
private void consumeUdp(Packet packet, NetworkInterface getter) {
if (agent == null || !agent.isRunning()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Not listening SNMP. Dropped a packet: " + packet);
}
return;
}
UdpPacket udpPacket = packet.get(UdpPacket.class);
SneoUdpTransportMapping tm
= (SneoUdpTransportMapping)agent.getTransportMapping();
if (
(udpPacket.getHeader().getDstPort().value() & 0xFFFF)
== tm.getAddress().getPort()
) {
agent.getContextfulWorkerPool()
.registerContext(new SnmpContext(packet, getter));
tm.processMessage(packet);
}
else {
if (LOGGER.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("Dropped a packet not to me(")
.append(tm.getAddress().getPort())
.append("): ")
.append(packet);
LOGGER.debug(sb.toString());
}
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:32,代码来源:Node.java
示例17: processMessage
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
public void processMessage(Packet packet) {
UdpPacket udpPacket = packet.get(UdpPacket.class);
byte[] snmpMessage = udpPacket.getPayload().getRawData();
InetAddress srcAddr;
IpV4Packet ipV4Packet = packet.get(IpV4Packet.class);
if (ipV4Packet != null) {
srcAddr = ipV4Packet.getHeader().getSrcAddr();
}
else {
srcAddr = packet.get(IpV6Packet.class).getHeader().getSrcAddr();
}
int srcPort = udpPacket.getHeader().getSrcPort().value() & 0xFFFF;
ByteBuffer bis;
if (isAsyncMsgProcessingSupported()) {
byte[] rawData = new byte[snmpMessage.length];
System.arraycopy(snmpMessage, 0, rawData, 0, rawData.length);
bis = ByteBuffer.wrap(rawData);
}
else {
bis = ByteBuffer.wrap(snmpMessage);
}
TransportStateReference stateReference
= new TransportStateReference(
this,
getAddress(),
null,
SecurityLevel.undefined,
SecurityLevel.undefined,
false,
null
);
fireProcessMessage(
new UdpAddress(srcAddr, srcPort),
bis,
stateReference
);
}
开发者ID:kaitoy,项目名称:sneo,代码行数:40,代码来源:SneoUdpTransportMapping.java
示例18: onEvent
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
@Override
public void onEvent(PacketContainer container, long sequence, boolean endOfBatch) throws Exception {
if (shouldSkipEvent(sequence)) {
return;
}
IpV4Packet ipV4Packet = container.getIpV4Packet();
if (ipV4Packet == null) {
return;
}
buffer.clear();
buffer.put(TYPE);
buffer.put(VERSION);
Timestamp timestamp = container.getTimestamp();
buffer.putLong(timestamp.getTime());
buffer.putInt(timestamp.getNanos());
IpV4Packet.IpV4Header ipV4Header = ipV4Packet.getHeader();
buffer.put(ipV4Header.getProtocol().value());
Packet transportLayerPacket = ipV4Packet.getPayload();
if (transportLayerPacket.getPayload() == null) {
return;
}
if (transportLayerPacket instanceof UdpPacket) {
UdpPacket.UdpHeader udpHeader = (UdpPacket.UdpHeader) transportLayerPacket.getHeader();
buffer.put(ipV4Header.getSrcAddr().getAddress());
buffer.putShort(udpHeader.getSrcPort().value());
buffer.put(ipV4Header.getDstAddr().getAddress());
buffer.putShort(udpHeader.getDstPort().value());
} else {
TcpPacket.TcpHeader tcpHeader = (TcpPacket.TcpHeader) transportLayerPacket.getHeader();
buffer.put(ipV4Header.getSrcAddr().getAddress());
buffer.putShort(tcpHeader.getSrcPort().value());
buffer.put(ipV4Header.getDstAddr().getAddress());
buffer.putShort(tcpHeader.getDstPort().value());
}
byte[] content = transportLayerPacket.getPayload().getRawData();
SipContentReader.read(content, (i1, i2) -> {
buffer.position(HEADER_LENGTH);
buffer.limit(buffer.capacity());
int length = i2 - i1;
buffer.putShort((short) length);
buffer.put(content, i1, length);
buffer.flip();
try {
TimeUnit.MILLISECONDS.sleep(delay);
channel.write(buffer);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
开发者ID:sip3io,项目名称:tapir,代码行数:56,代码来源:PacketSender.java
示例19: main
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
public static void main(String[] args) throws UnsupportedLookAndFeelException, AWTException, ClassNotFoundException, InterruptedException,
FontFormatException, InstantiationException, IllegalAccessException, IOException, PcapNativeException, NotOpenException {
System.setProperty("jna.nosys", "true");
if (!Sanity.check()) {
System.exit(1);
}
Settings.init();
Settings.set("autoload", Settings.get("autoload", "0")); //"autoload" is an ini-only toggle for advanced users.
setupTray();
getLocalAddr();
nif = Pcaps.getDevByAddress(addr);
if (nif == null) {
JOptionPane.showMessageDialog(null, "The device you selected doesn't seem to exist. Double-check the IP you entered.", "Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
final int addrHash = addr.hashCode();
final int snapLen = 65536;
final PromiscuousMode mode = PromiscuousMode.NONPROMISCUOUS;
final int timeout = 0;
handle = nif.openLive(snapLen, mode, timeout);
handle.setFilter("udp && less 150", BpfProgram.BpfCompileMode.OPTIMIZE);
ui = new Overlay();
while (running) {
final Packet packet = handle.getNextPacket();
if (packet != null) {
final IpV4Packet ippacket = packet.get(IpV4Packet.class);
if (ippacket != null) {
final UdpPacket udppack = ippacket.get(UdpPacket.class);
if (udppack != null && udppack.getPayload() != null) {
final int srcAddrHash = ippacket.getHeader().getSrcAddr().hashCode();
final int dstAddrHash = ippacket.getHeader().getDstAddr().hashCode();
final int payloadLen = udppack.getPayload().getRawData().length;
if (active.containsKey(srcAddrHash) && srcAddrHash != addrHash) {
if (active.get(srcAddrHash) != null && payloadLen == 68 //Packets are STUN related: 56 is request, 68 is response
&& dstAddrHash == addrHash) {
ui.setPing(ippacket.getHeader().getSrcAddr(), handle.getTimestamp().getTime() - active.get(srcAddrHash).getTime());
active.put(srcAddrHash, null); //No longer expect ping
}
} else {
if (payloadLen == 56 && srcAddrHash == addrHash) {
active.put(ippacket.getHeader().getDstAddr().hashCode(), handle.getTimestamp());
}
}
}
}
}
}
}
开发者ID:PsiLupan,项目名称:MakeLobbiesGreatAgain,代码行数:57,代码来源:Boot.java
示例20: testHandleDnsRequestEmptyPacket
import org.pcap4j.packet.UdpPacket; //导入依赖的package包/类
@Test
public void testHandleDnsRequestEmptyPacket() throws Exception {
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(new byte[0])
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNotNull(mockEventLoop.lastOutgoing);
assertEquals(0, mockEventLoop.lastOutgoing.getLength());
assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());
assertNull(mockEventLoop.lastResponse);
// Check the same thing with one upstream DNS server configured.
tinySetUp();
dnsPacketProxy.upstreamDnsServers.add(Inet4Address.getByAddress(new byte[]{1, 1, 1, 2}));
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastOutgoing);
assertNull(mockEventLoop.lastResponse);
// Check the same thing with enough upstream DNS servers configured.
tinySetUp();
for (byte i = 2; i < 9; i++)
dnsPacketProxy.upstreamDnsServers.add(Inet4Address.getByAddress(new byte[]{1, 1, 1, i}));
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNotNull(mockEventLoop.lastOutgoing);
assertEquals(0, mockEventLoop.lastOutgoing.getLength());
assertEquals(Inet4Address.getByAddress(new byte[]{1, 1, 1, 8}), mockEventLoop.lastOutgoing.getAddress());
assertNull(mockEventLoop.lastResponse);
}
开发者ID:julian-klode,项目名称:dns66,代码行数:54,代码来源:DnsPacketProxyTest.java
注:本文中的org.pcap4j.packet.UdpPacket类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论