mfontanini / libtins

High-level, multiplatform C++ network packet sniffing and crafting library.
http://libtins.github.io/
BSD 2-Clause "Simplified" License
1.91k stars 377 forks source link

How to send IP packet ? #124

Closed sherifmagdy closed 8 years ago

sherifmagdy commented 8 years ago

when i try to construct and send a packet like below it give me an error on windows ,

PacketSender sender; IP pkt = IP("192.168.0.1") / TCP(22) / RawPDU("foo"); sender.send(pkt);

it work fine if i encapsulate that packet as ethernet frame

mfontanini commented 8 years ago

Is this fixed if you use admin privileges as well?

sherifmagdy commented 8 years ago

it still throw in L3_send with admin priv.

mfontanini commented 8 years ago

This is just how Windows works. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx

Quoting:

On Windows 7, Windows Vista, Windows XP with Service Pack 2 (SP2), and Windows XP with 
Service Pack 3 (SP3), the ability to send traffic over raw sockets has been restricted in 
several ways:

* TCP data cannot be sent over raw sockets.
mfontanini commented 8 years ago

You can send it using ethernet encapsulation because that ends up using pcap_sendpacket which uses the Winpcap driver, which bypasses those restrictions.

mfontanini commented 8 years ago

Closing this as it's an OS limitation, unrelated to libtins.