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

(-)a/src/internet-node/ipv4-end-point.cc (+7 lines)
 Lines 42-47   Ipv4EndPoint::GetLocalAddress (void) Link Here 
42
{
42
{
43
  return m_localAddr;
43
  return m_localAddr;
44
}
44
}
45
46
void 
47
Ipv4EndPoint::SetLocalAddress (Ipv4Address address)
48
{
49
  m_localAddr = address;
50
}
51
45
uint16_t 
52
uint16_t 
46
Ipv4EndPoint::GetLocalPort (void)
53
Ipv4EndPoint::GetLocalPort (void)
47
{
54
{
(-)a/src/internet-node/ipv4-end-point.h (+1 lines)
 Lines 37-42   public: Link Here 
37
  ~Ipv4EndPoint ();
37
  ~Ipv4EndPoint ();
38
38
39
  Ipv4Address GetLocalAddress (void);
39
  Ipv4Address GetLocalAddress (void);
40
  void SetLocalAddress (Ipv4Address address);
40
  uint16_t GetLocalPort (void);
41
  uint16_t GetLocalPort (void);
41
  Ipv4Address GetPeerAddress (void);
42
  Ipv4Address GetPeerAddress (void);
42
  uint16_t GetPeerPort (void);
43
  uint16_t GetPeerPort (void);
(-)a/src/internet-node/udp-socket.cc (-14 / +61 lines)
 Lines 20-25    Link Here 
20
 */
20
 */
21
#include "ns3/node.h"
21
#include "ns3/node.h"
22
#include "ns3/inet-socket-address.h"
22
#include "ns3/inet-socket-address.h"
23
#include "ns3/ipv4-route.h"
24
#include "ns3/ipv4.h"
23
#include "udp-socket.h"
25
#include "udp-socket.h"
24
#include "udp-l4-protocol.h"
26
#include "udp-l4-protocol.h"
25
#include "ipv4-end-point.h"
27
#include "ipv4-end-point.h"
 Lines 147-159   int Link Here 
147
int
149
int
148
UdpSocket::Connect(const Address & address)
150
UdpSocket::Connect(const Address & address)
149
{
151
{
152
  Ipv4Route routeToDest;
150
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
153
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
151
  m_defaultAddress = transport.GetIpv4 ();
154
  m_defaultAddress = transport.GetIpv4 ();
152
  m_defaultPort = transport.GetPort ();
155
  m_defaultPort = transport.GetPort ();
156
  if (m_defaultAddress.IsBroadcast () )
157
    {
158
      NS_ASSERT_MSG(false, "UdpSocket::Connect, can't connect to broadcast");
159
    }
153
  NotifyConnectionSucceeded ();
160
  NotifyConnectionSucceeded ();
154
  m_connected = true;
161
  m_connected = true;
155
  return 0;
162
  if (GetIpv4RouteToDestination (m_node, routeToDest, m_defaultAddress) )
156
}
163
    {
164
      uint32_t localIfIndex = routeToDest.GetInterface ();
165
      Ptr<Ipv4> ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
166
      m_endPoint->SetLocalAddress (ipv4->GetAddress(localIfIndex) );
167
    }
168
  return 0;
169
}
170
157
int 
171
int 
158
UdpSocket::Send (const Packet &p)
172
UdpSocket::Send (const Packet &p)
159
{
173
{
 Lines 162-169   UdpSocket::Send (const Packet &p) Link Here 
162
      m_errno = ERROR_NOTCONN;
176
      m_errno = ERROR_NOTCONN;
163
      return -1;
177
      return -1;
164
    }
178
    }
165
  return DoSendTo (p, m_defaultAddress, m_defaultPort);
179
  return DoSend (p);
166
}
180
}
181
182
int 
183
UdpSocket::DoSend (const Packet &p)
184
{
185
  if (m_endPoint == 0)
186
    {
187
      if (Bind () == -1)
188
       {
189
          NS_ASSERT (m_endPoint == 0);
190
         return -1;
191
       }
192
      NS_ASSERT (m_endPoint != 0);
193
    }
194
  if (m_shutdownSend)
195
    {
196
      m_errno = ERROR_SHUTDOWN;
197
      return -1;
198
    } 
199
  m_udp->Send (p, m_endPoint->GetLocalAddress (), m_defaultAddress,
200
                  m_endPoint->GetLocalPort (), m_defaultPort);
201
  NotifyDataSent (p.GetSize ());
202
  return 0;
203
}
204
205
167
int
206
int
168
UdpSocket::DoSendTo (const Packet &p, const Address &address)
207
UdpSocket::DoSendTo (const Packet &p, const Address &address)
169
{
208
{
 Lines 173-179   UdpSocket::DoSendTo (const Packet &p, co Link Here 
173
  return DoSendTo (p, ipv4, port);
212
  return DoSendTo (p, ipv4, port);
174
}
213
}
175
int
214
int
176
UdpSocket::DoSendTo (const Packet &p, Ipv4Address ipv4, uint16_t port)
215
UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port)
177
{
216
{
178
  if (m_endPoint == 0)
217
  if (m_endPoint == 0)
179
    {
218
    {
 Lines 189-207   UdpSocket::DoSendTo (const Packet &p, Ip Link Here 
189
      m_errno = ERROR_SHUTDOWN;
228
      m_errno = ERROR_SHUTDOWN;
190
      return -1;
229
      return -1;
191
    }
230
    }
192
  m_udp->Send (p, m_endPoint->GetLocalAddress (), ipv4,
231
  Ipv4Route routeToDest;
232
  if (GetIpv4RouteToDestination (m_node, routeToDest, dest) )
233
    {
234
      uint32_t localIfIndex = routeToDest.GetInterface ();
235
      Ptr<Ipv4> ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
236
      m_udp->Send (p, ipv4->GetAddress (localIfIndex), dest,
193
		   m_endPoint->GetLocalPort (), port);
237
		   m_endPoint->GetLocalPort (), port);
194
  NotifyDataSent (p.GetSize ());
238
      NotifyDataSent (p.GetSize ());
195
  return 0;
239
      return 0;
196
}
240
    }
241
  else
242
   {
243
      m_errno = ERROR_NOROUTETOHOST;
244
      return -1;
245
   }
246
  return 0;
247
}
248
197
int 
249
int 
198
UdpSocket::SendTo(const Address &address, const Packet &p)
250
UdpSocket::SendTo(const Address &address, const Packet &p)
199
{
251
{
200
  if (m_connected)
201
    {
202
      m_errno = ERROR_ISCONN;
203
      return -1;
204
    }
205
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
252
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
206
  Ipv4Address ipv4 = transport.GetIpv4 ();
253
  Ipv4Address ipv4 = transport.GetIpv4 ();
207
  uint16_t port = transport.GetPort ();
254
  uint16_t port = transport.GetPort ();
(-)a/src/internet-node/udp-socket.h (+1 lines)
 Lines 62-67   private: Link Here 
62
  int FinishBind (void);
62
  int FinishBind (void);
63
  void ForwardUp (const Packet &p, Ipv4Address ipv4, uint16_t port);
63
  void ForwardUp (const Packet &p, Ipv4Address ipv4, uint16_t port);
64
  void Destroy (void);
64
  void Destroy (void);
65
  int DoSend (const Packet &p);
65
  int DoSendTo (const Packet &p, const Address &daddr);
66
  int DoSendTo (const Packet &p, const Address &daddr);
66
  int DoSendTo (const Packet &p, Ipv4Address daddr, uint16_t dport);
67
  int DoSendTo (const Packet &p, Ipv4Address daddr, uint16_t dport);
67
68
(-)a/src/node/ipv4.cc (+5 lines)
 Lines 74-79   GetIpv4RouteToDestination (Ptr<Node> nod Link Here 
74
          route = tempRoute;
74
          route = tempRoute;
75
          return true;
75
          return true;
76
        }
76
        }
77
      else if ( tempRoute.IsDefault () )
78
        {
79
          route = tempRoute;
80
          return true;
81
        }
77
    }
82
    }
78
  return false;
83
  return false;
79
}
84
}
(-)a/src/node/socket.h (+1 lines)
 Lines 58-63   public: Link Here 
58
    ERROR_AFNOSUPPORT,
58
    ERROR_AFNOSUPPORT,
59
    ERROR_INVAL,
59
    ERROR_INVAL,
60
    ERROR_BADF,
60
    ERROR_BADF,
61
    ERROR_NOROUTETOHOST,
61
    SOCKET_ERRNO_LAST
62
    SOCKET_ERRNO_LAST
62
  };
63
  };
63
64

Return to bug 69