Y
Y
yanchumak2014-11-09 13:35:53
linux
yanchumak, 2014-11-09 13:35:53

Implementing your own TCP(UDP)/IP stack, how to get an answer?

Good afternoon. It so happened that you need to implement your own TCP (UDP) / IP stack. The application logic resides at the OSI network layer (OSI level 3), i.e. there is a file descriptor from which I can read\write IP datagrams, then I can process each frame in accordance with the TCP / UDP protocol (and this is the OSI transport level - 4). Actually questions:
1. For the TCP protocol, you need to establish a connection and keep "somewhere" a bunch of ip/port str/dst and its socket? (we connect corny - we create a socket through socket and stupidly connect?)
1.1 In a separate thread (fork) to hammer a recv socket to receive data?
1.2 What about protocol flags?
2. The same thing, but for UDP, only TCP / UDP is of interest so far (God forbid, I’ll get to ICMP, but that’s another story, despite the fact that it works in parallel with IP)
ps rummaged through ready-made implementations, as it is not clear how they handle connections. Probably a habit from working with sockets in applications where you don't care about it.
pps I looked in the direction of dunkels.com/adam/miniweb as an example, but there is some kind of tin there, they receive packets from tun-a and send them back to it, is this some kind of trick?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MrFrizzy, 2014-11-10
@yanchumak

Alexander Kolesen - Implementing open-source TCP / IP with ...
Look, here a person implemented a tcp stack on top of userspace on android

S
Sergey, 2014-11-09
Protko @Fesor

God forbid, I will reach ICMP

How are you going to implement TCP without ICMP? You somehow need to confirm the delivery of packages.
The connection is handled quite simply. We make a triple handshake and, upon completion of it, we create some kind of object / structure where all the data we need is stored, the address of the second endpoint, write / read buffers (if you decide to implement congestion control and flow control, well, or just save the last packet and block sending until delivery of this package will not be confirmed).
In general, it seems to me that you just came up with an unbearable problem for yourself ... Why do you need to implement TCP if you have IP datagrams? To whom are these IP datagrams addressed? Who are you going to send them to? Whom to connect with? I think you just need to repackage the data from an IP datagram into a TCP packet.

N
neolink, 2014-11-09
@neolink

Implementing your own TCP(UDP)/IP stack

You yourself decide what you want to do either your own tcp stack, or you use linux network functions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question