[英]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.