gpt4 book ai didi

c# - 在单元测试中发送错误的 UDP/IP 数据报(故意)?

转载 作者:太空宇宙 更新时间:2023-11-03 13:44:15 29 4
gpt4 key购买 nike

我目前正在为我公司正在开发的设备( radio 编码器)开发单元测试。

可以通过 SNMP(仅限 v1)访问各种统计信息,其中您可以获得由于各种原因丢弃的 UDP 数据报的数量。

我希望能够发送一个包含在错误的 UDP header 中的数据包,其中包含各种错误(校验和错误、 header 中错误的 IP 地址等),以确保错误计数器正常运行。

我无法找到有关如何完成此操作的任何信息,我能够找到(显然)能够正确自动计算校验和的大多数高级网络功能。

最佳答案

你必须求助于原始套接字:

http://www.winsocketdotnetworkprogramming.com/clientserversocketnetworkcommunication8f_3.htmlhttp://www.winsocketdotnetworkprogramming.com/clientserversocketnetworkcommunication8h.html

请注意限制:http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx

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

TCP data cannot be sent over raw sockets. UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address). A call to the bind function with a raw socket for the IPPROTO_TCP protocol is not allowed. Note The bind function with a raw socket is allowed for other protocols (IPPROTO_IP, IPPROTO_UDP, or IPPROTO_SCTP, for example)

关于c# - 在单元测试中发送错误的 UDP/IP 数据报(故意)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15919733/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com