src/internet/model/ipv4-raw-socket-impl.cc
author Tommaso Pecorella <tommaso.pecorella@unifi.it>
Wed, 20 Nov 2013 20:15:02 +0100
changeset 10440 1e48ff9185f1
parent 10410 4d4eb8097fa3
child 10652 dc18deba4502
permissions -rw-r--r--
Bug 938 - missing Doxygen in ns-3 (internet model + helper)
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
10410
4d4eb8097fa3 doxygen] Suppress "warning: Member NS_OBJECT_ENSURE_REGISTERED is not documented"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9710
diff changeset
    20
NS_OBJECT_ENSURE_REGISTERED (Ipv4RawSocketImpl)
4d4eb8097fa3 doxygen] Suppress "warning: Member NS_OBJECT_ENSURE_REGISTERED is not documented"
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9710
diff changeset
    21
  ;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
TypeId 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
Ipv4RawSocketImpl::GetTypeId (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
  static TypeId tid = TypeId ("ns3::Ipv4RawSocketImpl")
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
    .SetParent<Socket> ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
    .AddAttribute ("Protocol", "Protocol number to match.",
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    29
                   UintegerValue (0),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    30
                   MakeUintegerAccessor (&Ipv4RawSocketImpl::m_protocol),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    31
                   MakeUintegerChecker<uint16_t> ())
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
    .AddAttribute ("IcmpFilter", 
7697
2a250bff1466 Bug 1319 - Clarify Ipv4RawSocketImpl ICMP filter limitations
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7485
diff changeset
    33
                   "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
    34
                   UintegerValue (0),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    35
                   MakeUintegerAccessor (&Ipv4RawSocketImpl::m_icmpFilter),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    36
                   MakeUintegerChecker<uint32_t> ())
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    37
    // 
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    38
    //  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
    39
    // 
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    40
    //            | IP_HDRINC on  |      off    |
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    41
    //  ----------+---------------+-------------+-
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    42
    //  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
    43
    //  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
    44
    //  ----------+---------------+-------------+-
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
    45
    .AddAttribute ("IpHeaderInclude", 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    46
                   "Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).",
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    47
                   BooleanValue (false),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    48
                   MakeBooleanAccessor (&Ipv4RawSocketImpl::m_iphdrincl),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    49
                   MakeBooleanChecker ())
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
    50
  ;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  return tid;
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
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
Ipv4RawSocketImpl::Ipv4RawSocketImpl ()
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
  m_err = Socket::ERROR_NOTERROR;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  m_node = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
  m_src = Ipv4Address::GetAny ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
  m_dst = Ipv4Address::GetAny ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  m_protocol = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
  m_shutdownSend = false;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  m_shutdownRecv = false;
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
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
Ipv4RawSocketImpl::SetNode (Ptr<Node> node)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 9147
diff changeset
    69
  NS_LOG_FUNCTION (this << node);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  m_node = node;
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
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
void
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
Ipv4RawSocketImpl::DoDispose (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  m_node = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  Socket::DoDispose ();
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
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
enum Socket::SocketErrno 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
Ipv4RawSocketImpl::GetErrno (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  return m_err;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
}
6689
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    87
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    88
enum Socket::SocketType
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    89
Ipv4RawSocketImpl::GetSocketType (void) const
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    90
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 9147
diff changeset
    91
  NS_LOG_FUNCTION (this);
6692
591fb1aa0ca4 Avoid enum name collision in socket
Josh Pelkey <jpelkey@gatech.edu>
parents: 6689
diff changeset
    92
  return NS3_SOCK_RAW;
6689
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    93
}
e2de571e920a Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents: 6448
diff changeset
    94
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
Ptr<Node> 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
Ipv4RawSocketImpl::GetNode (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
  return m_node;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
Ipv4RawSocketImpl::Bind (const Address &address)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  NS_LOG_FUNCTION (this << address);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
  if (!InetSocketAddress::IsMatchingType (address))
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
      m_err = Socket::ERROR_INVAL;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
      return -1;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  InetSocketAddress ad = InetSocketAddress::ConvertFrom (address);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  m_src = ad.GetIpv4 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
Ipv4RawSocketImpl::Bind (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
  m_src = Ipv4Address::GetAny ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
int 
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   122
Ipv4RawSocketImpl::Bind6 (void)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   123
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 9147
diff changeset
   124
  NS_LOG_FUNCTION (this);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   125
  return (-1);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   126
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7697
diff changeset
   127
int 
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
Ipv4RawSocketImpl::GetSockName (Address &address) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 9147
diff changeset
   130
  NS_LOG_FUNCTION (this << address);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
  address = InetSocketAddress (m_src, 0);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
Ipv4RawSocketImpl::Close (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
  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
   138
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
  if (ipv4 != 0)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
      ipv4->DeleteRawSocket (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
Ipv4RawSocketImpl::ShutdownSend (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
  m_shutdownSend = true;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
Ipv4RawSocketImpl::ShutdownRecv (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
  m_shutdownRecv = true;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
Ipv4RawSocketImpl::Connect (const Address &address)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
  NS_LOG_FUNCTION (this << address);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
  if (!InetSocketAddress::IsMatchingType (address))
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
      m_err = Socket::ERROR_INVAL;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
      return -1;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
  InetSocketAddress ad = InetSocketAddress::ConvertFrom (address);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
  m_dst = ad.GetIpv4 ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
Ipv4RawSocketImpl::Listen (void)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
  m_err = Socket::ERROR_OPNOTSUPP;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
  return -1;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
Ipv4RawSocketImpl::GetTxAvailable (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
  return 0xffffffff;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
Ipv4RawSocketImpl::Send (Ptr<Packet> p, uint32_t flags)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
  NS_LOG_FUNCTION (this << p << flags);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
  InetSocketAddress to = InetSocketAddress (m_dst, m_protocol);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
  return SendTo (p, flags, to);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
int 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
Ipv4RawSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   194
                           const Address &toAddress)
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
  NS_LOG_FUNCTION (this << p << flags << toAddress);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
  if (!InetSocketAddress::IsMatchingType (toAddress))
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
      m_err = Socket::ERROR_INVAL;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
      return -1;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  if (m_shutdownSend)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
      return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
  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
   207
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
  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
   209
  Ipv4Address src = m_src;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   210
  if (ipv4->GetRoutingProtocol ())
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   212
      Ipv4Header header;
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   213
      if (!m_iphdrincl)
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   214
        {
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   215
          header.SetDestination (dst);
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   216
          header.SetProtocol (m_protocol);
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   217
        }
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   218
      else
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   219
        {
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
   220
          p->RemoveHeader (header);
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   221
          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
   222
          src = header.GetSource ();
6334
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   223
        }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   224
      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
   225
      Ptr<Ipv4Route> route;
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti M?kel? <zarhan@cc.hut.fi>
parents: 5680
diff changeset
   226
      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
   227
      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
   228
        {
6428
a3afed368709 update Bug 932: source address selection in IPv4 HDRINCL
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6336
diff changeset
   229
          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
   230
          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
   231
          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
   232
          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
   233
        }
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
   234
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   235
      // 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
   236
      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
   237
      if (route != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   238
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   239
          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
   240
          if (!m_iphdrincl)
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   241
            {
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   242
              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
   243
            }
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   244
          else
c9373f264dfe Bug 932 - Support IP_HDRINCL option for Ipv4RawSocket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6333
diff changeset
   245
            {
6723
fff5c512f345 bug 967: decouple Ipv4L4Protocols from Ipv4L3Protocol::Send() via a new callback
Tom Henderson <tomh@tomh.org>
parents: 6692
diff changeset
   246
              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
   247
            }
6170
21c9ea05058b bug 864: Invalid return value in UdpSocketImpl::Send and Ipv4RawSocketImpl::Send
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6169
diff changeset
   248
          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
   249
          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
   250
          return p->GetSize ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   251
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   252
      else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   253
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   254
          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
   255
          return -1;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   256
        }
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
  return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
uint32_t 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
Ipv4RawSocketImpl::GetRxAvailable (void) const
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
  NS_LOG_FUNCTION (this);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
  uint32_t rx = 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
  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
   266
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
      rx += (i->packet)->GetSize ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   268
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
  return rx;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
Ptr<Packet> 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
Ipv4RawSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
  NS_LOG_FUNCTION (this << maxSize << flags);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
  Address tmp;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
  return RecvFrom (maxSize, flags, tmp);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
Ptr<Packet> 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   279
Ipv4RawSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   280
                             Address &fromAddress)
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   282
  NS_LOG_FUNCTION (this << maxSize << flags << fromAddress);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
  if (m_recv.empty ())
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
      return 0;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
  struct Data data = m_recv.front ();
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
  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
   289
  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
   290
  fromAddress = inet;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
  if (data.packet->GetSize () > maxSize)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
    {
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
      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
   294
      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
   295
        {
c461f7a25895 Bug 858 - support MSG_PEEK in IPv4/IPv6 raw socket
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents: 6173
diff changeset
   296
          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
   297
        }
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
      m_recv.push_front (data);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
      return first;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
  return data.packet;
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
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
void 
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
Ipv4RawSocketImpl::SetProtocol (uint16_t protocol)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   306
{
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   307
  NS_LOG_FUNCTION (this << protocol);
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   308
  m_protocol = protocol;
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
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   311
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
   312
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
   313
{
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
   314
  NS_LOG_FUNCTION (this << *p << ipHeader << incomingInterface);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
  if (m_shutdownRecv)
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   316
    {
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   317
      return false;
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   318
    }
9147
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   319
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   320
  Ptr<NetDevice> boundNetDevice = Socket::GetBoundNetDevice();
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   321
  if (boundNetDevice)
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   322
    {
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   323
      if (boundNetDevice != incomingInterface->GetDevice())
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   324
        {
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   325
          return false;
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
    }
e9af93287335 Bug 1527 - Ipv4RawSocket's BindToNetDevice not doing anything
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 8922
diff changeset
   328
5581
d74aff108ddc AodvProtocol in progress, doesn't work
Pavel Boyko <boyko@iitp.ru>
parents: 4603
diff changeset
   329
  NS_LOG_LOGIC ("src = " << m_src << " dst = " << m_dst);
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
  if ((m_src == Ipv4Address::GetAny () || ipHeader.GetDestination () == m_src) &&
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
      (m_dst == Ipv4Address::GetAny () || ipHeader.GetSource () == m_dst) &&
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   332
      ipHeader.GetProtocol () == m_protocol)
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   333
    {
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   334
      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
   335
      // Should check via getsockopt ()..
7758
c678188af993 Replace references to m_recvpktinfo with method call IsRecvPktInfo()
frederic.urbani@inria.fr
parents: 7717
diff changeset
   336
      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
   337
        {
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
          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
   339
          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
   340
          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
   341
          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
   342
        }
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   343
      if (m_protocol == 1)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   344
        {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   345
          Icmpv4Header icmpHeader;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   346
          copy->PeekHeader (icmpHeader);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   347
          uint8_t type = icmpHeader.GetType ();
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   348
          if (type < 32 &&
7697
2a250bff1466 Bug 1319 - Clarify Ipv4RawSocketImpl ICMP filter limitations
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7485
diff changeset
   349
              ((uint32_t(1) << type) & m_icmpFilter))
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   350
            {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   351
              // filter out icmp packet.
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   352
              return false;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   353
            }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6834
diff changeset
   354
        }
5677
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   355
      copy->AddHeader (ipHeader);
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   356
      struct Data data;
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   357
      data.packet = copy;
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   358
      data.fromIp = ipHeader.GetSource ();
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   359
      data.fromProtocol = ipHeader.GetProtocol ();
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   360
      m_recv.push_back (data);
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   361
      NotifyDataRecv ();
81bd758dd7f4 raw socket killed
Borovkova Elena <borovkovaes@iitp.ru>
parents: 5615
diff changeset
   362
      return true;
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
    }
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   364
  return false;
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   365
}
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   366
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
   367
bool
6437
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   368
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
   369
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 9147
diff changeset
   370
  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
   371
  if (!allowBroadcast)
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   372
    {
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
   373
      return false;
6437
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   374
    }
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
   375
  return true;
6437
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
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   378
bool
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   379
Ipv4RawSocketImpl::GetAllowBroadcast () const
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   380
{
9710
df21b904fce3 Further work on cleaning up function logging of internet module.
Kristijan Lenkovi? <k.lenkovic@me.com>
parents: 9147
diff changeset
   381
  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
   382
  return true;
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   383
}
c11291f51d57 Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6428
diff changeset
   384
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   385
} // namespace ns3