Sending IP packets [closed]
开发者_开发技巧
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this questionI'm lost. I've been searching the web for days now and I just can't find the answer. I'm more or less a beginner socket programmer but I do understand it.
I want to do the following things:
- Create a custom packet (from scratch, setting every value)
- Send it
Either Java, C++ or C#. Is there an easy to use library for this or is there a core class that allows me to? I've already tried the Java library jnetpcap but that only gave me errors, even when running the examples and following the installation guide for eclipse.
Any help is much appreciated!
Note: It's for windows
jNetPcap is an API based on WinPcap, just install WinPcap and it will work :)
As an alternative, you can try to use other libraries such as Jpcap (for Java) and SharpPcap (for C#)
Java: Socket
http://download.oracle.com/javase/1.4.2/docs/api/java/net/Socket.html
Java: Raw sockets
http://www.savarese.com/software/rocksaw/
C#: TCPClient
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient%28v=vs.71%29.aspx
C#: Raw sockets
http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx
It should be fairly easy looking up examples of all four.
I have used sockets in c++ using winsock in windows and socket bsd in linux.
This was the best guide I found http://beej.us/guide/bgnet/output/html/multipage/index.html
EDIT: Beej's guide has everything: background information, simple examples, advanced topics like data packing and some humour
Quite easy if u do it java.
for starters. http://download.oracle.com/javase/tutorial/networking/datagrams/clientServer.html
Tim,
Every packet needs a Fixed Length header followed by the Body and optionally a trailer. The fixed head length header should have details like the Packet Length(Body Length + Trailer Length), Time stamp, Unique Packet Id (Used to break the big packet into multiple small packets).
The receiver will always read the fixed length header first and determine the packet length and read the rest of the packet.
You need to append the size before every variable length elements like name etc.
Example of simple Packet Structure:
Header Size - 1 Byte
Sending details like Name, ID, Sex
Header
[8] - 1 Byte //size (Name Length + Name + Id + Sex)
Body
[5] - 1 Byte //Name Length
[Jeeva] - N Bytes
[1000] - 1 Byte ID
[0] - 1 Byte Sex (0 - Male, 1- Female)
Note: You need to be careful about Endianess. Ask further questions for clarification
精彩评论