简体   繁体   中英

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. But everwhere I saw that they say All the fields in the header of IP and TCP should be defined. Is it that I can use HDRINCL for my protocol to be used ??

Also one more doubt, suppose I want the IP functionality to be use, like fragmentation, by my protocol. 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 ). 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.

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. 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. Otherwise, I'd suggest using IP fragmentation as a reference point for developing your own fragmentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM