tags:

views:

1843

answers:

4

I need to create TCP/IP headers manually for my application. For that i used Raw socket. My system os is win xp (SP3).

My code compiles fine :) but it throws a run time error:

Initialising Winsock...Initialised successfully. Creating Raw TCP Socket...Raw TCP Socket Created successfully. Setting the socket in RAW mode...Successful. Enter hostname : 192.168.1.152

Resolving Hostname...Resolved. Enter Source IP : 192.168.1.151

Sending packet... Error sending Packet : 10022

I have set IP_HDRINCL to 1. What am i doing wrong? I switched off the firewall too but still get the same result.

+1  A: 

Hi - not an answer, but hopefully a start...

From MSDN:

WSAEINVAL 10022 Invalid argument. Some invalid argument was supplied (for example, specifying an invalid level to the setsockopt function). In some instances, it also refers to the current state of the socket—for instance, calling accept on a socket that is not listening.

What are the arguments to your send call?


I found this update on raw sockets:

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

  • TCP data cannot be sent over raw sockets.

Not sure if that applies to XP SP3 though...

ng5000
krishnakumar
Are you trying to send TCP data?
ng5000
(I guess so given that you have a TCP header) - see my update to answer.
ng5000
ya i have TCP header also
krishnakumar
+2  A: 

I suggest using WinPcap for this purpose. Even when you figure out how to do this properly with the win32 API it is going to be horribly slow.

I've used WinPcap successfully to inject packets to a Gigabit ethernet port as fast as the hardware can handle.

shoosh
A: 

Microsoft has limited the RAWSockets, but just use WinPcap http://www.winpcap.org/ . With that you can send all kind of packets.

dfak