【问题标题】:UDP - Raw Sockets - C#UDP - 原始套接字 - C#
【发布时间】:2017-10-28 21:07:32
【问题描述】:

我需要编辑 UDP 数据包的标头(并使用已编辑的标头发送),我想我必须使用原始套接字。

我尝试过这样的事情:

    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));

但我仍然无法编辑标题:(

【问题讨论】:

    标签: c# sockets udp


    【解决方案1】:
            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));
    

    【讨论】:

      猜你喜欢
      • 2016-08-01
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      相关资源
      最近更新 更多