简体   繁体   English

如何使用自定义协议进行数据传输?

[英]How to use a custom protocol for my data transfer?

Friends, 朋友们

I am in a real need of information. 我真的需要信息。 I want to develop a protocol with some fields in it.After some study over the net I came to the conclusion that I can use HDRINCL to let the kernel know that the headers are defined in the program. 我想开发一个包含某些领域的协议,经过网上研究后得出的结论是,我可以使用HDRINCL来让内核知道程序头已定义。 But everwhere I saw that they say All the fields in the header of IP and TCP should be defined. 但是到处都可以看到他们说应该定义IP和TCP标头中的所有字段。 Is it that I can use HDRINCL for my protocol to be used ?? 我可以使用HDRINCL来使用我的协议吗?

Also one more doubt, suppose I want the IP functionality to be use, like fragmentation, by my protocol. 还有一个疑问,假设我希望我的协议使用IP功能,例如分段。 The how to make a call the them ?? 如何打电话给他们?? can I do so ? 我可以这样做吗?

Assuming you're running Linux, it sounds like you want to use a socket of family PF_PACKET and of type SOCK_DGRAM (see man packet ). 假设您正在运行Linux,这听起来像您想使用PF_PACKET系列和SOCK_DGRAM类型的套接字(请参见man packet )。 These sockets will automatically include the layer 2 Ethernet headers for you, but it will be up to you to specify the rest of the packet above that layer. 这些套接字将自动为您提供第2层以太网头,但是由您决定在该层之上的其余数据包。

Unfortunately, the fragmentation logic used in IP is tied very closely to the IP protocol, as it relies on fields in the IP header in order to do fragmentation and reassembly. 不幸的是,IP中使用的分段逻辑非常紧密地与IP协议绑定,因为它依赖IP头中的字段来进行分段和重组。 If you are in a hurry and do not want to worry about fragmentation, you could always limit your packets to be smaller than your MTU. 如果您很着急并且不想担心碎片,可以始终将数据包限制为小于MTU。 Otherwise, I'd suggest using IP fragmentation as a reference point for developing your own fragmentation. 否则,我建议使用IP分段作为开发自己的分段的参考点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅使用NAK的数据传输协议如何才能可靠? - How can a Data Transfer Protocol using NAKs only be reliable? 如何确保使用了我的自定义URL协议? - How to make sure, that my custom URL protocol is used? 如何使用证书身份验证自定义套接字TCP协议? - How to use certificate authentication for custom sockets TCP protocol? 自定义协议的应用程序数据是否需要校验和? - Is a checksum needed for application data of a custom protocol? 如何使用自定义协议测试驱动网络应用程序? - How to test drive a networking application with custom protocol? NAT后面的两个主机用于P2P文件传输的协议是什么? - What protocol to use for P2P file transfer for two hosts behind NAT? 在Node.js中使用自定义传输层协议 - Use custom transport layer protocol in Node.js Tshark - 无法仅显示自定义协议的数据 - Tshark - can't display just data of custom protocol 如何在我的自定义服务器上使用Photon Unity Networking? - How do I use Photon Unity Networking with my custom server? 如何将序列化数据传输到服务器并反序列化 - How to transfer serialized data to the server and deserelize it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM