2009-02-17 15 views
2

我需要爲我的應用程序手動創建TCP/IP標頭。爲此,我使用原始套接字。我的系統操作系統是win xp(SP3)。在Windows中的原始套接字實現?

我的代碼編譯好:)但它拋出一個運行時錯誤:

 
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 
 

我已經設置IP_HDRINCL 1。我在做什麼錯?我也關掉了防火牆,但仍然得到相同的結果。

回答

2

我建議使用WinPcap用於這一目的。即使你知道如何用win32 API正確地做到這一點,它將會非常緩慢。

我已經成功地使用WinPcap將數據包注入千兆以太網端口,硬件可以處理的速度一樣快。

2

不是一個答案,但希望開始...

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.

哪些參數你發送調用?


我發現了原始套接字this更新:

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.

如果適用於XP SP3,雖然不知道......

+0

sendto(s,buf,sizeof(IPV4_HDR)+ sizeof(TCP_HDR)+ payload,0,(SOCKADDR *)&dest,sizeof(dest))) – krishnakumar 2009-02-17 12:41:25

+1

您是否嘗試發送TCP數據? – ng5000 2009-02-17 12:53:04