src/internet/model/ipv4-raw-socket-impl.cc
author Brian Swenson <bswenson3@gatech.edu>
Tue, 22 Apr 2014 11:52:55 -0400
changeset 10694 4af272d94cfd
parent 10652 dc18deba4502
child 10968 2d29fee2b7b8
permissions -rw-r--r--
Bug 1791
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7256
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
6333
c461f7a25895 Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6173
diff changeset
     2
#include <netinet/in.h>
7485
9bec9af5e3c8 make ns-3 compile on FreeBSD-8.2
Colin Perkins <csp@csperkins.org>
parents: 7385
diff changeset
     3
#include <sys/socket.h>
9bec9af5e3c8 make ns-3 compile on FreeBSD-8.2
Colin Perkins <csp@csperkins.org>
parents: 7385
diff changeset
     4
#include <sys/types.h>
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
#include "ipv4-raw-socket-impl.h"
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
#include "ipv4-l3-protocol.h"
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
#include "icmpv4.h"
6442
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
     8
#include "ns3/ipv4-packet-info-tag.h"
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
#include "ns3/inet-socket-address.h"
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
#include "ns3/node.h"
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
#include "ns3/packet.h"
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
#include "ns3/uinteger.h"
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    13
#include "ns3/boolean.h"
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
#include "ns3/log.h"
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
NS_LOG_COMPONENT_DEFINE ("Ipv4RawSocketImpl");
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
namespace ns3 {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
10652
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10410
diff changeset
    20
NS_OBJECT_ENSURE_REGISTERED (Ipv4RawSocketImpl);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
Ipv4RawSocketImpl::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
  static TypeId tid = TypeId ("ns3::Ipv4RawSocketImpl")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
    .SetParent<Socket> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
    .AddAttribute ("Protocol", "Protocol number to match.",
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    28
                   UintegerValue (0),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    29
                   MakeUintegerAccessor (&Ipv4RawSocketImpl::m_protocol),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    30
                   MakeUintegerChecker<uint16_t> ())
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
    .AddAttribute ("IcmpFilter", 
7697
2a250bff1466 Bug 1319 - Clarify Ipv4RawSocketImpl ICMP filter limitations
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7485
diff changeset
    32
                   "Any icmp header whose type field matches a bit in this filter is dropped. Type must be less than 32.",
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    33
                   UintegerValue (0),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    34
                   MakeUintegerAccessor (&Ipv4RawSocketImpl::m_icmpFilter),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    35
                   MakeUintegerChecker<uint32_t> ())
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    36
    // 
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    37
    //  from raw (7), linux, returned length of Send/Recv should be
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    38
    // 
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    39
    //            | IP_HDRINC on  |      off    |
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    40
    //  ----------+---------------+-------------+-
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    41
    //  Send(Ipv4)| hdr + payload | payload     |
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    42
    //  Recv(Ipv4)| hdr + payload | hdr+payload |
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    43
    //  ----------+---------------+-------------+-
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    44
    .AddAttribute ("IpHeaderInclude", 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    45
                   "Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).",
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    46
                   BooleanValue (false),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    47
                   MakeBooleanAccessor (&Ipv4RawSocketImpl::m_iphdrincl),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    48
                   MakeBooleanChecker ())
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    49
  ;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  return tid;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
Ipv4RawSocketImpl::Ipv4RawSocketImpl ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  m_err = Socket::ERROR_NOTERROR;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
  m_node = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  m_src = Ipv4Address::GetAny ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
  m_dst = Ipv4Address::GetAny ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
  m_protocol = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  m_shutdownSend = false;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
  m_shutdownRecv = false;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
Ipv4RawSocketImpl::SetNode (Ptr<Node> node)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9147
diff changeset
    68
  NS_LOG_FUNCTION (this << node);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  m_node = node;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
void
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
Ipv4RawSocketImpl::DoDispose (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  m_node = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  Socket::DoDispose ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
enum Socket::SocketErrno 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
Ipv4RawSocketImpl::GetErrno (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  return m_err;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
}
6689
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    86
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    87
enum Socket::SocketType
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    88
Ipv4RawSocketImpl::GetSocketType (void) const
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    89
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9147
diff changeset
    90
  NS_LOG_FUNCTION (this);
6692
591fb1aa0ca4 Avoid enum name collision in socket
Josh Pelkey <jpelkey@gatech.edu>
parents: 6689
diff changeset
    91
  return NS3_SOCK_RAW;
6689
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    92
}
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    93
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
Ptr<Node> 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
Ipv4RawSocketImpl::GetNode (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
  return m_node;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
Ipv4RawSocketImpl::Bind (const Address &address)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  NS_LOG_FUNCTION (this << address);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  if (!InetSocketAddress::IsMatchingType (address))
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
      m_err = Socket::ERROR_INVAL;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
      return -1;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
  InetSocketAddress ad = InetSocketAddress::ConvertFrom (address);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  m_src = ad.GetIpv4 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
Ipv4RawSocketImpl::Bind (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
  m_src = Ipv4Address::GetAny ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
int 
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   121
Ipv4RawSocketImpl::Bind6 (void)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   122
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9147
diff changeset
   123
  NS_LOG_FUNCTION (this);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   124
  return (-1);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   125
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   126
int 
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
Ipv4RawSocketImpl::GetSockName (Address &address) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9147
diff changeset
   129
  NS_LOG_FUNCTION (this << address);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
  address = InetSocketAddress (m_src, 0);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
Ipv4RawSocketImpl::Close (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
  NS_LOG_FUNCTION (this);
8922
922350836734 Bug 1477: Click doesn't work with raw sockets
Lalith Suresh <suresh.lalith@gmail.com>
parents: 7758
diff changeset
   137
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
  if (ipv4 != 0)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
      ipv4->DeleteRawSocket (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
Ipv4RawSocketImpl::ShutdownSend (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
  m_shutdownSend = true;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
Ipv4RawSocketImpl::ShutdownRecv (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  m_shutdownRecv = true;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
Ipv4RawSocketImpl::Connect (const Address &address)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
  NS_LOG_FUNCTION (this << address);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
  if (!InetSocketAddress::IsMatchingType (address))
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
      m_err = Socket::ERROR_INVAL;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
      return -1;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
  InetSocketAddress ad = InetSocketAddress::ConvertFrom (address);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
  m_dst = ad.GetIpv4 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
Ipv4RawSocketImpl::Listen (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
  m_err = Socket::ERROR_OPNOTSUPP;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
  return -1;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
Ipv4RawSocketImpl::GetTxAvailable (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
  return 0xffffffff;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
Ipv4RawSocketImpl::Send (Ptr<Packet> p, uint32_t flags)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
  NS_LOG_FUNCTION (this << p << flags);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
  InetSocketAddress to = InetSocketAddress (m_dst, m_protocol);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
  return SendTo (p, flags, to);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
Ipv4RawSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   193
                           const Address &toAddress)
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  NS_LOG_FUNCTION (this << p << flags << toAddress);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
  if (!InetSocketAddress::IsMatchingType (toAddress))
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
      m_err = Socket::ERROR_INVAL;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
      return -1;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
  if (m_shutdownSend)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
      return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
  InetSocketAddress ad = InetSocketAddress::ConvertFrom (toAddress);
8922
922350836734 Bug 1477: Click doesn't work with raw sockets
Lalith Suresh <suresh.lalith@gmail.com>
parents: 7758
diff changeset
   206
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
  Ipv4Address dst = ad.GetIpv4 ();
6428
a3afed368709 update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6336
diff changeset
   208
  Ipv4Address src = m_src;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   209
  if (ipv4->GetRoutingProtocol ())
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   211
      Ipv4Header header;
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   212
      if (!m_iphdrincl)
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   213
        {
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   214
          header.SetDestination (dst);
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   215
          header.SetProtocol (m_protocol);
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   216
        }
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   217
      else
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   218
        {
6336
464e8093700d update Bug 932 (Support IP_HDRINCL option for Ipv4RawSocket) again: regarding w/ Tom's comments.
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6334
diff changeset
   219
          p->RemoveHeader (header);
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   220
          dst = header.GetDestination ();
6428
a3afed368709 update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6336
diff changeset
   221
          src = header.GetSource ();
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   222
        }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   223
      SocketErrno errno_ = ERROR_NOTERROR; //do not use errno as it is the standard C last error number
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   224
      Ptr<Ipv4Route> route;
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5680
diff changeset
   225
      Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a source address
6428
a3afed368709 update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6336
diff changeset
   226
      if (!oif && src != Ipv4Address::GetAny ())
6173
6ff89f45451c bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6170
diff changeset
   227
        {
6428
a3afed368709 update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6336
diff changeset
   228
          int32_t index = ipv4->GetInterfaceForAddress (src);
6173
6ff89f45451c bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6170
diff changeset
   229
          NS_ASSERT (index >= 0);
6ff89f45451c bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6170
diff changeset
   230
          oif = ipv4->GetNetDevice (index);
6428
a3afed368709 update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6336
diff changeset
   231
          NS_LOG_LOGIC ("Set index " << oif << "from source " << src);
6173
6ff89f45451c bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6170
diff changeset
   232
        }
6ff89f45451c bug 859 - Output interface estimation for the source address bound socket in IPv4 Raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6170
diff changeset
   233
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   234
      // TBD-- we could cache the route and just check its validity
4603
67a0a49c1db4 bug 592: Ipv4RoutingProtocol::RouteOutput needs a packet pointer argument for reactive protocols
Josh Pelkey <joshpelkey@gmail.com>
parents: 4567
diff changeset
   235
      route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   236
      if (route != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   237
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   238
          NS_LOG_LOGIC ("Route exists");
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   239
          if (!m_iphdrincl)
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   240
            {
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   241
              ipv4->Send (p, route->GetSource (), dst, m_protocol, route);
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   242
            }
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   243
          else
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   244
            {
6723
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6692
diff changeset
   245
              ipv4->SendWithHeader (p, header, route);
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   246
            }
6170
21c9ea05058b bug 864: Invalid return value in UdpSocketImpl::Send and Ipv4RawSocketImpl::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6169
diff changeset
   247
          NotifyDataSent (p->GetSize ());
21c9ea05058b bug 864: Invalid return value in UdpSocketImpl::Send and Ipv4RawSocketImpl::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6169
diff changeset
   248
          NotifySend (GetTxAvailable ());
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   249
          return p->GetSize ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   250
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   251
      else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   252
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   253
          NS_LOG_DEBUG ("dropped because no outgoing route.");
6170
21c9ea05058b bug 864: Invalid return value in UdpSocketImpl::Send and Ipv4RawSocketImpl::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6169
diff changeset
   254
          return -1;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   255
        }
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
Ipv4RawSocketImpl::GetRxAvailable (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
  uint32_t rx = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
  for (std::list<Data>::const_iterator i = m_recv.begin (); i != m_recv.end (); ++i)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
      rx += (i->packet)->GetSize ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
  return rx;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
Ptr<Packet> 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
Ipv4RawSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
  NS_LOG_FUNCTION (this << maxSize << flags);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
  Address tmp;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
  return RecvFrom (maxSize, flags, tmp);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
Ptr<Packet> 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   278
Ipv4RawSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   279
                             Address &fromAddress)
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   280
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
  NS_LOG_FUNCTION (this << maxSize << flags << fromAddress);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   282
  if (m_recv.empty ())
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
      return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
  struct Data data = m_recv.front ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
  m_recv.pop_front ();
6169
bef40786d55b bug 865: Ipv4RawSocketImpl::RecvFrom does not return from address all the time
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 5856
diff changeset
   288
  InetSocketAddress inet = InetSocketAddress (data.fromIp, data.fromProtocol);
bef40786d55b bug 865: Ipv4RawSocketImpl::RecvFrom does not return from address all the time
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 5856
diff changeset
   289
  fromAddress = inet;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
  if (data.packet->GetSize () > maxSize)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
      Ptr<Packet> first = data.packet->CreateFragment (0, maxSize);
6333
c461f7a25895 Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6173
diff changeset
   293
      if (!(flags & MSG_PEEK))
c461f7a25895 Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6173
diff changeset
   294
        {
c461f7a25895 Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6173
diff changeset
   295
          data.packet->RemoveAtStart (maxSize);
c461f7a25895 Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6173
diff changeset
   296
        }
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
      m_recv.push_front (data);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
      return first;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
  return data.packet;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   302
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   303
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
Ipv4RawSocketImpl::SetProtocol (uint16_t protocol)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   306
  NS_LOG_FUNCTION (this << protocol);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   307
  m_protocol = protocol;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   308
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   309
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   310
bool 
6442
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   311
Ipv4RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<Ipv4Interface> incomingInterface)
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   312
{
6442
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   313
  NS_LOG_FUNCTION (this << *p << ipHeader << incomingInterface);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
  if (m_shutdownRecv)
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   315
    {
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   316
      return false;
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   317
    }
9147
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   318
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   319
  Ptr<NetDevice> boundNetDevice = Socket::GetBoundNetDevice();
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   320
  if (boundNetDevice)
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   321
    {
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   322
      if (boundNetDevice != incomingInterface->GetDevice())
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   323
        {
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   324
          return false;
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   325
        }
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   326
    }
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   327
5581
d74aff108ddc AodvProtocol in progress, doesn't work
Pavel Boyko <boyko@iitp.ru>
parents: 4603
diff changeset
   328
  NS_LOG_LOGIC ("src = " << m_src << " dst = " << m_dst);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   329
  if ((m_src == Ipv4Address::GetAny () || ipHeader.GetDestination () == m_src) &&
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
      (m_dst == Ipv4Address::GetAny () || ipHeader.GetSource () == m_dst) &&
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
      ipHeader.GetProtocol () == m_protocol)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   332
    {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   333
      Ptr<Packet> copy = p->Copy ();
6442
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   334
      // Should check via getsockopt ()..
7758
c678188af993 Replace references to m_recvpktinfo with method call IsRecvPktInfo()
frederic.urbani@inria.fr
parents: 7717
diff changeset
   335
      if (IsRecvPktInfo ())
6442
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   336
        {
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   337
          Ipv4PacketInfoTag tag;
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   338
          copy->RemovePacketTag (tag);
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   339
          tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   340
          copy->AddPacketTag (tag);
f380cf1aa4d8 Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6437
diff changeset
   341
        }
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   342
      if (m_protocol == 1)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   343
        {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   344
          Icmpv4Header icmpHeader;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   345
          copy->PeekHeader (icmpHeader);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   346
          uint8_t type = icmpHeader.GetType ();
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   347
          if (type < 32 &&
7697
2a250bff1466 Bug 1319 - Clarify Ipv4RawSocketImpl ICMP filter limitations
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7485
diff changeset
   348
              ((uint32_t(1) << type) & m_icmpFilter))
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   349
            {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   350
              // filter out icmp packet.
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   351
              return false;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   352
            }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   353
        }
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   354
      copy->AddHeader (ipHeader);
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   355
      struct Data data;
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   356
      data.packet = copy;
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   357
      data.fromIp = ipHeader.GetSource ();
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   358
      data.fromProtocol = ipHeader.GetProtocol ();
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   359
      m_recv.push_back (data);
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   360
      NotifyDataRecv ();
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   361
      return true;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   362
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
  return false;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   364
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   365
6448
184a509cc71d Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6442
diff changeset
   366
bool
6437
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   367
Ipv4RawSocketImpl::SetAllowBroadcast (bool allowBroadcast)
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   368
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9147
diff changeset
   369
  NS_LOG_FUNCTION (this << allowBroadcast);
6437
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   370
  if (!allowBroadcast)
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   371
    {
6448
184a509cc71d Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6442
diff changeset
   372
      return false;
6437
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   373
    }
6448
184a509cc71d Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6442
diff changeset
   374
  return true;
6437
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   375
}
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   376
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   377
bool
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   378
Ipv4RawSocketImpl::GetAllowBroadcast () const
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   379
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 9147
diff changeset
   380
  NS_LOG_FUNCTION (this);
6437
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   381
  return true;
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   382
}
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   383
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   384
} // namespace ns3