请问有人可以帮忙用 c/c++ 编写服务器客户端原始套接字程序吗?
我是原始套接字的新手。我想编写一个服务器和一个客户端应用程序,它们使用原始套接字发送和接收一个或多个文件中的原始数据。每个文件可能包含一个或多个 50 字节的数据段,每个数据段都有指定的分隔符(即空格、回车符等)。我的服务器的工作是从文件中读取并一次发送每个段。每个数据包应该只包含数据,而不包含任何传统的标头信息,例如以太网标头(如 MAC 地址)(数据包可能在数据包前面包含某种形式的数据,以指示数据包的长度和/或开始以及分隔符以指示数据包的结尾)。客户端应用程序应该简单地监听 port,解析数据并将原始数据写入文件。
请指导我。我发现了许多原始套接字程序,但是没有一个是明确的。如果有人能给我一个坚实的开始,那就太好了。
I am new to raw socket. I want write a server and a client application that use raw sockets to send and receive raw data in one or more files. Each file may contain one or more data segments of 50 bytes each with a designated delimiters (i.e., space, carriage return, and etc.) The job of my server is to read from the file and send each segment at a time. Each packet should only contain the data without any traditional header information such as the Ethernet header like the MAC addresses (the packet may contain some form of data in front of the packet to indicate the length and/or the start of the packet and the delimiter to indicate the end of the packet). The client application should simply listen to the
port, parse the data and write the raw data into a file.
Please, guide me. I have found many raw socket programs but, none were clear. If anybody could give me a solid start then that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以在这里看到:http://sock-raw.org/papers/sock_raw,但是什么你说的确实有可能。
事实上,想象一下,在您的数据中,您有与可路由协议匹配的数据,数据包将被路由。事实上,如果您查看文档,原始套接字句柄标头和有效负载。您必须有一个标头(在您的情况下,它必须以 0 开头表示个人标头,并且在没有标头之后,仅表示有效负载)。而且,也许它可以与非常基本的路由器/交换机一起使用,但现在,这听起来很困难,因为路由器查看数据并可能认为这是损坏的数据。
You can see here : http://sock-raw.org/papers/sock_raw, but what you say is really possible.
In fact, imagine that, in your data, you have data that match a protocol which can be routed, the packet will be routed. Indeed, if you see documentation, Raw socket handle header and payload. You MUST have a header (in your case, it must begin with 0 to say personnal header, and after no header, juste payload). And, maybe it can be work with a very basic router/switch, but nowaday, it's sound difficult because router look data and may imagine this is corrupted data.