2017-05-28 253 views
0

我需要編輯UDP數據包的標題(併發送它與編輯的標題),我想我必須使用原始套接字。UDP - 原始套接字 - C#

我想是這樣的:

byte[] buffer = new byte[]{0x00,0x00}; 
    string ip = "SomeIP" 

    Socket sk = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Raw); 
    sk.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true); 
    sk.SendTo(new byte[] { buffer }, new IPEndPoint(IPAddress.Parse(ip),2017)); 

但我仍然無法編輯標題:(

回答

0
 byte[] buffer = new byte[] { 0x00, 0x00 }; 
     string ip = "SomeIP"; 
     // Set Socket Type to 'Dgram' for connectionless and UDP since your working with UDP 
     Socket sk = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); 
     sk.SendTo(buffer, new IPEndPoint(IPAddress.Parse(ip), 2017)); 
+0

但我不能編輯頁眉。 –