1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 #ifndef IPV4_RAW_SOCKET_IMPL_H 3 #define IPV4_RAW_SOCKET_IMPL_H 4 5 #include "ns3/socket.h" 6 #include "ns3/ipv4-header.h" 7 #include "ns3/ipv4-route.h" 8 #include "ns3/ipv4-interface.h" 9 #include <list> 10 11 namespace ns3 { 12 13 class NetDevice; 14 class Node; 15 16 /** 17 * \ingroup socket 18 * \ingroup ipv4 19 * 20 * \brief IPv4 raw socket. 21 * 22 * A RAW Socket typically is used to access specific IP layers not usually 23 * available through L4 sockets, e.g., ICMP. The implementer should take 24 * particular care to define the Ipv4RawSocketImpl Attributes, and in 25 * particular the Protocol attribute. 26 */ 27 class Ipv4RawSocketImpl : public Socket 28 { 29 public: 30 /** 31 * \brief Get the type ID of this class. 32 * \return type ID 33 */ 34 static TypeId GetTypeId (void); 35 36 Ipv4RawSocketImpl (); 37 38 /** 39 * \brief Set the node associated with this socket. 40 * \param node node to set 41 */ 42 void SetNode (Ptr<Node> node); 43 44 virtual enum Socket::SocketErrno GetErrno () const; 45 46 /** 47 * \brief Get socket type (NS3_SOCK_RAW) 48 * \return socket type 49 */ 50 virtual enum Socket::SocketType GetSocketType (void) const; 51 52 virtual Ptr<Node> GetNode (void) const; 53 virtual int Bind (const Address &address); 54 virtual int Bind (); 55 virtual int Bind6 (); 56 virtual int GetSockName (Address &address) const; 57 virtual int GetPeerName (Address &address) const; 58 virtual int Close (void); 59 virtual int ShutdownSend (void); 60 virtual int ShutdownRecv (void); 61 virtual int Connect (const Address &address); 62 virtual int Listen (void); 63 virtual uint32_t GetTxAvailable (void) const; 64 virtual int Send (Ptr<Packet> p, uint32_t flags); 65 virtual int SendTo (Ptr<Packet> p, uint32_t flags, 66 const Address &toAddress); 67 virtual uint32_t GetRxAvailable (void) const; 68 virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags); 69 virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags, 70 Address &fromAddress); 71 72 73 /** 74 * \brief Set protocol field. 75 * \param protocol protocol to set 76 */ 77 void SetProtocol (uint16_t protocol); 78 79 /** 80 * \brief Forward up to receive method. 81 * \param p packet 82 * \param ipHeader IPv4 header 83 * \param incomingInterface incoming interface 84 * \return true if forwarded, false otherwise 85 */ 86 bool ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<Ipv4Interface> incomingInterface); 87 virtual bool SetAllowBroadcast (bool allowBroadcast); 88 virtual bool GetAllowBroadcast () const; 89 90 private: 91 virtual void DoDispose (void); 92 93 /** 94 * \struct Data 95 * \brief IPv4 raw data and additional information. 96 */ 97 struct Data { 98 Ptr<Packet> packet; /**< Packet data */ 99 Ipv4Address fromIp; /**< Source address */ 100 uint16_t fromProtocol; /**< Protocol used */ 101 }; 102 103 mutable enum Socket::SocketErrno m_err; //!< Last error number. 104 Ptr<Node> m_node; //!< Node 105 Ipv4Address m_src; //!< Source address. 106 Ipv4Address m_dst; //!< Destination address. 107 uint16_t m_protocol; //!< Protocol. 108 std::list<struct Data> m_recv; //!< Packet waiting to be processed. 109 bool m_shutdownSend; //!< Flag to shutdown send capability. 110 bool m_shutdownRecv; //!< Flag to shutdown receive capability. 111 uint32_t m_icmpFilter; //!< ICMPv4 filter specification 112 bool m_iphdrincl; //!< Include IP Header information (a.k.a setsockopt (IP_HDRINCL)) 113 }; 114 115 } // namespace ns3 116 117 #endif /* IPV4_RAW_SOCKET_IMPL_H */ 118