How to find existing TCP/socket?

5 pts.
Tags:
Socket
TCP
How do I find an existing TCP/socket?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

If it’s a server socket, you should call listen() on your socket, and then getsockname() to find the port number on which it is listening:

struct sockaddr_in sin;

socklen_t len = sizeof(sin);

if (getsockname(sock, (struct sockaddr *)&sin, &len) == -1)

    perror(“getsockname”);

else

    printf(“port number %d\n”, ntohs(sin.sin_port));

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Subhendu Sen
    What is the environment there? Is it an office / personal use. Is this a mixed OS(s), or they are all same. Not so cleared, actually what you wanted to achieve. Did you want to check all open TCP connections. Or just wanted to check TCP settings. However, you can try this command on command prompt for help, netstat -a -o -n
    139,010 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: