We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
下面是两个通过 UDP 套接字进行通信的程序的非常简单的代码示例:一个代码列表创建并发送一个数据包,另一个代码列表接收该数据包。
http://www.abc.se/~m6695/udp.html
注意这些网络函数不是 C 语言本身的一部分,C 语言本身没有网络支持,但它们是标准的(POSIX,我认为)并且在大多数现代 C 实现上以类似的形式可用。
请注意,使用标准功能,您只需指定数据包有效负载、地址、端口和一些标志,您无法控制以太网帧、IP 标头等的确切内容,这些内容是由操作者为您创建的系统。如果您需要对低级数据包进行这种级别的控制,我相信您可以使用 libpcap/winpcap 来实现此目的,或者某些操作系统可能具有“原始”套接字,可以让您执行此操作。
Here is a very simple code example for two programs that talk over a UDP socket: One code listing creates and sends a packet and one receives it.
http://www.abc.se/~m6695/udp.html
Note that these Network functions aren't part of the C Language itself which has no networking support, but they are standard (POSIX, I think) and available in similar forms on most modern C implementations.
Note that with the standard functions, you only specify the packet payload, address, port, and some flags, you don't get to control the exact contents of the ethernet frame, IP headers, etc, those are created for you by the Operating System. If you need that level of control over the low level packet, I believe you can use libpcap/winpcap for that purpose, or some operating systems may have 'raw' sockets which let you do this.