nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.

closes bugzilla #320.
This commit is contained in:
Florian Westphal
2008-11-18 23:14:02 +01:00
parent afe55f740e
commit b6939441cd
2 changed files with 17 additions and 30 deletions

View File

@@ -485,13 +485,12 @@ void NscTcpSocketImpl::CompleteFork(void)
// address <-> Socket handling is done by NSC internally.
// We only need to add the new ns-3 socket to the list of sockets, so
// we use plain Allocate() instead of Allocate(m_localAddress, ... )
uint8_t buf[4];
int port;
size_t buflen = sizeof(buf);
struct sockaddr_in sin;
size_t sin_len = sizeof(sin);
if (0 == m_nscTcpSocket->getpeername((void *) buf, &buflen, &port)) {
m_remotePort = ntohs(port);
m_remoteAddress = m_remoteAddress.Deserialize(buf);
if (0 == m_nscTcpSocket->getpeername((struct sockaddr*) &sin, &sin_len)) {
m_remotePort = ntohs(sin.sin_port);
m_remoteAddress = m_remoteAddress.Deserialize((const uint8_t*) &sin.sin_addr);
m_peerAddress = InetSocketAddress(m_remoteAddress, m_remotePort);
}
@@ -501,9 +500,10 @@ void NscTcpSocketImpl::CompleteFork(void)
NS_ASSERT(m_state == LISTEN);
m_state = ESTABLISHED;
buflen = sizeof(buf);
if (0 == m_nscTcpSocket->getsockname((void *) &buf, &buflen, &port))
m_localAddress = m_localAddress.Deserialize(buf);
sin_len = sizeof(sin);
if (0 == m_nscTcpSocket->getsockname((struct sockaddr *) &sin, &sin_len))
m_localAddress = m_localAddress.Deserialize((const uint8_t*) &sin.sin_addr);
NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from "
<< m_remoteAddress << ":" << m_remotePort
@@ -519,13 +519,11 @@ void NscTcpSocketImpl::ConnectionSucceeded()
{ // We would preferred to have scheduled an event directly to
// NotifyConnectionSucceeded, but (sigh) these are protected
// and we can get the address of it :(
uint8_t buf[4];
int port;
size_t buflen = sizeof(buf);
if (0 == m_nscTcpSocket->getsockname((void *) &buf, &buflen, &port)) {
m_localAddress = m_localAddress.Deserialize(buf);
m_localPort = ntohs(port);
struct sockaddr_in sin;
size_t sin_len = sizeof(sin);
if (0 == m_nscTcpSocket->getsockname((struct sockaddr *) &sin, &sin_len)) {
m_localAddress = m_localAddress.Deserialize((const uint8_t*)&sin.sin_addr);
m_localPort = ntohs(sin.sin_port);
}
NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to "

View File

@@ -20,7 +20,7 @@
*/
#define NSC_VERSION 0x000400
#define NSC_VERSION 0x000500
struct INetStack
{
@@ -149,21 +149,10 @@ struct INetStreamSocket
virtual bool is_connected() = 0;
virtual bool is_listening() = 0;
/*
* addrspace points to a byte buffer of *addrs_len bytes.
* It is filled with a (network order) byte representation of the ip address,
* addrs_len is updated to reflect the length (i.e. 4 or eventually 16 for ipv6).
* *port is updated with the TCP/SCTP etc. port number.
*
* The reason that this doesn't use a *struct sockaddr is that the BSDs
* have an sa_len member in there, Linux does not, so the struct layout is
* different depending on the actual NSC stack and the real host operating
* system.
*/
virtual int getpeername(void *addrspace, size_t *addrs_len, int *port) {
virtual int getpeername(struct sockaddr *sa, size_t *salen) {
return -1;
}
virtual int getsockname(void *addrspace, size_t *addrs_len, int *port) {
virtual int getsockname(struct sockaddr *sa, size_t *salen) {
return -1;
}
/* Optional functions used to get and set variables for this TCP