This is more hypothetical at this point but lets say I have a TCP server written in C running on Linux. Is it possible to obtain the destination name from an individual packet? For example, if client connects and my server is located at www.example.com. I would like to be able to obtain "www.example.com" from the incoming packet.
My end goal is to separate network traffic by destination name similar to the way that IIS does on Windows with bindings for websites.
It would be nice to have multiple services running on the same machine and be accessible through the same port: 443, but be able to be separated by domain name. If I can obtain the destination name from the packet, I'm pretty sure that I can write something like this fairly easily.
--Edit I have done a little bit of research but have come up empty. I've looked through previous servers that I have written and I don't think I can do it with the existing Linux socket layer. I might have to go lower than that.
No, because the destination hostname is never sent.
The sender uses DNS to find the IP address for the host it wants to communicate with, then sends a packet to that IP address. (Lower level still, the IP address is translated to a MAC address, which is what the hardware layer uses)
Your TCP sockets layer should allow you to see the source and destination IP addresses for the socket, and you'd then have to do a reverse-DNS lookup to translate that back to a hostname. But remember that one IP address could translate to multiple host names...
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments