Y
Y
yanchumak2014-11-03 22:52:32
linux
yanchumak, 2014-11-03 22:52:32

How to send/receive OSI layer 3 packets to the world?

There is a file descriptor for the tun0 virtual interface and wrapped all traffic through it. When sending data through this interface in an eternal loop, I read data through read in the form of datagrams of the 3rd level of the OSI network model.
The packet contains all relevant information, sender/destination address/port, protocol, packet length, and actual data. The question is how to programmatically redirect all incoming packets to this interface to the "world" and at the same time receive a response and write back to this interface tun0 ?
I can parse the packet, but I don’t understand how to send it so that the answer comes, and it’s also not clear what to do with the TCP packet, if UDP sent everything clearly, although it’s not clear how to get the answer, but with TCP the problem is to keep the connection for each package?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
brutal_lobster, 2014-11-04
@brutal_lobster

What do you write? Is it really necessary to handle everything by hand?
For the gist of the matter, look at lwn.net/images/pdf/LDD3/ch17.pdf

Y
yanchumak, 2014-11-04
@yanchumak

yes, you need to process it with your hands, I write a sniffer. Thanks for the link, but it's a bit different :(
The point is, I have a "raw" IP packet, I need to send it to the world via TCP / UPD (depending on the headers). I repeat, I parse the headers and packet structure according to RFC: Any hints would be welcome. Thanks!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question