-
Packet sending
Hello, I've discovered that using an application called scapy i can send network packets to any address,port, subnet. The thing that caught my attention was the option to modify the source of the packet in the packet that was sent. I want to do that in c++. So far, all i can do is something like this:
Code:
WSAStartup(0x101,&wsadata);
bsock=socket(AF_INET, SOCK_STREAM, 0);
sinb.sin_family=AF_INET;
sinb.sin_addr.s_addr=inet_addr(ip);
sinb.sin_port=htons(port);
connect( bsock, (SOCKADDR*) &sinb, sizeof(SOCKADDR_IN) );
Any help or reference to a proper tutorial will be welcomed. Thanks
-
Well, seeing you called WSAStartup, I am assuming you are on windows.
http://msdn.microsoft.com/en-us/libr...16(VS.85).aspx
This has great documentation and examples.
http://beej.us/guide/bgnet/
This is also a good reference as well. The examples here are for a unix type environment, but most of it is similar. It also shows some good techniques on how to do some advanced topics.
-
Source spoofing is usually considered evil. Moreover, it doesn't work unless you are within the core routing network.
You can set the source IP to something that's not your real IP, but firstly, the socket layer will not allow you to bind to an IP which isn't configured on an interface, and secondly, even if you send a raw packet, your ISP's routers will detect the lie and drop the packet on the floor.
You might be able to source spoof within a LAN, if the routers are configured stupidly. Anyway, don't do it.
-
i've googled a bit and found out that i can send raw packets by registering a new protocol driver to which i later write to through a handle (http://www.codeproject.com/KB/IP/sendrawpacket.aspx). Is it the only way?