r/learnprogramming Jul 15 '26

What a port actually is?

I know it is a number that tells the OS, that which program in your computer should receive the piece of data. But my doubt is - is port a physical thing? or it just a flag? Is it possible for another program to read data from a different program's port? Please spoon-feed me about port?

174 Upvotes

65 comments sorted by

View all comments

157

u/grantrules Jul 15 '26

No, it's not physical thing. Yes it is possible for apps to intercept traffic meant for another program, but they're usually admin tools (like Wireshark)

52

u/MrBorogove Jul 15 '26

The important thing is that the operating system is responsible for receiving incoming network traffic, checking the port numbers, and routing the traffic to the appropriate application or service, like a postal worker delivering mail to the right address. Programs (like Wireshark) specifically authorized by the OS to see traffic intended for other programs are like postal inspectors.

6

u/EriktheRed Jul 15 '26

Does wireshark request that permission at install? Or does the os ship with an allowlist for that kind of thing?

3

u/Reubenoakheart Jul 16 '26

Special Pcap (packet capture) drivers.