简体   繁体   中英

Packet Encapsulation in Java

I have been given an assignment for my data communications class where I am required to encapsulate a IP packet over UDP. I then need to encapsulate this manually made packet into an actual UDP packet and send it over IP. This will yield the following protocol stack (blue denotes the headers I will create manually):

在此输入图像描述

Is there an easy way to do this in Java? I understand in CI could use the struct defined for UDP and IP headers in the Linux kernel libraries, manually populate all the fields, and concatenate the information into the packet. However, in Java I will not have access to Linux networking header files. I am also trying to do this without the use of external APIs.

For clarification I plan to develop the application Linux using Eclipse.

Actually, you may try to access Linux kernel libraries through Java Native Access.

like this: ( http://jnaexamples.blogspot.tw/2012/03/java-native-access-is-easy-way-to.html )

You can wrap the TCP packet structure in native c code, and then send it from java socket.

Meanwhile, the jnetpcap library may be your coding reference if you want to assemble the TCP/IP data structure in java. ( http://jnetpcap.com/node/29 )

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