3 ms·
Had to read quite a bit before getting to the core insight: > “So when you listen on a port, you’re really listening on a combination of a port, an IP, a proto
by criticaltinker 5y ago
Had to read quite a bit before getting to the core insight:
> “So when you listen on a port, you’re really listening on a combination of a port, an IP, a protocol, and an IP version?”
> “Yeah, unless you listen on all local IPs. And if you listen on all IPv6 IPs, you also listen on all IPv4 IPs, unless you specifically ask not to before you call bind.”
> “Right. So the operating system must have, like, a hash map from a port and IP pair to a socket, for each combination of TCP or UDP, IPv4 or IPv6.”*
> “To a list of sockets”, Liz corrects. “Remember how I could listen on more than one?”
> “But it also has to handle listening on all ‘home’ IPs, and to be able to find a socket listening on IPv6 from an IPv4 IP.”
- NoWizards 5y agothanks for this summary (the lecture was pretty boring to me). As i understood it, the article explains what happens when you listen to same or similar combinations of a port-ip-protocol-whatever... but i didn't learn what does it mean to "listen" on a port. how does two programs communicate by this way?
- thaumasiotes 5y agoThe port number is one field in a TCP or UDP packet. When you listen, you register with the operating system (or whatever controls the network card, I guess) saying that you want a particular port. When a packet comes in (on the network card), it will be routed to you (on your socket) if it's addressed to you (by including a port number you're registered for). You can think of the port number as the second half of your IP address. As far as the networking goes, an IP address and a port number are basically the same thing. The port number is just the lower bits of the "combined IP address".
- Dylan16807 5y ago"and an IP version" is more of a matter of interpretation though. I'm pretty sure you can model that behavior in terms of binding to an IPv4 address and binding to its associated IPv6 address. Rather than binding to the same IP with different IP versions. And it's worth mentioning that IP doesn't have ports. You don't take a port and then divide it into TCP and UDP use. TCP and UDP each independently build their own version of ports.