"Rich Blum" <rich_blum@juno.com> skrev i en meddelelse
news:ccdac0da.0308070752.317411f5@posting.google.c om...[color=blue]
> "Just" <swjREMOVETHISDUETOSPAM@it.dk> wrote in message[/color]
news:<bgrrsl$vdo$1@news.cybercity.dk>...[color=blue][color=green]
> > Hi everybody
> >
> > I was wondering if it is possible to use SendTo to send a whole IP[/color][/color]
package[color=blue][color=green]
> > including header to another IP than specified in the package. Say I have[/color][/color]
a[color=blue][color=green]
> > complete package and in it the destination IP is set to 10.0.0.3, but[/color][/color]
now I[color=blue][color=green]
> > want to send the package to a server which has destination IP 10.0.0.2
> >[/color]
> Just -
>
> You can do this using a raw socket type, but you have to build the
> complete IP header, including the checksum values. A short sample
> would be:
>
> Socket s = new Socket(AddressFamily.InterNetwork,
> SocketType.Raw,
> ProtocolType.IP);
> IPEndPoint iep = new
> IPEndPoint(IPAddress.Parse("192.168.1.1"),0);
> s.Bind(iep);
> byte[] data = {0x45, 0x00, 0x00, 0x30, 0xc8, 0x40, 0x40, 0x00,
> 0x80,
> 0x06, 0x00, 0x00, 0xC0, 0xA8, 0x01, 0x01, 0xC0, 0xA8, 0x01,
> 0x05,
> 0x07, 0xe5, 0x00, 0x17, 0xd3, 0x16, 0x3f, 0xe6, 0x00, 0x00,
> 0x00, 0x00, 0x70, 0x02, 0xff, 0xff, 0xe4, 0xcf, 0x00, 0x00,
> 0x02, 0x04, 0x05, 0xb4, 0x01, 0x01, 0x04, 0x02};
>
> IPEndPoint fakeIP = new
> IPEndPoint(IPAddress.Parse("192.168.1.5"), 0);
> s.SetSocketOption(SocketOptionLevel.IP,
> SocketOptionName.HeaderIncluded, 1);
> s.SendTo(data, data.Length, SocketFlags.None, fakeIP);
>
> The first IPEndPoint value must point to a valid local IP address
> so .Net knows what interface to send the packet out on. The second
> IPEndPoint value can point to any fake address, it is just there for
> filler in the SendTo() method. The IP addresses specified in the raw
> data are what appear in the outbound packet. Hope this helps solve
> your problem. Good luck.[/color]
Thanks for the answer...
From that example I can conclude that I can not send an ippackage with the
sendTo function and expect it to go to the specified destination (because of
the fake endpoint).
The problem is, that if I have a package with a destination which is not on
my LAN, I have to send it to the next router, and this means that I cannot
alter the IP destination address, just modify the destination MAC address.
But this is properly to low-level for C#.
I hoped that the sendTo function, somehow was connected to the Datalink
layer and just passed a destination to the datalink layer and here the
destination MAC address was attached.
Now I can see that I have to use an NDIS driver or similar to go down to the
layer and manipulate the package.
[color=blue]
>
> Rich Blum - Author
> "C# Network Programming" (Sybex)
>
http://www.sybex.com/sybexbooks.nsf/Booklist/4176[/color]
BTW great book, bought it a couple of weeks ago. :o)
[color=blue]
> "Network Performance Open Source Toolkit" (Wiley)
>
http://www.wiley.com/WileyCDA/WileyT...471433012.html[/color]