My question is, if machine A have two IP address X,Y.
Can it open port 80 twice,like X:80
and Y:80
?
Say,is port unique by machine or by IP?
The answer is no. The IP address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. The port number is used so the data is directed to the correct location within this device.
Ports and Protocols. Between the protocols User Datagram Protocol (UDP) and Transmission Control Protocol (TCP), there are 65,535 ports available for communication between devices.
An IP address can also include a port number. The port number follows the IP address and is separated by a colon (for example, 250.250. 250.1:8451).
The port number is “tacked on” to the end of the IP address, for example, “192.168. 1.67:80” shows both the IP address and port number. When data arrives at a device, the network software looks at the port number and sends it to the right program.
An IP address specifies a network interface (think an ethernet port on your computer or your WiFi connection). A port number specifies the process to which to route messages arriving on a given network interface. Hence you can use the same port number with different IP addresses, as they specify the port on which to listen on that given interface. Note, though, that you can even reuse a port number with the same IP address if you use the SO_REUSEADDR option when invoking the bind function.
It's unique by IP. When you bind
, (that's the important part), you bind to an IP and a port number, not a machine and a port number. To bind to all addreses you can use something like INADDR_ANY
.
If you want to bind only to a few addresses, you have to do so "by hand". When the OS receives a packet it first checks he is the destination. Then it forwards it to the program that has requested
(through bind, through connect etc) that he be the destination of packets with that specific IP and port number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With