applications: Check for Bind errors

This commit is contained in:
Alexander Krotov
2017-04-05 12:42:35 +03:00
parent 5fbe6ba313
commit 0a1cd67308
8 changed files with 84 additions and 21 deletions

View File

@@ -130,11 +130,17 @@ void BulkSendApplication::StartApplication (void) // Called at time specified by
if (Inet6SocketAddress::IsMatchingType (m_peer))
{
m_socket->Bind6 ();
if (m_socket->Bind6 () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
}
else if (InetSocketAddress::IsMatchingType (m_peer))
{
m_socket->Bind ();
if (m_socket->Bind () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
}
m_socket->Connect (m_peer);

View File

@@ -153,12 +153,18 @@ void OnOffApplication::StartApplication () // Called at time specified by Start
m_socket = Socket::CreateSocket (GetNode (), m_tid);
if (Inet6SocketAddress::IsMatchingType (m_peer))
{
m_socket->Bind6 ();
if (m_socket->Bind6 () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
}
else if (InetSocketAddress::IsMatchingType (m_peer) ||
PacketSocketAddress::IsMatchingType (m_peer))
{
m_socket->Bind ();
if (m_socket->Bind () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
}
m_socket->Connect (m_peer);
m_socket->SetAllowBroadcast (true);

View File

@@ -114,7 +114,10 @@ void PacketSink::StartApplication () // Called at time specified by Start
if (!m_socket)
{
m_socket = Socket::CreateSocket (GetNode (), m_tid);
m_socket->Bind (m_local);
if (m_socket->Bind (m_local) == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Listen ();
m_socket->ShutdownSend ();
if (addressUtils::IsMulticast (m_local))

View File

@@ -119,22 +119,34 @@ UdpClient::StartApplication (void)
m_socket = Socket::CreateSocket (GetNode (), tid);
if (Ipv4Address::IsMatchingType(m_peerAddress) == true)
{
m_socket->Bind ();
if (m_socket->Bind () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom(m_peerAddress), m_peerPort));
}
else if (Ipv6Address::IsMatchingType(m_peerAddress) == true)
{
m_socket->Bind6 ();
if (m_socket->Bind6 () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (Inet6SocketAddress (Ipv6Address::ConvertFrom(m_peerAddress), m_peerPort));
}
else if (InetSocketAddress::IsMatchingType (m_peerAddress) == true)
{
m_socket->Bind ();
if (m_socket->Bind () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (m_peerAddress);
}
else if (Inet6SocketAddress::IsMatchingType (m_peerAddress) == true)
{
m_socket->Bind6 ();
if (m_socket->Bind6 () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (m_peerAddress);
}
else

View File

@@ -127,22 +127,34 @@ UdpEchoClient::StartApplication (void)
m_socket = Socket::CreateSocket (GetNode (), tid);
if (Ipv4Address::IsMatchingType(m_peerAddress) == true)
{
m_socket->Bind();
if (m_socket->Bind () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom(m_peerAddress), m_peerPort));
}
else if (Ipv6Address::IsMatchingType(m_peerAddress) == true)
{
m_socket->Bind6();
if (m_socket->Bind6 () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (Inet6SocketAddress (Ipv6Address::ConvertFrom(m_peerAddress), m_peerPort));
}
else if (InetSocketAddress::IsMatchingType (m_peerAddress) == true)
{
m_socket->Bind ();
if (m_socket->Bind () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (m_peerAddress);
}
else if (Inet6SocketAddress::IsMatchingType (m_peerAddress) == true)
{
m_socket->Bind6 ();
if (m_socket->Bind6 () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (m_peerAddress);
}
else

View File

@@ -82,7 +82,10 @@ UdpEchoServer::StartApplication (void)
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
m_socket = Socket::CreateSocket (GetNode (), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port);
m_socket->Bind (local);
if (m_socket->Bind (local) == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
if (addressUtils::IsMulticast (m_local))
{
Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket);
@@ -103,7 +106,10 @@ UdpEchoServer::StartApplication (void)
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
m_socket6 = Socket::CreateSocket (GetNode (), tid);
Inet6SocketAddress local6 = Inet6SocketAddress (Ipv6Address::GetAny (), m_port);
m_socket6->Bind (local6);
if (m_socket6->Bind (local6) == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
if (addressUtils::IsMulticast (local6))
{
Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket> (m_socket6);

View File

@@ -121,7 +121,10 @@ UdpServer::StartApplication (void)
m_socket = Socket::CreateSocket (GetNode (), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (),
m_port);
m_socket->Bind (local);
if (m_socket->Bind (local) == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
}
m_socket->SetRecvCallback (MakeCallback (&UdpServer::HandleRead, this));
@@ -132,7 +135,10 @@ UdpServer::StartApplication (void)
m_socket6 = Socket::CreateSocket (GetNode (), tid);
Inet6SocketAddress local = Inet6SocketAddress (Ipv6Address::GetAny (),
m_port);
m_socket6->Bind (local);
if (m_socket6->Bind (local) == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
}
m_socket6->SetRecvCallback (MakeCallback (&UdpServer::HandleRead, this));

View File

@@ -242,22 +242,34 @@ UdpTraceClient::StartApplication (void)
m_socket = Socket::CreateSocket (GetNode (), tid);
if (Ipv4Address::IsMatchingType(m_peerAddress) == true)
{
m_socket->Bind ();
if (m_socket->Bind () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom (m_peerAddress), m_peerPort));
}
else if (Ipv6Address::IsMatchingType(m_peerAddress) == true)
{
m_socket->Bind6 ();
if (m_socket->Bind6 () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (Inet6SocketAddress (Ipv6Address::ConvertFrom (m_peerAddress), m_peerPort));
}
else if (InetSocketAddress::IsMatchingType (m_peerAddress) == true)
{
m_socket->Bind ();
if (m_socket->Bind () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (m_peerAddress);
}
else if (Inet6SocketAddress::IsMatchingType (m_peerAddress) == true)
{
m_socket->Bind6 ();
if (m_socket->Bind6 () == -1)
{
NS_FATAL_ERROR ("Failed to bind socket");
}
m_socket->Connect (m_peerAddress);
}
else