EthernetLayer.Write()

Dec 15, 2010 at 4:54 AM

Hi Boaz, i have some doubts about EhernetLayer.Write() .

Two days before you told me to use EthernetLayer with correct Destination MAC address, source address and Payload Layer is need to transfer data from one MAC address to another MAC address without using IPAddress.

I am doing as like you told , but the arguments in write() is confusing me

public override void Write(
	byte[] buffer,
	int offset,
	int payloadLength,  
        ILayer previousLayer,
  ILayer nextLayer )

Here is my sample code ...

            IList allDevices = LivePacketDevice.AllLocalMachine;
            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }

            MacAddress address = LivePacketDeviceExtensions.GetMacAddress(allDevices[0]);
           
            Console.WriteLine("My MAC Address - " + address.ToString()); 
            MacAddress source =address;                  //source and destination both are same
            MacAddress destination = address; // Ethernet Layer EthernetLayer ethernetLayer = new EthernetLayer { Source = source, Destination = destination };

I am still in this line , i dont no how to create payload and how to transfer it to destination.

what is PreviousLayer and NextLayer in Write()...

if am any silly question means forgive me, i am beginner but i think this is a big task for me

Thanks in advance

g_shanmuga

 

Coordinator
Dec 15, 2010 at 5:22 AM

Hi,

 

Please read the user guide.

Specifically the tutorial section about Sending Packets.

 

Boaz.

Dec 15, 2010 at 5:38 AM

Hi Boaz.

I read user guide and also sending packet with SendPacket(), in this tutorial you are using PacketCommunicator and Ipv4 Layer.

Mu doubt is What is the work of Write() in EthernetLayer.

Thanks in advance

g_shanmuga

 

 

 

 

Coordinator
Dec 15, 2010 at 5:45 AM

Hi g_shanmuga,

 

There is no need to call the Write() method yourself.

Use PacketBuilder class like the user guide demonstrates.

 

Boaz.

Dec 15, 2010 at 6:11 AM
Edited Dec 15, 2010 at 6:12 AM

Hi Boaz,

I am using as like  in your samples, but i have an exception

 

 

 
            IList allDevices = LivePacketDevice.AllLocalMachine;
            if (allDevices.Count == 0)
            {
                Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
                return;
            }

            PacketDevice selectedDevice = allDevices[0];
            MacAddress address = LivePacketDeviceExtensions.GetMacAddress(allDevices[0]);
            Console.WriteLine("My MAC Address" + address.ToString()); 
           
            MacAddress source =address;
            MacAddress destination = address; // Ethernet Layer EthernetLayer ethernetLayer = new EthernetLayer { Source = source, Destination = destination }; IpV4Layer ipV4Layer = new IpV4Layer { Source = new IpV4Address("192.168.0.75"), Ttl = 128, // The rest of the important parameters will be set for each packet }; IcmpEchoLayer icmpLayer = new IcmpEchoLayer(); using(PacketCommunicator communicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000)) { PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer); ipV4Layer.Destination = new IpV4Address("192.168.0.75"); ipV4Layer.Identification = (ushort)1; icmpLayer.SequenceNumber = (ushort)1; icmpLayer.Identifier = (ushort)1; Packet packet = builder.Build(DateTime.Now);  //Exception occur here 
               communicator.SendPacket(packet); }
Exception Message

Can't determine protocol automatically from next layer because there is no next layer

Actually what is need of Ipv4Layer, IcmpLayer...

Thanks in advace
g_shanmuga

 

Coordinator
Dec 15, 2010 at 6:21 AM

Hi,

 

First it would be great if you can give full exception details when posting an exception.

I thought you what you need is just Ethernet and then payload, without IPv4.

If you need just Ethernet and a generic Payload, you need to set the Ethernet Type of the Ethernet Layer to a specific type so the packet builder will know how to build the packet.

If you need just Ethernet, IPv4 and a generic Payload (or no payload, like the code you wrote), you need to set the Protocol of the IPv4 Layer to a specific protocol so the packet builder will know how to build the packet.

 

Boaz.

Dec 15, 2010 at 6:36 AM

Hi Boaz,

I need Ethernet and Payload to send data to another ethernet and no need to use Ipv4Layer.

I can set my ethernet layer type using the property EthernetType in EthernetLayer class.

But I need to send data from one ethernet to another ethernet card , i check EthernetType enum it contains lots of types i don't know which is suitable for my task.

 

Thanks in advance

g_shanmuga

 

Coordinator
Dec 15, 2010 at 1:41 PM

This is a network issue, and no a Pcap.Net issue.

I believe pretty much any type will work, it depends how the network devices in your network handle different types and how you want them to handle it.

I would try IPv4 since it's very common to have Ethernet payload (even though the IP part would not interpret right).