packet decapsulation

Programming, for all ages and all languages.
Post Reply
icealys
Member
Member
Posts: 60
Joined: Mon Feb 17, 2014 3:54 pm

packet decapsulation

Post by icealys »

if the source address and all other low level header information gets decapsulated or removed by a server and the data reaches the server's application layer, then how does the application in the server know what source address to send the data back to if all that information was previously stripped away?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: packet decapsulation

Post by thepowersgang »

Simple - The application is informed of how to address the return packets (through metadata associated with the data).

(This metadata might just be contained within the transport layer, i.e. a TCP connection, or be propagated up for UDP sockets)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: packet decapsulation

Post by Combuster »

It's called a socket.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
icealys
Member
Member
Posts: 60
Joined: Mon Feb 17, 2014 3:54 pm

Re: packet decapsulation

Post by icealys »

so if the application layer just receives the data without any of the headers...that means that the metadata would be part of the payload? The application on the server is what needs to send the data back to the client, so the application on the server would need to receive the metadata. I don't see it being anywhere else but the payload because all of the lower layers(3 and 4) are stripped away before it gets to the application.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: packet decapsulation

Post by bluemoon »

Application get those meta data from socket abstraction and API.
For BSD-socket, you get the peer address upon recvfrom() for udp packet, and use such address to response.
For tcp, application can just response to a socket object without much care, or get address with getpeername().
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: packet decapsulation

Post by Kevin »

Why don't you just try and write some simple network servers and clients for one or two existing OSes? This would answer your question how existing OSes do things.
Developer of tyndur - community OS of Lowlevel (German)
icealys
Member
Member
Posts: 60
Joined: Mon Feb 17, 2014 3:54 pm

Re: packet decapsulation

Post by icealys »

hmm...I looked up getpeername() and its part of the winsocks functions...does that invoke a system call or is that just a function to retrieve data in user space?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: packet decapsulation

Post by thepowersgang »

Does it matter? It's implementation defined how those functions actually work, one system may do it as a specific system call, another might use an ioctl, a third might just read from a readonly page provided by the kernel, a fourth might have the entire networking stack in userland (and hence that call would never involve the kernel).
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply