[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
how do I find the port number used after a return from accept()
From: |
mathews20 |
Subject: |
how do I find the port number used after a return from accept() |
Date: |
Mon, 09 Sep 2002 13:02:16 -0400 |
I'm trying to determine what port is being used on the server side after
calling accept and it returning with a new file descriptor.
the man page for accept() says:
DESCRIPTION
The accept function is used with connection-based socket
types (SOCK_STREAM, SOCK_SEQPACKET and SOCK_RDM). It
extracts the first connection request on the queue of
pending connections, creates a new connected socket with
mostly the same properties as s, and allocates a new file
descriptor for the socket, which is returned. The newly
created socket is no longer in the listening state. The
original socket s is unaffected by this call. Note that
any per file descriptor flags (everything that can be set
are not inherited across an accept.
Ok, so I'm establishing a listen port, and as I understand it when a
connection/data request comes in the accept returns with a "new connected
socket". So I would assume this new socket is using a different port other
than the original that is being listened on. I've tried calling [on the
return descriptor from accept()]
clientFD = accept(serverFD, NULL, NULL);
getsockname(clientFD, (struct sockaddr *)&tempt, (socklen_t *)&length_t);
cout << htons(tempt.sin_port) << endl;
but tempt.sin_port keeps showing the original port that serverFD was
established with rather than a different port. I've always understood the
port number was used by the network code to route incoming data to the
proper file descriptor. So wouldn't that mean there will be a different
port used by the accept()s return file descriptor? Or am I doing something
wrong in trying to get the correct port number.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- how do I find the port number used after a return from accept(),
mathews20 <=