org.bdware.dogp.sample.DOGPDstNaiveFiller Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.dogp.sample;
import io.netty.channel.ChannelHandlerContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.dogp.DOGPRequestHandler;
import org.bdware.dogp.codec.DOGPMessage;
public class DOGPDstNaiveFiller implements DOGPRequestHandler {
byte[] ipAndPort;
RecvCounter counter;
static Logger LOGGER = LogManager.getLogger(DOGPDstNaiveFiller.class);
public DOGPDstNaiveFiller(String ip, int port) {
ipAndPort = new byte[6];
String[] splited = ip.split("\\.");
assert splited.length == 4;
for (int i = 0; i < splited.length; i++) {
int val = Integer.valueOf(splited[i]);
ipAndPort[i] = (byte) (val & 0xff);
}
ipAndPort[4] = (byte) ((port & 0xff00) >> 8);
ipAndPort[5] = (byte) (port & 0xff);
counter = new RecvCounter("DOGPDstNaiveFiller.class");
counter.start();
}
@Override
public DOGPMessage onRequest(ChannelHandlerContext ctx, DOGPMessage msg) {
if (msg.opcode == 1)
msg.opcode = 2;
counter.inc();
return msg.setDst(ipAndPort);
}
}