A Discrete-Event Network Simulator
API
ipv4-raw-socket-impl.h
Go to the documentation of this file.
1 #ifndef IPV4_RAW_SOCKET_IMPL_H
2 #define IPV4_RAW_SOCKET_IMPL_H
3 
4 #include "ns3/ipv4-header.h"
5 #include "ns3/ipv4-interface.h"
6 #include "ns3/ipv4-route.h"
7 #include "ns3/socket.h"
8 
9 #include <list>
10 
11 namespace ns3
12 {
13 
14 class NetDevice;
15 class Node;
16 
28 class Ipv4RawSocketImpl : public Socket
29 {
30  public:
35  static TypeId GetTypeId();
36 
38 
43  void SetNode(Ptr<Node> node);
44 
45  enum Socket::SocketErrno GetErrno() const override;
46 
51  enum Socket::SocketType GetSocketType() const override;
52 
53  Ptr<Node> GetNode() const override;
54  int Bind(const Address& address) override;
55  int Bind() override;
56  int Bind6() override;
57  int GetSockName(Address& address) const override;
58  int GetPeerName(Address& address) const override;
59  int Close() override;
60  int ShutdownSend() override;
61  int ShutdownRecv() override;
62  int Connect(const Address& address) override;
63  int Listen() override;
64  uint32_t GetTxAvailable() const override;
65  int Send(Ptr<Packet> p, uint32_t flags) override;
66  int SendTo(Ptr<Packet> p, uint32_t flags, const Address& toAddress) override;
67  uint32_t GetRxAvailable() const override;
68  Ptr<Packet> Recv(uint32_t maxSize, uint32_t flags) override;
69  Ptr<Packet> RecvFrom(uint32_t maxSize, uint32_t flags, Address& fromAddress) override;
70 
75  void SetProtocol(uint16_t protocol);
76 
84  bool ForwardUp(Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<Ipv4Interface> incomingInterface);
85  bool SetAllowBroadcast(bool allowBroadcast) override;
86  bool GetAllowBroadcast() const override;
87 
88  private:
89  void DoDispose() override;
90 
95  struct Data
96  {
99  uint16_t fromProtocol;
100  };
101 
102  mutable enum Socket::SocketErrno m_err;
106  uint16_t m_protocol;
107  std::list<struct Data> m_recv;
110  uint32_t m_icmpFilter;
111  bool m_iphdrincl;
112 };
113 
114 } // namespace ns3
115 
116 #endif /* IPV4_RAW_SOCKET_IMPL_H */
a polymophic address class
Definition: address.h:100
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Packet header for IPv4.
Definition: ipv4-header.h:34
Ptr< Node > GetNode() const override
Return the node this socket is associated with.
int GetPeerName(Address &address) const override
Get the peer address of a connected socket.
Ipv4Address m_src
Source address.
int Bind() override
Allocate a local IPv4 endpoint for this socket.
int Send(Ptr< Packet > p, uint32_t flags) override
Send data (or dummy data) to the remote host.
Ipv4Address m_dst
Destination address.
void DoDispose() override
Destructor implementation.
int Close() override
Close a socket.
int Listen() override
Listen for incoming connections.
std::list< struct Data > m_recv
Packet waiting to be processed.
bool GetAllowBroadcast() const override
Query whether broadcast datagram transmissions are allowed.
uint32_t GetRxAvailable() const override
Return number of bytes which can be returned from one or multiple calls to Recv.
void SetProtocol(uint16_t protocol)
Set protocol field.
Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress) override
Read a single packet from the socket and retrieve the sender address.
bool m_iphdrincl
Include IP Header information (a.k.a setsockopt (IP_HDRINCL))
enum Socket::SocketErrno GetErrno() const override
Get last error number.
uint16_t m_protocol
Protocol.
int Connect(const Address &address) override
Initiate a connection to a remote host.
int Bind6() override
Allocate a local IPv6 endpoint for this socket.
enum Socket::SocketErrno m_err
Last error number.
bool SetAllowBroadcast(bool allowBroadcast) override
Configure whether broadcast datagram transmissions are allowed.
bool ForwardUp(Ptr< const Packet > p, Ipv4Header ipHeader, Ptr< Ipv4Interface > incomingInterface)
Forward up to receive method.
uint32_t m_icmpFilter
ICMPv4 filter specification.
bool m_shutdownRecv
Flag to shutdown receive capability.
static TypeId GetTypeId()
Get the type ID of this class.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
uint32_t GetTxAvailable() const override
Returns the number of bytes which can be sent in a single call to Send.
bool m_shutdownSend
Flag to shutdown send capability.
enum Socket::SocketType GetSocketType() const override
Get socket type (NS3_SOCK_RAW)
int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress) override
Send data to a specified peer.
int GetSockName(Address &address) const override
Get socket address.
A low-level Socket API based loosely on the BSD Socket API.
Definition: socket.h:68
Ptr< Packet > Recv()
Read a single packet from the socket.
Definition: socket.cc:172
SocketType
Enumeration of the possible socket types.
Definition: socket.h:107
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
a unique identifier for an interface.
Definition: type-id.h:60
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IPv4 raw data and additional information.
Ipv4Address fromIp
Source address.
uint16_t fromProtocol
Protocol used.
Ptr< Packet > packet
Packet data.