Reputation: 2268
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 C I 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.
Upvotes: 3
Views: 1110
Reputation: 11
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)
Upvotes: 1