This project is read-only.

Error: Sender protocol address length is 15 bytes while target protocol address length is 14 bytes

Jun 10, 2011 at 5:10 AM
Edited Jun 10, 2011 at 5:10 AM

I want to create an arp request packets, however in the implementation process failed

"Sender protocol address length is 15 bytes while target protocol address length is 14 bytes"


This is my code

 

using (PacketCommunicator communicator = selectedDevice.Open(100, // name of the device
                                                                         PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                                                         1000)) // read timeout
            {
                // Supposing to be on ethernet, set mac source to 1:1:1:1:1:1
                MacAddress source = new MacAddress("00:22:19:F0:57:FC");

                // set mac destination to 2:2:2:2:2:2
                MacAddress destination = new MacAddress("00:1f:e2:69:17:4f");
               
                // Create the packets layers

                // Ethernet Layer
                EthernetLayer ethernetLayer = new EthernetLayer
                                                  {
                                                      Source = source,
                                                      Destination = destination
                                                  };
               // ushort macsource = ushort.Parse("00:22:19:F0:57:FC");
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] macsource = encoding.GetBytes("00:22:19:F0:57:FC");
                ASCIIEncoding encoding1 = new ASCIIEncoding();
                byte[] macdest = encoding1.GetBytes("FF:FF:FF:FF:FF:FF");
                ASCIIEncoding encoding2 = new ASCIIEncoding();
                byte[] ipsource = encoding2.GetBytes("192.168.137.221");
                ASCIIEncoding encoding3 = new ASCIIEncoding();
                byte[] ipdest = encoding3.GetBytes("192.168.137.25");
                ArpLayer arp = new ArpLayer
                {
                    SenderHardwareAddress = new System.Collections.ObjectModel.ReadOnlyCollection<byte>(macsource),
                    TargetHardwareAddress = new System.Collections.ObjectModel.ReadOnlyCollection<byte>(macdest),
                    SenderProtocolAddress = new System.Collections.ObjectModel.ReadOnlyCollection<byte>(ipsource),
                    TargetProtocolAddress = new System.Collections.ObjectModel.ReadOnlyCollection<byte>(ipdest),
                    Operation = ArpOperation.Request,
                   
                    ProtocolType = EthernetType.IpV4,
                    

                };


                // Create the builder that will build our packets
                PacketBuilder builder = new PacketBuilder(ethernetLayer, arp);

                    // Build the packet
                    Packet packet = builder.Build(DateTime.Now);

                    // Send down the packet
                    communicator.SendPacket(packet);
               // }
            }

Coordinator
Jun 11, 2011 at 1:12 PM

Hi haonhien,

 

Converting a MacAddress string to bytes using ASCII Encoding isn't useful in this case.

Create a MacAddress and write it to a 6 bytes array.

 

MacAddress address = new MacAddress("00:22:19:F0:57:FC");

byte[] addressBytes = new byte[6];

addressBytes.Write(0, address, Endianity.Small);

 

I'm not completely positive that Small Endianity is correct here, but you can try both small and big and see what works (for example, look in Wireshark).

 

Boaz.

Jun 12, 2011 at 5:52 AM
Edited Jun 12, 2011 at 5:54 AM

Thank brickner!

addressBytes.Write(0, address, Endianity.Big);

brickner can send me the nick yahoo