style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-7505528228218001"
data-ad-slot="1225241371">

Trying to create an ARP packet

3 replies [Last post]
kobe
Offline
Joined: 02/02/2016

Hi
I am trying to create an ARP packet, but it seems I cant set the opcode. Any help will be greatly appreciated.

kobe

DavidJones
Offline
Joined: 06/08/2015
Good luck with the rest of

Good luck with the rest of your project, I will make sure to keep coming back to see how your story unfolds. - Bobby Price

kobe
Offline
Joined: 02/02/2016
the code

it seems the setbytearray() method brings an error with arp. Below is the code and the sample packet, with the setbytearray() array commented

byte[] sourceAddr= {(byte) 172,(byte) 16,(byte) 0,(byte) 250};
byte[] targetAddr = {(byte) 172,(byte) 16,(byte) 1,(byte) 215};
byte[] targetMac= ConvertMacToByte(destinationMac);

int hardwareType = 1;
int protocolType = 2048;
int hardwareLength = 6;
int protocolLength = 4;
int opCode = 1;
System.out.println(getMac().length);
JPacket packet = new JMemoryPacket(60);
packet.order(ByteOrder.BIG_ENDIAN);
packet.setUShort(12, 0x0806);
packet.scan(JProtocol.ETHERNET_ID);
Ethernet ethernet = packet.getHeader(new Ethernet());
ethernet.destination(targetMac);
ethernet.type(0x806);
ethernet.source(getMac());

packet.setUByte(14, 0x40 | 0x05);
packet.scan(JProtocol.ETHERNET_ID);

Arp arp = packet.getHeader(new Arp());
arp.setUShort(0, hardwareType );
arp.setUShort(2, protocolType);
arp.setUByte(4, hardwareLength);
arp.setUByte(5, protocolLength);
arp.setUShort(6, 1);
// arp.setByteArray(8, getMac());// error starts here.any bytes array wing bring an bufferUnderflow exception
//arp.setByteArray(14, sourceAddr);
///arp.setByteArray(18, ConvertMacToByte(destinationMac));
//arp.setByteArray(24,targetMac);
packet.scan(JProtocol.ETHERNET_ID);

packet.scan(Ethernet.ID);
pcp.sendPacket(packet);
return packet;
}

kobe

kobe
Offline
Joined: 02/02/2016
the code

it seems the setbytearray() method brings an error with arp. Below is the code and the sample packet, with the setbytearray() array commented

byte[] sourceAddr= {(byte) 172,(byte) 16,(byte) 0,(byte) 250};
byte[] targetAddr = {(byte) 172,(byte) 16,(byte) 1,(byte) 215};
byte[] targetMac= ConvertMacToByte(destinationMac);

int hardwareType = 1;
int protocolType = 2048;
int hardwareLength = 6;
int protocolLength = 4;
int opCode = 1;
System.out.println(getMac().length);
JPacket packet = new JMemoryPacket(60);
packet.order(ByteOrder.BIG_ENDIAN);
packet.setUShort(12, 0x0806);
packet.scan(JProtocol.ETHERNET_ID);
Ethernet ethernet = packet.getHeader(new Ethernet());
ethernet.destination(targetMac);
ethernet.type(0x806);
ethernet.source(getMac());

packet.setUByte(14, 0x40 | 0x05);
packet.scan(JProtocol.ETHERNET_ID);

Arp arp = packet.getHeader(new Arp());
arp.setUShort(0, hardwareType );
arp.setUShort(2, protocolType);
arp.setUByte(4, hardwareLength);
arp.setUByte(5, protocolLength);
arp.setUShort(6, 1);
// arp.setByteArray(8, getMac());// error starts here.any bytes array wing bring an bufferUnderflow exception
//arp.setByteArray(14, sourceAddr);
///arp.setByteArray(18, ConvertMacToByte(destinationMac));
//arp.setByteArray(24,targetMac);
packet.scan(JProtocol.ETHERNET_ID);

packet.scan(Ethernet.ID);
pcp.sendPacket(packet);
return packet;
}

kobe

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.