I was wondering how to, using C, find out what port a client is currently listening to. ie, I want to know what the source port is, not the destination port.
Thanks in advance!
I was wondering how to, using C, find out what port a client is currently listening to. ie, I want to know what the source port is, not the destination port.
Thanks in advance!
If you're talking about how to scan for all open ports, then you might be after a port scanner. There are many many many many source codes available but I definitely don't recommend you use one of them, they are usually slow even if multithreading is enabled. Why? There's nmap
: http://nmap.org/
The socket address structure should be filled-in by the connect() system-call. Check it after a successful return from that call.
Depending on what you want (which I'm too obtuse to guess right now), you want to call either getsockname() or getpeername().