From b6939441cdedfb3262df229ac790449a044776ad Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Tue, 18 Nov 2008 23:14:02 +0100 Subject: [PATCH] nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface. closes bugzilla #320. --- src/internet-stack/nsc-tcp-socket-impl.cc | 30 +++++++++++------------ src/internet-stack/sim_interface.h | 17 +++---------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/internet-stack/nsc-tcp-socket-impl.cc b/src/internet-stack/nsc-tcp-socket-impl.cc index cbb4d777a..8ec9794f4 100644 --- a/src/internet-stack/nsc-tcp-socket-impl.cc +++ b/src/internet-stack/nsc-tcp-socket-impl.cc @@ -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 " diff --git a/src/internet-stack/sim_interface.h b/src/internet-stack/sim_interface.h index 4ba15c44d..c290235eb 100644 --- a/src/internet-stack/sim_interface.h +++ b/src/internet-stack/sim_interface.h @@ -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