View | Details | Raw Unified | Return to bug 316
Collapse All | Expand All

(-)a/src/internet-stack/nsc-tcp-l4-protocol.cc (-14 / +8 lines)
 Lines 38-46    Link Here 
38
#include <sstream>
38
#include <sstream>
39
#include <dlfcn.h>
39
#include <dlfcn.h>
40
#include <iomanip>
40
#include <iomanip>
41
42
#include <netinet/ip.h>
43
#include <netinet/tcp.h>
44
41
45
NS_LOG_COMPONENT_DEFINE ("NscTcpL4Protocol");
42
NS_LOG_COMPONENT_DEFINE ("NscTcpL4Protocol");
46
43
 Lines 313-334    Link Here 
313
310
314
void NscTcpL4Protocol::send_callback(const void* data, int datalen)
311
void NscTcpL4Protocol::send_callback(const void* data, int datalen)
315
{
312
{
316
  Ptr<Packet> p;
313
  static const int iphdrlen = 20;
314
  const uint8_t *rawdata = reinterpret_cast<const uint8_t *>(data);
317
315
318
  NS_ASSERT(datalen > (int)sizeof(struct iphdr));
316
  Ipv4Address saddr = Ipv4Address::Deserialize (&rawdata[12]);
319
317
  Ipv4Address daddr = Ipv4Address::Deserialize (&rawdata[16]);
320
  const uint8_t *rawdata = reinterpret_cast<const uint8_t *>(data);
321
  rawdata += sizeof(struct iphdr);
322
323
  const struct iphdr *ipHdr = reinterpret_cast<const struct iphdr *>(data);
324
318
325
  // create packet, without IP header. The TCP header is not touched.
319
  // create packet, without IP header. The TCP header is not touched.
326
  // Not using the IP header makes integration easier, but it destroys
320
  // Not using the IP header makes integration easier, but it destroys
327
  // eg. ECN.
321
  // eg. ECN.
328
  p = Create<Packet> (rawdata, datalen - sizeof(struct iphdr));
322
  NS_ASSERT (datalen > iphdrlen);
329
323
  datalen -= iphdrlen;
330
  Ipv4Address saddr(ntohl(ipHdr->saddr));
324
  rawdata += iphdrlen;
331
  Ipv4Address daddr(ntohl(ipHdr->daddr));
325
  Ptr<Packet> p = Create<Packet> (rawdata, datalen);
332
326
333
  Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
327
  Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
334
  if (ipv4 != 0)
328
  if (ipv4 != 0)
(-)a/src/internet-stack/nsc-tcp-socket-impl.cc (-13 / +11 lines)
 Lines 33-48    Link Here 
33
33
34
#include <algorithm>
34
#include <algorithm>
35
35
36
#include <sys/socket.h>
37
#include <netinet/in.h>
38
#include <arpa/inet.h>
39
#include <netinet/ip.h>
40
#include <netinet/tcp.h>
41
42
#include "sim_interface.h"
36
#include "sim_interface.h"
43
#include "sim_errno.h"
37
#include "sim_errno.h"
44
38
45
NS_LOG_COMPONENT_DEFINE ("NscTcpSocketImpl");
39
NS_LOG_COMPONENT_DEFINE ("NscTcpSocketImpl");
40
41
#define nsc_bytswap_16(x) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
46
42
47
using namespace std;
43
using namespace std;
48
44
 Lines 307-319    Link Here 
307
  m_remoteAddress = transport.GetIpv4 ();
303
  m_remoteAddress = transport.GetIpv4 ();
308
  m_remotePort = transport.GetPort ();
304
  m_remotePort = transport.GetPort ();
309
305
310
  struct in_addr remoteAddr;
306
  uint8_t addr[4];
311
  uint32_t addr32;
312
307
313
  m_remoteAddress.Serialize((uint8_t*)&addr32);
308
  m_remoteAddress.Serialize (addr);
314
  remoteAddr.s_addr = addr32;
309
  Ipv4Address ipAddr = Ipv4Address::Deserialize (addr);
310
  std::ostringstream addrss;
311
  ipAddr.Print (addrss);
312
  std::string addrStr = addrss.str();
315
313
316
  m_nscTcpSocket->connect(inet_ntoa(remoteAddr), m_remotePort);
314
  m_nscTcpSocket->connect (addrStr.c_str (), m_remotePort);
317
  m_state = SYN_SENT;
315
  m_state = SYN_SENT;
318
  return 0;
316
  return 0;
319
}
317
}
 Lines 497-503    Link Here 
497
  size_t buflen = sizeof(buf);
495
  size_t buflen = sizeof(buf);
498
496
499
  if (0 == m_nscTcpSocket->getpeername((void *) buf, &buflen, &port)) {
497
  if (0 == m_nscTcpSocket->getpeername((void *) buf, &buflen, &port)) {
500
    m_remotePort = ntohs(port);
498
    m_remotePort = nsc_bytswap_16 (port);
501
    m_remoteAddress = m_remoteAddress.Deserialize(buf);
499
    m_remoteAddress = m_remoteAddress.Deserialize(buf);
502
    m_peerAddress = InetSocketAddress(m_remoteAddress, m_remotePort);
500
    m_peerAddress = InetSocketAddress(m_remoteAddress, m_remotePort);
503
  }
501
  }
 Lines 532-538    Link Here 
532
  size_t buflen = sizeof(buf);
530
  size_t buflen = sizeof(buf);
533
  if (0 == m_nscTcpSocket->getsockname((void *) &buf, &buflen, &port)) {
531
  if (0 == m_nscTcpSocket->getsockname((void *) &buf, &buflen, &port)) {
534
    m_localAddress = m_localAddress.Deserialize(buf);
532
    m_localAddress = m_localAddress.Deserialize(buf);
535
    m_localPort = ntohs(port);
533
    m_localPort = nsc_bytswap_16 (port);
536
  }
534
  }
537
535
538
  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to "
536
  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to "

Return to bug 316