1.1 --- a/src/internet-stack/nsc-tcp-l4-protocol.cc Mon Sep 22 22:18:53 2008 +0200
1.2 +++ b/src/internet-stack/nsc-tcp-l4-protocol.cc Tue Sep 23 01:09:43 2008 +0200
1.3 @@ -39,8 +39,8 @@
1.4 #include <dlfcn.h>
1.5 #include <iomanip>
1.6
1.7 -#include <netinet/ip.h>
1.8 -#include <netinet/tcp.h>
1.9 +#include <netinet/in.h>
1.10 +#include <arpa/inet.h>
1.11
1.12 NS_LOG_COMPONENT_DEFINE ("NscTcpL4Protocol");
1.13
1.14 @@ -313,27 +313,31 @@
1.15 void NscTcpL4Protocol::send_callback(const void* data, int datalen)
1.16 {
1.17 Ptr<Packet> p;
1.18 + uint32_t ipv4Saddr, ipv4Daddr;
1.19
1.20 - NS_ASSERT(datalen > (int)sizeof(struct iphdr));
1.21 + NS_ASSERT(datalen > 20);
1.22
1.23 - const uint8_t *rawdata = reinterpret_cast<const uint8_t *>(data);
1.24 - rawdata += sizeof(struct iphdr);
1.25 -
1.26 - const struct iphdr *ipHdr = reinterpret_cast<const struct iphdr *>(data);
1.27
1.28 // create packet, without IP header. The TCP header is not touched.
1.29 // Not using the IP header makes integration easier, but it destroys
1.30 // eg. ECN.
1.31 - p = Create<Packet> (rawdata, datalen - sizeof(struct iphdr));
1.32 + const uint8_t *rawdata = reinterpret_cast<const uint8_t *>(data);
1.33 + rawdata += 20; // skip IP header. IP options aren't supported at this time.
1.34 + datalen -= 20;
1.35 + p = Create<Packet> (rawdata, datalen);
1.36
1.37 - Ipv4Address saddr(ntohl(ipHdr->saddr));
1.38 - Ipv4Address daddr(ntohl(ipHdr->daddr));
1.39 + // we need the real source/destination ipv4 addresses for Send ().
1.40 + const uint32_t *ipheader = reinterpret_cast<const uint32_t *>(data);
1.41 + ipv4Saddr = *(ipheader+3);
1.42 + ipv4Daddr = *(ipheader+4);
1.43 +
1.44 + Ipv4Address saddr(ntohl(ipv4Saddr));
1.45 + Ipv4Address daddr(ntohl(ipv4Daddr));
1.46
1.47 Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
1.48 - if (ipv4 != 0)
1.49 - {
1.50 - ipv4->Send (p, saddr, daddr, PROT_NUMBER);
1.51 - }
1.52 + NS_ASSERT_MSG (ipv4, "nsc callback invoked, but node has no ipv4 object");
1.53 +
1.54 + ipv4->Send (p, saddr, daddr, PROT_NUMBER);
1.55 m_nscStack->if_send_finish(0);
1.56 }
1.57
2.1 --- a/src/internet-stack/nsc-tcp-socket-impl.cc Mon Sep 22 22:18:53 2008 +0200
2.2 +++ b/src/internet-stack/nsc-tcp-socket-impl.cc Tue Sep 23 01:09:43 2008 +0200
2.3 @@ -33,11 +33,9 @@
2.4
2.5 #include <algorithm>
2.6
2.7 -#include <sys/socket.h>
2.8 +// for ntohs().
2.9 +#include <arpa/inet.h>
2.10 #include <netinet/in.h>
2.11 -#include <arpa/inet.h>
2.12 -#include <netinet/ip.h>
2.13 -#include <netinet/tcp.h>
2.14
2.15 #include "sim_interface.h"
2.16 #include "sim_errno.h"
2.17 @@ -307,13 +305,11 @@
2.18 m_remoteAddress = transport.GetIpv4 ();
2.19 m_remotePort = transport.GetPort ();
2.20
2.21 - struct in_addr remoteAddr;
2.22 - uint32_t addr32;
2.23 + std::ostringstream ss;
2.24 + m_remoteAddress.Print(ss);
2.25 + std::string ipstring = ss.str ();
2.26
2.27 - m_remoteAddress.Serialize((uint8_t*)&addr32);
2.28 - remoteAddr.s_addr = addr32;
2.29 -
2.30 - m_nscTcpSocket->connect(inet_ntoa(remoteAddr), m_remotePort);
2.31 + m_nscTcpSocket->connect(ipstring.c_str (), m_remotePort);
2.32 m_state = SYN_SENT;
2.33 return 0;
2.34 }